blob: 5b1fe3ae3c0d7af8dd826a00f4047f1ddf70ac1c [file] [log] [blame]
Shawn O. Pearcea949fa52009-08-22 18:17:46 -07001#!/bin/sh
Shawn O. Pearce15f65792009-08-22 19:23:55 -07002# 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. Pearcea949fa52009-08-22 18:17:46 -070020
21MSG="$1"
22
23# Check for, and add if missing, a unique Change-Id
24#
25add_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. Pearce15f65792009-08-22 19:23:55 -070034 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. Pearcea949fa52009-08-22 18:17:46 -070040 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
66add_ChangeId