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

[updated PATCH] Simplify and fix --first-parent implementation

From
Stephen R. van den Berg <srb@cuci.nl>
Date
Apr 27, 2008, 17:32 UTC
Message-ID
<20080427173246.10023.45426.stgit@aristoteles.cuci.nl>
The purpose of --first-parent is to simplify the tree into a tree without
 merges.  This is accomplished by pretending there are no other parents
than the first parent when encountering a merge.  In order to implement
this correctly the behaviour should be such that the tree traversal does
not depend on any parent other than the first.

The old code marked the other parents as seen, which means that the tree traversal (under certain circumstances) will behave differently depending on which merges have been done, therefore violating the rule that only the first parent should be relevant.

Case in point, given the following tree:
       -----
      /     \
 D---E---F---G master

The current first-parent code considers E to be seen and stops the traversal after showing G and F.

Signed-off-by: Stephen R. van den Berg <srb@cuci.nl>
---
 revision.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/revision.c b/revision.c
index 4231ea2..bcfcd2a 100644
--- a/revision.c
+++ b/revision.c
@@ -415,7 +415,6 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, str
 {
 	struct commit_list *parent = commit->parents;
 	unsigned left_flag;
-	int add, rest;
 
 	if (commit->object.flags & ADDED)
 		return 0;
@@ -462,19 +461,18 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, str
 
 	left_flag = (commit->object.flags & SYMMETRIC_LEFT);
 
-	rest = !revs->first_parent_only;
-	for (parent = commit->parents, add = 1; parent; add = rest) {
+	for (parent = commit->parents; parent; parent = parent->next) {
 		struct commit *p = parent->item;
 
-		parent = parent->next;
 		if (parse_commit(p) < 0)
 			return -1;
 		p->object.flags |= left_flag;
 		if (p->object.flags & SEEN)
 			continue;
 		p->object.flags |= SEEN;
-		if (add)
-			insert_by_date(p, list);
+		insert_by_date(p, list);
+		if(revs->first_parent_only)
+			break;
 	}
 	return 0;
 }
Message 1 of 1 in “Simplify and fix --first-parent implementation”
  1. Simplify and fix --first-parent implementationStephen R. van den Berg, Apr 27, 2008

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.