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

[RFC/PATCH 7/7] mktag: call "check_sha1_signature" with the replacement sha1

From
Christian Couder <chriscool@tuxfamily.org>
Date
Jan 12, 2009, 17:51 UTC
Message-ID
<20090112185126.a3984b7d.chriscool@tuxfamily.org>
Otherwise we get a "sha1 mismatch" error for replaced objects.

While at it, this patch makes the first argument of "verify_object" const.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 mktag.c            |    7 ++++---
 t/t6050-replace.sh |   11 +++++++++++
 2 files changed, 15 insertions(+), 3 deletions(-)
	Note that I am not sure at all that this is a good change.
	It may be that we should just refuse to tag a replaced object. But
	in this case we should probably give a meaningfull error message
	instead of "sha1 mismatch".
	Otherwise I checked the 2 other calls to "check_sha1_signature" and
	they look like they don't need any change.
diff --git a/mktag.c b/mktag.c
index ba3d495..ac812e5 100644
--- a/mktag.c
+++ b/mktag.c
@@ -18,16 +18,17 @@
 /*
  * We refuse to tag something we can't verify. Just because.
  */
-static int verify_object(unsigned char *sha1, const char *expected_type)
+static int verify_object(const unsigned char *sha1, const char *expected_type)
 {
 	int ret = -1;
 	enum object_type type;
 	unsigned long size;
-	void *buffer = read_sha1_file(sha1, &type, &size);
+	const unsigned char *repl;
+	void *buffer = read_sha1_file_repl(sha1, &type, &size, &repl);
 
 	if (buffer) {
 		if (type == type_from_string(expected_type))
-			ret = check_sha1_signature(sha1, buffer, size, expected_type);
+			ret = check_sha1_signature(repl, buffer, size, expected_type);
 		free(buffer);
 	}
 	return ret;
diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh
index 0a585ec..697e0f6 100755
--- a/t/t6050-replace.sh
+++ b/t/t6050-replace.sh
@@ -70,6 +70,17 @@ test_expect_success 'replace the author' '
      git show $HASH2 | grep "O Thor"
 '
 
+cat >tag.sig <<EOF
+object $HASH2
+type commit
+tag mytag
+tagger T A Gger <> 0 +0000
+
+EOF
+
+test_expect_success 'tag replaced commit' \
+    'git mktag <tag.sig >.git/refs/tags/mytag 2>message'
+
 #
 #
 test_done
-- 
1.6.1.83.g16e5
Message 1 of 1 in “mktag: call "check_sha1_signature" with the replacement sha1”
  1. 7/7 mktag: call "check_sha1_signature" with the replacement sha1Christian Couder, Jan 12, 2009

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.