Get tests passing again.
[git-central.git] / server / post-receive-commitnumbers
1 #!/bin/bash
2 #
3 # Creates commitnumbers as lightweight tags named "r/X" where X increases
4 # monotonically.
5 #
6 # Works by creating a GIT_DIR/commitnumbers file that is a list of all
7 # commit SHA1s where the commitnumber == the line number of the SHA1 in the
8 # file.
9 #
10 # If you're adding commitnumbers to an existing repo, you can jump start it
11 # (without the tags, but so you don't start at 0), by:
12 #
13 #     git rev-list --all > $GIT_DIR/commitnumbers
14 #
15 # There is no real reason the tags are named "r/X"--feel free to substitute your
16 # own prefix or drop it all together. That should probably be a config variable.
17 #
18
19 . $(dirname $0)/functions
20
21 while read oldrev newrev refname ; do
22         set_new_commits
23         echo "$new_commits" | git rev-list --reverse --stdin | while read commit ; do
24                 if [[ $(grep "$commit" "$GIT_DIR/commitnumbers" 2>/dev/null) == "" ]] ; then
25                         with_lock "$GIT_DIR/commitnumbers.lock" 'echo "$commit $refname" >> "$GIT_DIR/commitnumbers"'
26                         number=$(grep --max-count=1 --line-number "$commit" "$GIT_DIR/commitnumbers" | grep -oP "^\d+(?=:)")
27                         git tag "r/$number" "$commit"
28                 fi
29         done
30 done
31