From a8563ec8515d87259590a7aad182922def8e2cf2 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 26 Aug 2009 16:39:10 -0700 Subject: upload-pack: add a trigger for post-upload-pack hook After upload-pack successfully finishes its operation, post-upload-pack hook can be called for logging purposes. The hook is passed various pieces of information, one per line, from its standard input. Currently the following items can be fed to the hook, but more types of information may be added in the future: want SHA-1:: 40-byte hexadecimal object name the client asked to include in the resulting pack. Can occur one or more times in the input. have SHA-1:: 40-byte hexadecimal object name the client asked to exclude from the resulting pack, claiming to have them already. Can occur zero or more times in the input. time float:: Number of seconds spent for creating the packfile. size decimal:: Size of the resulting packfile in bytes. Signed-off-by: Junio C Hamano --- t/t5501-post-upload-pack.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 t/t5501-post-upload-pack.sh (limited to 't') diff --git a/t/t5501-post-upload-pack.sh b/t/t5501-post-upload-pack.sh new file mode 100755 index 000000000..47ee7b503 --- /dev/null +++ b/t/t5501-post-upload-pack.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +test_description='post upload-hook' + +. ./test-lib.sh + +LOGFILE=".git/post-upload-pack-log" + +test_expect_success setup ' + test_commit A && + test_commit B && + git reset --hard A && + test_commit C && + git branch prev B && + mkdir -p .git/hooks && + { + echo "#!$SHELL_PATH" && + echo "cat >post-upload-pack-log" + } >".git/hooks/post-upload-pack" && + chmod +x .git/hooks/post-upload-pack +' + +test_expect_success initial ' + rm -fr sub && + git init sub && + ( + cd sub && + git fetch --no-tags .. prev + ) && + want=$(sed -n "s/^want //p" "$LOGFILE") && + test "$want" = "$(git rev-parse --verify B)" && + ! grep "^have " "$LOGFILE" +' + +test_expect_success second ' + rm -fr sub && + git init sub && + ( + cd sub && + git fetch --no-tags .. prev:refs/remotes/prev && + git fetch --no-tags .. master + ) && + want=$(sed -n "s/^want //p" "$LOGFILE") && + test "$want" = "$(git rev-parse --verify C)" && + have=$(sed -n "s/^have //p" "$LOGFILE") && + test "$have" = "$(git rev-parse --verify B)" +' + +test_done -- cgit v1.2.1 From 11cae066b2433fcec807810b45f317f8203df358 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 28 Aug 2009 22:19:45 -0700 Subject: 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 --- t/t5501-post-upload-pack.sh | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/t5501-post-upload-pack.sh b/t/t5501-post-upload-pack.sh index 47ee7b503..d89fb51ba 100755 --- a/t/t5501-post-upload-pack.sh +++ b/t/t5501-post-upload-pack.sh @@ -29,7 +29,9 @@ test_expect_success initial ' ) && want=$(sed -n "s/^want //p" "$LOGFILE") && test "$want" = "$(git rev-parse --verify B)" && - ! grep "^have " "$LOGFILE" + ! grep "^have " "$LOGFILE" && + kind=$(sed -n "s/^kind //p" "$LOGFILE") && + test "$kind" = fetch ' test_expect_success second ' @@ -43,7 +45,25 @@ test_expect_success second ' want=$(sed -n "s/^want //p" "$LOGFILE") && test "$want" = "$(git rev-parse --verify C)" && have=$(sed -n "s/^have //p" "$LOGFILE") && - test "$have" = "$(git rev-parse --verify B)" + test "$have" = "$(git rev-parse --verify B)" && + kind=$(sed -n "s/^kind //p" "$LOGFILE") && + test "$kind" = fetch +' + +test_expect_success all ' + rm -fr sub && + HERE=$(pwd) && + git init sub && + ( + cd sub && + git clone "file://$HERE/.git" new + ) && + sed -n "s/^want //p" "$LOGFILE" | sort >actual && + git rev-parse A B C | sort >expect && + test_cmp expect actual && + ! grep "^have " "$LOGFILE" && + kind=$(sed -n "s/^kind //p" "$LOGFILE") && + test "$kind" = clone ' test_done -- cgit v1.2.1