Skip to content

Commit 2e3400c

Browse files
pcloudsgitster
authored andcommitted
parse_object: pass on the original sha1, not the replaced one
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ad33605 commit 2e3400c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ struct object *parse_object(const unsigned char *sha1)
199199
return NULL;
200200
}
201201

202-
obj = parse_object_buffer(repl, type, size, buffer, &eaten);
202+
obj = parse_object_buffer(sha1, type, size, buffer, &eaten);
203203
if (!eaten)
204204
free(buffer);
205205
return obj;

t/t6050-replace.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ test_expect_success 'fetch branch with replacement' '
209209

210210
test_expect_success 'bisect and replacements' '
211211
git bisect start $HASH7 $HASH1 &&
212-
test "$S" = "$(git rev-parse --verify HEAD)" &&
212+
test "$PARA3" = "$(git rev-parse --verify HEAD)" &&
213213
git bisect reset &&
214214
GIT_NO_REPLACE_OBJECTS=1 git bisect start $HASH7 $HASH1 &&
215215
test "$HASH4" = "$(git rev-parse --verify HEAD)" &&

0 commit comments

Comments
 (0)