From 8f22e3b529f02ad4b7b91fe40903f84ce4f11612 Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Mon, 29 Sep 2008 03:36:54 -0500 Subject: [PATCH] Append to a separate "commitnumbers" to avoid race conditions. 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 | 13 +++++-------- ...00-server-post-receive-assign-commit-numbers.sh | 14 +++++++------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/server/post-receive-assign-commit-numbers b/server/post-receive-assign-commit-numbers index 9d424b1..6ed313d 100644 --- a/server/post-receive-assign-commit-numbers +++ b/server/post-receive-assign-commit-numbers @@ -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 diff --git a/tests/t3200-server-post-receive-assign-commit-numbers.sh b/tests/t3200-server-post-receive-assign-commit-numbers.sh index 6e76cd6..4f8f924 100644 --- a/tests/t3200-server-post-receive-assign-commit-numbers.sh +++ b/tests/t3200-server-post-receive-assign-commit-numbers.sh @@ -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 -- 2.39.5