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

[PATCH v2] parse_object: pass on the original sha1, not the replaced one

From
Christian Couder <chriscool@tuxfamily.org>
Date
Sep 3, 2010, 20:51 UTC
Message-ID
<20100903205154.4894.4393.chriscool@tuxfamily.org>
From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= <pclouds@gmail.com>

Commit 0e87c36 (object: call "check_sha1_signature" with the replacement sha1) changed the first argument passed to parse_object_buffer() from "sha1" to "repl". With that change, the returned obj pointer has the replacement SHA1 in obj->sha1, not the original one.

But when using lookup_commit() and then parse_commit() on a commit, we get an object pointer with the original sha1, but the commit content comes from the replacement commit.

So the result we get from using parse_object() is different from the we get from using lookup_commit() followed by parse_commit().

It looks much simpler and safer to fix this inconsistency by passing "sha1" to parse_object_bufer() instead of "repl".

The commit comment should be used to tell the the replacement commit is replacing another commit and why. So it should be easy to see that we have a replacement commit instead of an original one.

And it is not a problem if the content of the commit is not consistent with the sha1 as cat-file piped to hash-object can be used to see the difference.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
The only change since previous version is that the test case
breakage in t6050 is fixed.
 object.c           |    2 +-
 t/t6050-replace.sh |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/object.c b/object.c
index 277b3dd..7adfda7 100644
--- a/object.c
+++ b/object.c
@@ -199,7 +199,7 @@ struct object *parse_object(const unsigned char *sha1)
 			return NULL;
 		}
 
-		obj = parse_object_buffer(repl, type, size, buffer, &eaten);
+		obj = parse_object_buffer(sha1, type, size, buffer, &eaten);
 		if (!eaten)
 			free(buffer);
 		return obj;
diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh
index 4185b7c..dd917d7 100755
--- a/t/t6050-replace.sh
+++ b/t/t6050-replace.sh
@@ -209,7 +209,7 @@ test_expect_success 'fetch branch with replacement' '
 
 test_expect_success 'bisect and replacements' '
      git bisect start $HASH7 $HASH1 &&
-     test "$S" = "$(git rev-parse --verify HEAD)" &&
+     test "$PARA3" = "$(git rev-parse --verify HEAD)" &&
      git bisect reset &&
      GIT_NO_REPLACE_OBJECTS=1 git bisect start $HASH7 $HASH1 &&
      test "$HASH4" = "$(git rev-parse --verify HEAD)" &&
-- 
1.7.2.2.576.g2f52
Message 1 of 1 in “parse_object: pass on the original sha1, not the replaced one”
  1. parse_object: pass on the original sha1, not the replaced oneChristian Couder, Sep 3, 2010

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.