@matheusbsbs / matheus-bagliano / commits / 11cae066b2
Fork 0

upload-pack: feed "kind [clone|fetch]" to post-upload-pack hook

A request to clone the repository does not give any "have" but asks for all the refs we offer with "want". When a request does not ask to clone the repository fully, but asks to fetch some refs into an empty repository, it will not give any "have" but its "want" won't ask for all the refs we offer. If we suppose (and I would say this is a rather big if) that it makes sense to distinguish these two cases, a hook cannot reliably do this alone. The hook can detect lack of "have" and bunch of "want", but there is no direct way to tell if the other end asked for all refs we offered, or merely most of them. Between the time we talked with the other end and the time the hook got called, we may have acquired more refs or lost some refs in the repository by concurrent operations. Given that we plan to introduce selective advertisement of refs with a protocol extension, it would become even more difficult for hooks to guess between these two cases. This adds "kind [clone|fetch]" to hook's input, as a stable interface to allow the hooks to tell these cases apart. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 28, 2009 at 22:19 UTC 11cae066b2433fcec807810b45f317f8203df358
3 files changed +30 -2
Documentation/githooks.txt
+4
@@ -332,6 +332,10 @@ time float::
332 size decimal::
333 Size of the resulting packfile in bytes.
334
335 +kind string:
336 + Either "clone" (when the client did not give us any "have", and asked
337 + for all our refs with "want"), or "fetch" (otherwise).
338 +
339 pre-auto-gc
340 -----------
341
t/t5501-post-upload-pack.sh
+22 -2
@@ -29,7 +29,9 @@ test_expect_success initial '
29 ) &&
30 want=$(sed -n "s/^want //p" "$LOGFILE") &&
31 test "$want" = "$(git rev-parse --verify B)" &&
32 - ! grep "^have " "$LOGFILE"
32 + ! grep "^have " "$LOGFILE" &&
33 + kind=$(sed -n "s/^kind //p" "$LOGFILE") &&
34 + test "$kind" = fetch
35 '
36
37 test_expect_success second '
@@ -43,7 +45,25 @@ test_expect_success second '
45 want=$(sed -n "s/^want //p" "$LOGFILE") &&
46 test "$want" = "$(git rev-parse --verify C)" &&
47 have=$(sed -n "s/^have //p" "$LOGFILE") &&
46 - test "$have" = "$(git rev-parse --verify B)"
48 + test "$have" = "$(git rev-parse --verify B)" &&
49 + kind=$(sed -n "s/^kind //p" "$LOGFILE") &&
50 + test "$kind" = fetch
51 +'
52 +
53 +test_expect_success all '
54 + rm -fr sub &&
55 + HERE=$(pwd) &&
56 + git init sub &&
57 + (
58 + cd sub &&
59 + git clone "file://$HERE/.git" new
60 + ) &&
61 + sed -n "s/^want //p" "$LOGFILE" | sort >actual &&
62 + git rev-parse A B C | sort >expect &&
63 + test_cmp expect actual &&
64 + ! grep "^have " "$LOGFILE" &&
65 + kind=$(sed -n "s/^kind //p" "$LOGFILE") &&
66 + test "$kind" = clone
67 '
68
69 test_done
upload-pack.c
+4
@@ -187,6 +187,10 @@ static int run_post_upload_pack_hook(size_t total, struct timeval *tv)
187 (long)tv->tv_sec, (long)tv->tv_usec);
188 if (!err)
189 err |= feed_msg_to_hook(proc.in, "size %ld\n", (long)total);
190 + if (!err)
191 + err |= feed_msg_to_hook(proc.in, "kind %s\n",
192 + (nr_our_refs == want_obj.nr && !have_obj.nr)
193 + ? "clone" : "fetch");
194 if (close(proc.in))
195 err = 1;
196 if (finish_command(&proc))