{"thread":{"id":"24965","subject":"[PATCH v2] parse_object: pass on the original sha1, not the replaced one","startedAt":"2010-09-03T20:51:53Z","lastAt":"2010-09-03T20:51:53Z","messageCount":1,"participants":["Christian Couder"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"149814","messageId":"20100903205154.4894.4393.chriscool@tuxfamily.org","threadId":"24965","inReplyTo":null,"subject":"[PATCH v2] parse_object: pass on the original sha1, not the replaced one","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2010-09-03T20:51:53Z","receivedAt":"2010-09-03T20:51:53Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= <pclouds@gmail.com>\n\nCommit 0e87c36 (object: call \"check_sha1_signature\" with the\nreplacement sha1) changed the first argument passed to\nparse_object_buffer() from \"sha1\" to \"repl\". With that change,\nthe returned obj pointer has the replacement SHA1 in obj->sha1,\nnot the original one.\n\nBut when using lookup_commit() and then parse_commit() on a\ncommit, we get an object pointer with the original sha1, but\nthe commit content comes from the replacement commit.\n\nSo the result we get from using parse_object() is different\nfrom the we get from using lookup_commit() followed by\nparse_commit().\n\nIt looks much simpler and safer to fix this inconsistency by\npassing \"sha1\" to parse_object_bufer() instead of \"repl\".\n\nThe commit comment should be used to tell the the replacement\ncommit is replacing another commit and why. So it should be\neasy to see that we have a replacement commit instead of an\noriginal one.\n\nAnd it is not a problem if the content of the commit is not\nconsistent with the sha1 as cat-file piped to hash-object can\nbe used to see the difference.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\nThe only change since previous version is that the test case\nbreakage in t6050 is fixed.\n\n object.c           |    2 +-\n t/t6050-replace.sh |    2 +-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/object.c b/object.c\nindex 277b3dd..7adfda7 100644\n--- a/object.c\n+++ b/object.c\n@@ -199,7 +199,7 @@ struct object *parse_object(const unsigned char *sha1)\n \t\t\treturn NULL;\n \t\t}\n \n-\t\tobj = parse_object_buffer(repl, type, size, buffer, &eaten);\n+\t\tobj = parse_object_buffer(sha1, type, size, buffer, &eaten);\n \t\tif (!eaten)\n \t\t\tfree(buffer);\n \t\treturn obj;\ndiff --git a/t/t6050-replace.sh b/t/t6050-replace.sh\nindex 4185b7c..dd917d7 100755\n--- a/t/t6050-replace.sh\n+++ b/t/t6050-replace.sh\n@@ -209,7 +209,7 @@ test_expect_success 'fetch branch with replacement' '\n \n test_expect_success 'bisect and replacements' '\n      git bisect start $HASH7 $HASH1 &&\n-     test \"$S\" = \"$(git rev-parse --verify HEAD)\" &&\n+     test \"$PARA3\" = \"$(git rev-parse --verify HEAD)\" &&\n      git bisect reset &&\n      GIT_NO_REPLACE_OBJECTS=1 git bisect start $HASH7 $HASH1 &&\n      test \"$HASH4\" = \"$(git rev-parse --verify HEAD)\" &&\n-- \n1.7.2.2.576.g2f52\n"}]}