Shawn O. Pearce | a949fa5 | 2009-08-22 18:17:46 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | MSG="$1" |
| 4 | |
| 5 | # Check for, and add if missing, a unique Change-Id |
| 6 | # |
| 7 | add_ChangeId() { |
| 8 | if grep '^Change-Id: ' "$MSG" >/dev/null |
| 9 | then |
| 10 | return |
| 11 | fi |
| 12 | |
| 13 | id=$(_gen_ChangeId) |
| 14 | out="$MSG.new" |
| 15 | ftt="$MSG.footers" |
| 16 | sed -e '/^[A-Za-z][A-Za-z0-9-]*: /,$d' <"$MSG" >"$out" |
| 17 | sed -ne '/^[A-Za-z][A-Za-z0-9-]*: /,$p' <"$MSG" >"$ftt" |
| 18 | if ! [ -s "$ftt" ] |
| 19 | then |
| 20 | echo >>"$out" |
| 21 | fi |
| 22 | echo "Change-Id: I$id" >>"$out" |
| 23 | cat "$ftt" >>"$out" |
| 24 | mv -f "$out" "$MSG" |
| 25 | rm -f "$out" "$ftt" |
| 26 | } |
| 27 | _gen_ChangeIdInput() { |
| 28 | echo "tree $(git write-tree)" |
| 29 | if parent=$(git rev-parse HEAD^0 2>/dev/null) |
| 30 | then |
| 31 | echo "parent $parent" |
| 32 | fi |
| 33 | echo "author $(git var GIT_AUTHOR_IDENT)" |
| 34 | echo "committer $(git var GIT_COMMITTER_IDENT)" |
| 35 | echo |
| 36 | cat "$MSG" |
| 37 | } |
| 38 | _gen_ChangeId() { |
| 39 | _gen_ChangeIdInput | |
| 40 | git hash-object -t commit --stdin |
| 41 | } |
| 42 | |
| 43 | |
| 44 | add_ChangeId |