git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] combine-diff: update --cc "uninteresting hunks" logic.

From
Junio C Hamano <junkio@cox.net>
Date
Feb 2, 2006, 08:18 UTC
Message-ID
<7voe1qtbr5.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.64.0602020002110.21884@g5.osdl.org>

Earlier logic was discarding hunks that has difference from only one parent or the same difference from all but one parent. This changes it to check if the differences on all lines are from the same sets of parents. This discards more uninteresting hunks and seems to match expectations more naturally.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 Linus Torvalds <torvalds@osdl.org> writes:
 > On Wed, 1 Feb 2006, Linus Torvalds wrote:
 >> 
 >> I _think_ your version of the rule ("pluses and minuses in all the same 
 >> columns") ends up being exactly the same as my rule ("only two different 
 >> versions").
 >
 > Actually, I take that back.
 I do not do that "result to match the final" check in this
 version yet.  I'll need to revisit it before placing this in
 the master, but I am going to bed.
 combine-diff.c |  102 ++++++++++++++++++--------------------------------------
 1 files changed, 33 insertions(+), 69 deletions(-)
bcb331e2e87c2d7221751994b5ead4a79dd2a17b
diff --git a/combine-diff.c b/combine-diff.c
index 0cc18fe..44931b2 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -262,58 +262,6 @@ static int interesting(struct sline *sli
 	return ((sline->flag & all_mask) != all_mask || sline->lost_head);
 }
 
-static unsigned long line_common_diff(struct sline *sline, unsigned long all_mask)
-{
-	/*
-	 * Look at the line and see from which parents we have the
-	 * same difference.
-	 */
-
-	/* Lower bits of sline->flag records if the parent had this
-	 * line, so XOR with all_mask gives us on-bits for parents we
-	 * have differences with.
-	 */
-	unsigned long common_adds = (sline->flag ^ all_mask) & all_mask;
-	unsigned long common_removes = all_mask;
-
-	/* If all the parents have this line, that also counts as
-	 * having the same difference.
-	 */
-	if (!common_adds)
-		common_adds = all_mask;
-
-	if (sline->lost_head) {
-		/* Lost head list records the lines removed from
-		 * the parents, and parent_map records from which
-		 * parent the line was removed.
-		 */
-		struct lline *ll;
-		for (ll = sline->lost_head; ll; ll = ll->next) {
-			common_removes &= ll->parent_map;
-		}
-	}
-	return common_adds & common_removes;
-}
-
-static unsigned long line_all_diff(struct sline *sline, unsigned long all_mask)
-{
-	/*
-	 * Look at the line and see from which parents we have some difference.
-	 */
-	unsigned long different = (sline->flag ^ all_mask) & all_mask;
-	if (sline->lost_head) {
-		/* Lost head list records the lines removed from
-		 * the parents, and parent_map records from which
-		 * parent the line was removed.
-		 */
-		struct lline *ll;
-		for (ll = sline->lost_head; ll; ll = ll->next) {
-			different |= ll->parent_map;
-		}
-	}
-	return different;
-}
-
 static unsigned long adjust_hunk_tail(struct sline *sline,
 				      unsigned long all_mask,
 				      unsigned long hunk_begin,
@@ -417,8 +365,7 @@ static int make_hunks(struct sline *slin
 	i = 0;
 	while (i < cnt) {
 		unsigned long j, hunk_begin, hunk_end;
-		int same, diff;
-		unsigned long same_diff, all_diff;
+		unsigned long same_diff;
 		while (i < cnt && !(sline[i].flag & mark))
 			i++;
 		if (cnt <= i)
@@ -449,23 +396,40 @@ static int make_hunks(struct sline *slin
 		}
 		hunk_end = j;
 
-		/* [i..hunk_end) are interesting.  Now does it have
-		 * the same change with all but one parent?
+		/* [i..hunk_end) are interesting.  Now is it really
+		 * interesting?
 		 */
-		same_diff = all_mask;
-		all_diff = 0;
-		for (j = i; j < hunk_end; j++) {
-			same_diff &= line_common_diff(sline + j, all_mask);
-			all_diff |= line_all_diff(sline + j, all_mask);
-		}
-		diff = same = 0;
-		for (j = 0; j < num_parent; j++) {
-			if (same_diff & (1UL<<j))
-				same++;
-			if (all_diff & (1UL<<j))
-				diff++;
+		same_diff = 0;
+		has_interesting = 0;
+		for (j = i; j < hunk_end && !has_interesting; j++) {
+			unsigned long this_diff = ~sline[j].flag & all_mask;
+			struct lline *ll = sline[j].lost_head;
+			if (this_diff) {
+				/* This has some changes.  Is it the
+				 * same as others?
+				 */
+				if (!same_diff)
+					same_diff = this_diff;
+				else if (same_diff != this_diff) {
+					has_interesting = 1;
+					break;
+				}
+			}
+			while (ll && !has_interesting) {
+				/* Lost this line from these parents;
+				 * who are they?  Are they the same?
+				 */
+				this_diff = ll->parent_map;
+				if (!same_diff)
+					same_diff = this_diff;
+				else if (same_diff != this_diff) {
+					has_interesting = 1;
+				}
+				ll = ll->next;
+			}
 		}
-		if ((num_parent - 1 <= same) || (diff == 1)) {
+
+		if (!has_interesting) {
 			/* This hunk is not that interesting after all */
 			for (j = hunk_begin; j < hunk_end; j++)
 				sline[j].flag &= ~mark;
-- 
1.1.6.g2672
Previous: Linus TorvaldsNext: Junio C Hamano
Message 7 of 40 in “The merge from hell...”
  1. Linus TorvaldsFeb 2, 2006
  2. Junio C HamanoFeb 2, 2006
  3. combine-diff: reuse diff from the same blob.Junio C Hamano, Feb 2, 2006
  4. Linus TorvaldsFeb 2, 2006
  5. Linus TorvaldsFeb 2, 2006
  6. Linus TorvaldsFeb 2, 2006
  7. combine-diff: update --cc "uninteresting hunks" logic.Junio C Hamano, Feb 2, 2006
  8. combine-diff: add safety check to --cc.Junio C Hamano, Feb 2, 2006
  9. Linus TorvaldsFeb 2, 2006
  10. Junio C HamanoFeb 3, 2006
  11. Linus TorvaldsFeb 3, 2006
  12. [Attn - repository browser authors] diff-tree combined format.Junio C Hamano, Feb 3, 2006
  13. Marco CostalbaFeb 3, 2006
  14. Junio C HamanoFeb 3, 2006
  15. Junio C HamanoFeb 3, 2006
  16. Marco CostalbaFeb 4, 2006
  17. Paul MackerrasFeb 4, 2006
  18. Junio C HamanoFeb 3, 2006
  19. Paul MackerrasFeb 4, 2006
  20. Junio C HamanoFeb 4, 2006
  21. Paul MackerrasFeb 4, 2006
  22. Junio C HamanoFeb 4, 2006
  23. Linus TorvaldsFeb 4, 2006
  24. Linus TorvaldsFeb 4, 2006
  25. Marco CostalbaFeb 2, 2006
  26. Linus TorvaldsFeb 2, 2006
  27. Aneesh KumarFeb 2, 2006
  28. Junio C HamanoFeb 2, 2006
  29. Linus TorvaldsFeb 2, 2006
  30. Junio C HamanoFeb 2, 2006
  31. Linus TorvaldsFeb 5, 2006
  32. Add a "git show" command to show a commitLinus Torvalds, Feb 5, 2006
  33. Fix git-rev-parse over-eager errorsLinus Torvalds, Feb 5, 2006
  34. Junio C HamanoFeb 5, 2006
  35. Linus TorvaldsFeb 5, 2006
  36. Junio C HamanoFeb 6, 2006
  37. Junio C HamanoFeb 5, 2006
  38. Linus TorvaldsFeb 5, 2006
  39. Linus TorvaldsFeb 5, 2006
  40. Junio C HamanoFeb 6, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.