Add a with_lock function to ensure commitnumber appends do not interweave.
[git-central.git] / server / post-receive-assign-commit-numbers
index 46cd45a..39c3f48 100644 (file)
@@ -2,13 +2,11 @@
 
 . $(dirname $0)/functions
 
-touch "$GIT_DIR/commitnumbers"
-
 while read oldrev newrev refname ; do
        set_new_commits
        echo "$new_commits" | git rev-list --reverse --stdin | while read commit ; do
-               if [[ $(grep "$commit" "$GIT_DIR/commitnumbers") == "" ]] ; then
-                       echo "$commit" >> "$GIT_DIR/commitnumbers"
+               if [[ $(grep "$commit" "$GIT_DIR/commitnumbers" 2>/dev/null) == "" ]] ; then
+                       with_lock "$GIT_DIR/commitnumbers.lock" 'echo "$commit" >> "$GIT_DIR/commitnumbers"'
                        number=$(grep --max-count=1 --line-number "$commit" "$GIT_DIR/commitnumbers" | grep -oP "^\d+(?=:)")
                        git tag "r/$number" "$commit"
                fi