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

[PATCH] rev-list: omit duplicated parents.

From
Junio C Hamano <junkio@cox.net>
Date
Jan 29, 2006, 23:30 UTC
Message-ID
<7vmzhehath.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<7vmzhekcz3.fsf@assigned-by-dhcp.cox.net>

Showing the same parent more than once for a commit does not make much sense downstream, so stop it.

This can happen with an incorrectly made merge commit that merges the same parent twice, but can happen in an otherwise sane development history while squishing the history by taking into account only commits that touch specified paths.

For example,
	$ git rev-list --max-count=1 --parents addafaf -- rev-list.c
would have to show this commit ancestry graph:
                  .---o---.
                 /         \
                .---*---o---.
               /    93b74bc  \
   ---*---o---o-----o---o-----o addafaf
      d8f6b34  \             /
                .---o---o---.
                 \         /
                  .---*---.
                      3815f42

where 5 independent development tracks, only two of which have changes in the specified paths since they forked. The last change for the other three development tracks was done by the same commit before they forked, and we were showing that three times.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
    Junio C Hamano <junkio@cox.net> writes:
    > I think it probably is a bug...
    > ...
    > Let me wait for a while to hear Linus contradicts me, though...
    I've considered doing this only when path is specified, but
    instead decided to do so for all commits.  I recall there
    are commits in the kernel archive created somehow with the
    same parent listed twice, and the downstream tools would
    have the same trouble if we didn't.
 rev-list.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
d6d9f494403a4e77d17244ece43005eec51200d3
diff --git a/rev-list.c b/rev-list.c
index 0b142c1..93ea41b 100644
--- a/rev-list.c
+++ b/rev-list.c
@@ -12,6 +12,7 @@
 #define COUNTED		(1u << 2)
 #define SHOWN		(1u << 3)
 #define TREECHANGE	(1u << 4)
+#define TMP_MARK	(1u << 5) /* for isolated cases; clean after use */
 
 static const char rev_list_usage[] =
 "git-rev-list [OPTION] <commit-id>... [ -- paths... ]\n"
@@ -72,9 +73,21 @@ static void show_commit(struct commit *c
 	if (show_parents) {
 		struct commit_list *parents = commit->parents;
 		while (parents) {
-			printf(" %s", sha1_to_hex(parents->item->object.sha1));
+			struct object *o = &(parents->item->object);
 			parents = parents->next;
+			if (o->flags & TMP_MARK)
+				continue;
+			printf(" %s", sha1_to_hex(o->sha1));
+			o->flags |= TMP_MARK;
 		}
+		/* TMP_MARK is a general purpose flag that can
+		 * be used locally, but the user should clean
+		 * things up after it is done with them.
+		 */
+		for (parents = commit->parents;
+		     parents;
+		     parents = parents->next)
+			parents->item->object.flags &= ~TMP_MARK;
 	}
 	if (commit_format == CMIT_FMT_ONELINE)
 		putchar(' ');
-- 
1.1.5.g9843f
Previous: Junio C HamanoNext: Linus Torvalds
Message 3 of 4 in “Possible git-rev-list bug”
  1. Marco CostalbaJan 29, 2006
  2. Junio C HamanoJan 29, 2006
  3. rev-list: omit duplicated parents.Junio C Hamano, Jan 29, 2006
  4. Linus TorvaldsJan 31, 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.