fetch-pack: fix object_id of exact sha1

Commit 58f2ed0 (remote-curl: pass ref SHA-1 to fetch-pack as well, 2013-12-05) added support for specifying a SHA-1 as well as a ref name. Add support for specifying just a SHA-1 and set the ref name to the same value in this case. Signed-off-by: Gabriel Souza Franco <gabrielfrancosouza@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Gabriel Souza Franco committed Feb 29, 2016 at 23:12 UTC 4a8d202c4e95472c7dc7444fd314037090cf08a1
2 files changed +27 -3
builtin/fetch-pack.c
+13 -3
@@ -16,10 +16,20 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,
16 struct ref *ref;
17 struct object_id oid;
18
19 - if (!get_oid_hex(name, &oid) && name[GIT_SHA1_HEXSZ] == ' ')
20 - name += GIT_SHA1_HEXSZ + 1;
21 - else
19 + if (!get_oid_hex(name, &oid)) {
20 + if (name[GIT_SHA1_HEXSZ] == ' ') {
21 + /* <sha1> <ref>, find refname */
22 + name += GIT_SHA1_HEXSZ + 1;
23 + } else if (name[GIT_SHA1_HEXSZ] == '\0') {
24 + ; /* <sha1>, leave sha1 as name */
25 + } else {
26 + /* <ref>, clear cruft from oid */
27 + oidclr(&oid);
28 + }
29 + } else {
30 + /* <ref>, clear cruft from get_oid_hex */
31 oidclr(&oid);
32 + }
33
34 ref = alloc_ref(name);
35 oidcpy(&ref->old_oid, &oid);
t/t5500-fetch-pack.sh
+14
@@ -531,6 +531,20 @@ test_expect_success 'shallow fetch with tags does not break the repository' '
531 git fsck
532 )
533 '
534 +
535 +test_expect_success 'fetch-pack can fetch a raw sha1' '
536 + git init hidden &&
537 + (
538 + cd hidden &&
539 + test_commit 1 &&
540 + test_commit 2 &&
541 + git update-ref refs/hidden/one HEAD^ &&
542 + git config transfer.hiderefs refs/hidden &&
543 + git config uploadpack.allowtipsha1inwant true
544 + ) &&
545 + git fetch-pack hidden $(git -C hidden rev-parse refs/hidden/one)
546 +'
547 +
548 check_prot_path () {
549 cat >expected <<-EOF &&
550 Diag: url=$1