summaryrefslogtreecommitdiffstats
path: root/hooks/commit-msg
diff options
context:
space:
mode:
Diffstat (limited to 'hooks/commit-msg')
-rwxr-xr-xhooks/commit-msg64
1 files changed, 43 insertions, 21 deletions
diff --git a/hooks/commit-msg b/hooks/commit-msg
index fd76c074..712921c9 100755
--- a/hooks/commit-msg
+++ b/hooks/commit-msg
@@ -1,23 +1,24 @@
1#!/bin/sh 1#!/bin/sh
2# From Gerrit Code Review v2.0.19.1-4-g21d307b 2# From Gerrit Code Review 2.1.2-rc2-33-g7e30c72
3# 3#
4# Part of Gerrit Code Review (http://code.google.com/p/gerrit/) 4# Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
5# 5#
6# Copyright (C) 2009 The Android Open Source Project 6# Copyright (C) 2009 The Android Open Source Project
7# 7#
8# Licensed under the Apache License, Version 2.0 (the "License"); 8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with 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 10# You may obtain a copy of the License at
11# 11#
12# http://www.apache.org/licenses/LICENSE-2.0 12# http://www.apache.org/licenses/LICENSE-2.0
13# 13#
14# Unless required by applicable law or agreed to in writing, software 14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, 15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and 17# See the License for the specific language governing permissions and
18# limitations under the License. 18# limitations under the License.
19# 19#
20 20
21CHANGE_ID_AFTER="Bug|Issue"
21MSG="$1" 22MSG="$1"
22 23
23# Check for, and add if missing, a unique Change-Id 24# Check for, and add if missing, a unique Change-Id
@@ -42,22 +43,43 @@ add_ChangeId() {
42 fi 43 fi
43 44
44 id=$(_gen_ChangeId) 45 id=$(_gen_ChangeId)
45 out="$MSG.OUT" 46 perl -e '
46 ftt="$MSG.FTT" 47 $MSG = shift;
47 sed -e '2,${ 48 $id = shift;
48 /^[A-Za-z][A-Za-z0-9-]*: /,$d 49 $CHANGE_ID_AFTER = shift;
49 }' <"$MSG" >"$out" 50
50 sed -ne '2,${ 51 undef $/;
51 /^[A-Za-z][A-Za-z0-9-]*: /,$p 52 open(I, $MSG); $_ = <I>; close I;
52 }' <"$MSG" >"$ftt" 53 s|^diff --git a/.*||ms;
53 if ! test -s "$ftt" 54 s|^#.*$||mg;
54 then 55 exit unless $_;
55 echo >>"$out" 56
56 fi 57 @message = split /\n/;
57 echo "Change-Id: I$id" >>"$out" 58 $haveFooter = 0;
58 cat "$ftt" >>"$out" 59 $startFooter = @message;
59 mv -f "$out" "$MSG" 60 for($line = @message - 1; $line >= 0; $line--) {
60 rm -f "$out" "$ftt" 61 $_ = $message[$line];
62
63 ($haveFooter++, next) if /^[a-zA-Z0-9-]+:/;
64 next if /^[ []/;
65 $startFooter = $line if ($haveFooter && /^\r?$/);
66 last;
67 }
68
69 @footer = @message[$startFooter+1..@message];
70 @message = @message[0..$startFooter];
71 push(@footer, "") unless @footer;
72
73 for ($line = 0; $line < @footer; $line++) {
74 $_ = $footer[$line];
75 next if /^($CHANGE_ID_AFTER):/i;
76 last;
77 }
78 splice(@footer, $line, 0, "Change-Id: I$id");
79
80 $_ = join("\n", @message, @footer);
81 open(O, ">$MSG"); print O; close O;
82 ' "$MSG" "$id" "$CHANGE_ID_AFTER"
61} 83}
62_gen_ChangeIdInput() { 84_gen_ChangeIdInput() {
63 echo "tree $(git write-tree)" 85 echo "tree $(git write-tree)"