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

Re: [PATCH] Fix "git log --parent -m" from emitting duplicated parent info

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 9, 2007, 01:20 UTC
Message-ID
<7v4pkez832.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7vd4z2za2g.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <gitster@pobox.com> writes:
Show 11 quoted lines
> This is whitespace damaged in a funny way (some lines do not
> have leading whitespace while some do).
>
> log_tree_diff() hence log_tree_commit() is caled by codepaths
> other than "git log -p", and I am not convinced that this patch
> would not break them.  Worrysome.
>
> I wonder why we did not actually remove the duplicate parents
> from "commit->parents" list after history simplification when we
> originally did 88494423, instead of filtering only on the output
> path.  Anybody remember the reason?

In any case, I think this patch would let us revert 88494239 and the "matching" patch for git-log I sent out earlier, and also makes your patch unnecessary.

Seems to pass the test suite, and your original example of checking addafaf with path limiter of "diff.h".

I am a bit worried about the possible fallout, though. There might be some callers that expect to find the same number of parents in commit->parents list and what is recorded in the commit object itself, although I do not think of any, and I tend to think it is broken if there is one.

-- >8 -- [PATCH] remove duplicated parents after history simplification

When we simplify history due to path limits, the parents list for a rewritten commit can end up having duplicates. Instead of filtering them out in the output codepath like earlier commit 88494423 did, remove them much earlier, when the parent rewriting actually happens.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 revision.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/revision.c b/revision.c
index 5184716..b8a7571 100644
--- a/revision.c
+++ b/revision.c
@@ -1308,6 +1308,26 @@ static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp
 	}
 }
 
+static int remove_duplicate_parents(struct commit *commit)
+{
+	struct commit_list *p;
+	struct commit_list **pp = &commit->parents;
+
+	/* Examine existing parents while marking ones we have seen... */
+	for (p = commit->parents; p; p = p->next) {
+		struct commit *parent = p->item;
+		if (parent->object.flags & TMP_MARK)
+			continue;
+		parent->object.flags |= TMP_MARK;
+		*pp = p;
+		pp = &p->next;
+	}
+	/* ... and clear the temporary mark */
+	for (p = commit->parents; p; p = p->next)
+		p->item->object.flags &= ~TMP_MARK;
+	return 0;
+}
+
 static int rewrite_parents(struct rev_info *revs, struct commit *commit)
 {
 	struct commit_list **pp = &commit->parents;
@@ -1324,7 +1344,7 @@ static int rewrite_parents(struct rev_info *revs, struct commit *commit)
 		}
 		pp = &parent->next;
 	}
-	return 0;
+	return remove_duplicate_parents(commit);
 }
 
 static int commit_match(struct commit *commit, struct rev_info *opt)
Previous: Junio C HamanoNext: Johannes Schindelin
Message 6 of 10 in “Fix "git log --parent -m" from emitting duplicated parent info”
  1. Fix "git log --parent -m" from emitting duplicated parent infoMarco Costalba, Jul 8, 2007
  2. Junio C HamanoJul 8, 2007
  3. Junio C HamanoJul 9, 2007
  4. Johannes SchindelinJul 9, 2007
  5. Junio C HamanoJul 9, 2007
  6. Junio C HamanoJul 9, 2007
  7. Johannes SchindelinJul 9, 2007
  8. Junio C HamanoJul 9, 2007
  9. Marco CostalbaJul 9, 2007
  10. Junio C HamanoJul 9, 2007

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.