2 # From Gerrit Code Review 2.1.7-rc2
4 # Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
6 # Copyright (C) 2009 The Android Open Source Project
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
12 # http://www.apache.org/licenses/LICENSE-2.0
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.
21 CHANGE_ID_AFTER="Bug|Issue"
24 # Check for, and add if missing, a unique Change-Id
27 clean_message=`sed -e '
34 ' "$MSG" | git stripspace`
35 if test -z "$clean_message"
40 if grep -i '^Change-Id:' "$MSG" >/dev/null
49 $CHANGE_ID_AFTER = shift;
52 open(I, $MSG); $_ = <I>; close I;
53 s|^diff --git a/.*||ms;
57 @message = split /\n/;
59 $startFooter = @message;
60 for($line = @message - 1; $line >= 0; $line--) {
63 if (/^[a-zA-Z0-9-]+:/ && !m,^[a-z0-9-]+://,) {
68 $startFooter = $line if ($haveFooter && /^\r?$/);
72 @footer = @message[$startFooter+1..@message];
73 @message = @message[0..$startFooter];
74 push(@footer, "") unless @footer;
76 for ($line = 0; $line < @footer; $line++) {
78 next if /^($CHANGE_ID_AFTER):/i;
81 splice(@footer, $line, 0, "Change-Id: I$id");
83 $_ = join("\n", @message, @footer);
84 open(O, ">$MSG"); print O; close O;
85 ' "$MSG" "$id" "$CHANGE_ID_AFTER"
87 _gen_ChangeIdInput() {
88 echo "tree `git write-tree`"
89 if parent=`git rev-parse HEAD^0 2>/dev/null`
93 echo "author `git var GIT_AUTHOR_IDENT`"
94 echo "committer `git var GIT_COMMITTER_IDENT`"
96 printf '%s' "$clean_message"
100 git hash-object -t commit --stdin