Append to a separate "commitnumbers" to avoid race conditions.
authorStephen Haberman <stephen@exigencecorp.com>
Mon, 29 Sep 2008 08:36:54 +0000 (03:36 -0500)
committerStephen Haberman <stephen@exigencecorp.com>
Mon, 29 Sep 2008 08:36:54 +0000 (03:36 -0500)
Also use `git tag` to create the tag instead of mucking directly with
packed-refs. The refs will end up there eventually upon gc.

server/post-receive-assign-commit-numbers
tests/t3200-server-post-receive-assign-commit-numbers.sh

index 9d424b1..6ed313d 100644 (file)
@@ -5,15 +5,12 @@
 while read oldrev newrev refname ; do
        set_new_commits
        echo "$new_commits" | git rev-list --reverse --stdin | while read commit ; do
-               cat $GIT_DIR/packed-refs | grep --quiet "$commit"
+               touch "$GIT_DIR/commitnumbers"
+               cat "$GIT_DIR/commitnumbers" | grep --quiet "$commit"
                if [ $? -ne 0 ] ; then
-                       current=$(cat $GIT_DIR/packed-refs | grep "refs/tags/r/" | tail -n 1 | grep -oP "r\/\d+" | grep -oP "\d+")
-                       if [ $? -ne 0 ] ; then
-                               next="0"
-                       else
-                               next=$(($current + 1))
-                       fi
-                       echo "$commit refs/tags/r/$next" >> $GIT_DIR/packed-refs
+                       echo "$commit" >> "$GIT_DIR/commitnumbers"
+                       number=$(cat "$GIT_DIR/commitnumbers" | grep --line-number "$commit" | grep -oP "^\d+(?=:)")
+                       git tag "r/$number" "$commit"
                fi
        done
 done
index 6e76cd6..4f8f924 100644 (file)
@@ -25,8 +25,8 @@ test_expect_success 'assign one new commit' '
        git push origin master &&
        git fetch &&
 
-       test "$(git rev-parse HEAD)" = "$(git rev-parse r/0)"
-       test "$(git describe --tags)" = "r/0"
+       test "$(git rev-parse HEAD)" = "$(git rev-parse r/1)"
+       test "$(git describe --tags)" = "r/1"
 '
 
 test_expect_success 'assign two new commits' '
@@ -37,11 +37,11 @@ test_expect_success 'assign two new commits' '
        git push origin master &&
        git fetch &&
 
-       test "$(git rev-parse HEAD)" = "$(git rev-parse r/2)"
-       test "$(git describe --tags)" = "r/2"
+       test "$(git rev-parse HEAD)" = "$(git rev-parse r/3)"
+       test "$(git describe --tags)" = "r/3"
 
-       test "$(git rev-parse HEAD^)" = "$(git rev-parse r/1)"
-       test "$(git describe --tags HEAD^)" = "r/1"
+       test "$(git rev-parse HEAD^)" = "$(git rev-parse r/2)"
+       test "$(git describe --tags HEAD^)" = "r/2"
 '
 
 test_expect_success 'pushing commits to a new branch does not reassign' '
@@ -50,7 +50,7 @@ test_expect_success 'pushing commits to a new branch does not reassign' '
        git push origin topica &&
        git fetch &&
 
-       ! git rev-parse r/3
+       ! git rev-parse r/4
 '
 
 test_done