Shawn O. Pearce | a949fa5 | 2009-08-22 18:17:46 -0700 | [diff] [blame] | 1 | #!/bin/sh |
Shawn O. Pearce | 15f6579 | 2009-08-22 19:23:55 -0700 | [diff] [blame^] | 2 | # From Gerrit Code Review v2.0.18-100-g98fc90a |
| 3 | # |
| 4 | # Part of Gerrit Code Review (http://code.google.com/p/gerrit/) |
| 5 | # |
| 6 | # Copyright (C) 2009 The Android Open Source Project |
| 7 | # |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | # you may not use this file except in compliance with the License. |
| 10 | # You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
| 19 | # |
Shawn O. Pearce | a949fa5 | 2009-08-22 18:17:46 -0700 | [diff] [blame] | 20 | |
| 21 | MSG="$1" |
| 22 | |
| 23 | # Check for, and add if missing, a unique Change-Id |
| 24 | # |
| 25 | add_ChangeId() { |
| 26 | if grep '^Change-Id: ' "$MSG" >/dev/null |
| 27 | then |
| 28 | return |
| 29 | fi |
| 30 | |
| 31 | id=$(_gen_ChangeId) |
| 32 | out="$MSG.new" |
| 33 | ftt="$MSG.footers" |
Shawn O. Pearce | 15f6579 | 2009-08-22 19:23:55 -0700 | [diff] [blame^] | 34 | sed -e '2,${ |
| 35 | /^[A-Za-z][A-Za-z0-9-]*: /,$d |
| 36 | }' <"$MSG" >"$out" |
| 37 | sed -ne '2,${ |
| 38 | /^[A-Za-z][A-Za-z0-9-]*: /,$p |
| 39 | }' <"$MSG" >"$ftt" |
Shawn O. Pearce | a949fa5 | 2009-08-22 18:17:46 -0700 | [diff] [blame] | 40 | if ! [ -s "$ftt" ] |
| 41 | then |
| 42 | echo >>"$out" |
| 43 | fi |
| 44 | echo "Change-Id: I$id" >>"$out" |
| 45 | cat "$ftt" >>"$out" |
| 46 | mv -f "$out" "$MSG" |
| 47 | rm -f "$out" "$ftt" |
| 48 | } |
| 49 | _gen_ChangeIdInput() { |
| 50 | echo "tree $(git write-tree)" |
| 51 | if parent=$(git rev-parse HEAD^0 2>/dev/null) |
| 52 | then |
| 53 | echo "parent $parent" |
| 54 | fi |
| 55 | echo "author $(git var GIT_AUTHOR_IDENT)" |
| 56 | echo "committer $(git var GIT_COMMITTER_IDENT)" |
| 57 | echo |
| 58 | cat "$MSG" |
| 59 | } |
| 60 | _gen_ChangeId() { |
| 61 | _gen_ChangeIdInput | |
| 62 | git hash-object -t commit --stdin |
| 63 | } |
| 64 | |
| 65 | |
| 66 | add_ChangeId |