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

Fix interesting git-rev-list corner case

From
Linus Torvalds <torvalds@osdl.org>
Date
Jul 29, 2005, 22:50 UTC
Message-ID
<Pine.LNX.4.58.0507291542060.29650@g5.osdl.org>

This corner-case was triggered by a kernel commit that was not in date order, due to a misconfigured time zone that made the commit appear three hours older than it was.

That caused git-rev-list to traverse the commit tree in a non-obvious order, and made it parse several of the _parents_ of the misplaced commit before it actually parsed the commit itself. That's fine, but it meant that the grandparents of the commit didn't get marked uninteresting, because they had been reached through an "interesting" branch.

The reason was that "mark_parents_uninteresting()" (which is supposed to mark all existing parents as being uninteresting - duh) didn't actually traverse more than one level down the parent chain.

NORMALLY this is fine, since with the date-based traversal order, grandparents won't ever even have been looked at before their parents (so traversing the chain down isn't needed, because the next time around when we pick out the parent we'll mark _its_ parents uninteresting), but since we'd gotten out of order, we'd already seen the parent and thus never got around to mark the grandparents.

Anyway, the fix is simple. Just traverse parent chains recursively. Normally the chain won't even exist (since the parent hasn't been parsed yet), so this is not actually going to trigger except in this strange corner-case.

Add a comment to the simple one-liner, since this was a bit subtle, and I had to really think things through to understand how it could happen.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
diff --git a/rev-list.c b/rev-list.c
--- a/rev-list.c
+++ b/rev-list.c
@@ -228,6 +228,17 @@ static void mark_parents_uninteresting(s
 		commit->object.flags |= UNINTERESTING;
 
 		/*
+		 * Normally we haven't parsed the parent
+		 * yet, so we won't have a parent of a parent
+		 * here. However, it may turn out that we've
+		 * reached this commit some other way (where it
+		 * wasn't uninteresting), in which case we need
+		 * to mark its parents recursively too..
+		 */
+		if (commit->parents)
+			mark_parents_uninteresting(commit);
+
+		/*
 		 * A missing commit is ok iff its parent is marked 
 		 * uninteresting.
 		 *
Next: Ryan Anderson
Message 1 of 15 in “Fix interesting git-rev-list corner case”
  1. Linus TorvaldsJul 29, 2005
  2. Ryan AndersonJul 30, 2005
  3. A Large Angry SCMJul 30, 2005
  4. Linus TorvaldsJul 30, 2005
  5. Linus TorvaldsJul 30, 2005
  6. Peter OsterlundJul 30, 2005
  7. Linus TorvaldsJul 30, 2005
  8. Peter OsterlundJul 30, 2005
  9. Linus TorvaldsJul 30, 2005
  10. Peter OsterlundJul 30, 2005
  11. Linus TorvaldsJul 30, 2005
  12. Linus TorvaldsJul 30, 2005
  13. Peter OsterlundJul 30, 2005
  14. Linus TorvaldsJul 31, 2005
  15. Junio C HamanoJul 31, 2005

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.