Skip to contentSkip to conversation

Do not run useless show-diff on unmerged paths repeatedly.

PATCH New Junio C Hamano 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Do not run useless show-diff on unmerged paths repeatedly.

When run on unmerged dircache, show-diff compares the working file with each non-empty stage for that path. Two out of three times, this is not very helpful. This patch makes it report the unmergedness only once per each path and avoids running the actual diff.

Upper layer SCMs like Cogito are expected to find out mode/SHA1 for each stage by using "show-files --stage" and run the diff itself. This would result in more sensible diffs.

To be applied on top of my previous patches:

[PATCH] Optionally tell show-diff to show only named files. [PATCH] show-diff -z option for machine readable output. [PATCH] show-diff shell safety.
[PATCH] (take 2) Rename confusing variable in show-diff. [PATCH] show-diff style fix.

---

 ++show-diff.c |   13 +++++++++++++
 1 files changed, 13 insertions(+)
++show-diff.c renamed from show-diff.c +13 -0
@@ -167,6 +167,19 @@
 		    ! matches_pathspec(ce, argv+1, argc-1))
 			continue;
 
+		if (ce_stage(ce)) {
+			if (machine_readable)
+				printf("U %s%c", ce->name, 0);
+			else
+				printf("%s: Unmerged\n",
+				       ce->name);
+			while (i < entries &&
+			       !strcmp(ce->name, active_cache[i]->name))
+				i++;
+			i--; /* compensate for loop control increments */
+			continue;
+		}
+ 
 		if (stat(ce->name, &st) < 0) {
 			if (errno == ENOENT && silent_on_nonexisting_files)
 				continue;