Meta/Announce: mention release tarball location
[alt-git.git] / Reintegrate
blob8052dda9af584a1035b3b015ce91981110a05012
1 #!/bin/sh
3 accept_rerere="--rerere-autoupdate" generate=no update= diff= edit= stop_at_cut=
4 while case "$#,$1" in 0,*) break;; *,-*) ;; esac
5 do
6 case "$1" in
7 -n) accept_rerere= ;;
8 -e) edit=t ;;
9 -c) stop_at_cut=1 ;;
10 -c?*) stop_at_cut=${1#-c} ;;
11 -d) update=${2?"diff with what?"}
12 diff=yes
13 generate=yes
14 shift ;;
15 -u) update=${2?"update what?"}
16 generate=yes
17 shift ;;
18 *) generate=yes
19 break ;;
20 esac
21 shift
22 done
24 annotate_merge () {
25 test -f Meta/whats-cooking.txt || return 0
27 perl -e '
28 sub wildo_match {
29 s/^\s*//;
30 if (/^Will (?:\S+ ){0,2}(fast-track|keep|merge|drop|discard|cook|kick|defer|be re-?rolled)[,. ]/ ||
31 /^Not urgent/ || /^Not ready/ || /^Waiting for / ||
32 /^Needs? / || /^Expecting / || /^May want to /) {
33 return 1;
35 return 0;
38 my ($branch) = $ARGV[0];
39 my ($in_section, $in_desc);
40 my @msg = ();
41 while (<STDIN>) {
42 chomp;
43 if (/^\* $branch /) {
44 $in_section = 1;
45 next;
47 last if (/^[-*\[]/ && $in_section);
48 next unless $in_section;
49 s/^\s+//;
50 if (/^$/) {
51 $in_desc = 1;
53 next unless ($in_section && $in_desc);
54 next if (/Originally merged to '\''next'\'' on ([-0-9]+)/);
55 next if (wildo_match($_));
56 push @msg, "$_\n";
59 if ($in_section && @msg) {
60 open(my $fh, "-|", qw(git cat-file commit HEAD));
61 my @original = (<$fh>);
62 close $fh;
63 my @final;
64 $in_section = 0;
65 for (@original) {
66 if (!$in_section) {
67 $in_section = 1 if (/^$/);
68 next;
70 if (/^Conflicts:$/ && $in_section == 2) {
71 $in_section = 3;
74 if ($in_section == 3) {
75 $_ = "# $_";
77 push @final, $_;
78 if (/^$/ && $in_section == 1) {
79 push @final, @msg;
80 push @final, "\n";
81 $in_section = 2;
84 open($fh, "|-", qw(git commit --amend -F -));
85 print $fh @final;
86 close $fh;
88 ' <Meta/whats-cooking.txt "$1"
91 case "$generate" in
92 no)
93 accept_rerere () {
94 if ! git write-tree 2>/dev/null >/dev/null
95 then
96 git rerere remaining
97 return 1
98 else
99 EDITOR=: git commit --no-verify
100 echo "Accepted previous resolution"
101 return 0
105 mark_cut () {
106 test -n "$stop_at_cut" && return
108 count_since_last_cut=$(( $count_since_last_cut + 1 ))
109 test -z "$prev_cut" && return
110 git commit --allow-empty -m "$prev_cut"
111 prev_cut=
114 cut_seen=0 prev_cut= count_since_last_cut=0
115 while read branch eh
117 case "$branch" in '###') cut_seen=$(( $cut_seen + 1 )) ;; esac
118 if test -n "$stop_at_cut" && test $stop_at_cut -le $cut_seen
119 then
120 continue ;# slurp the remainder and skip
123 case "$branch" in
124 '###')
125 if test "$count_since_last_cut" = 0
126 then
127 prev_cut=
128 else
129 echo >&2 "$branch $eh"
130 prev_cut="$branch $eh"
131 count_since_last_cut=0
133 continue ;;
134 '#'* | '')
135 continue ;;
136 esac
138 case "$eh" in
139 "" | "#"*)
140 echo >&2 "* $branch"
142 save=$(git rev-parse --verify HEAD)
143 tip=$(git rev-parse --verify "$branch^0")
144 mb=$(git merge-base "$tip" "$save")
145 test "$mb" = "$tip" && continue
147 mark_cut
149 EDITOR=: git merge $accept_rerere --edit "$branch" ||
150 accept_rerere ||
151 exit
153 annotate_merge "$branch" || exit
154 test -z "$edit" ||
155 git commit --amend || exit
157 this=$(git rev-parse --verify HEAD)
158 if test "$this" = "$save"
159 then
161 elif git show-ref -q --verify "refs/merge-fix/$branch"
162 then
163 echo >&2 "Fixing up the merge"
164 git cherry-pick --no-commit "refs/merge-fix/$branch" &&
165 EDITOR=: git commit --amend -a || exit
168 pick" "*)
169 echo >&2 "* $eh"
171 mark_cut
173 git cherry-pick "$branch" || exit ;;
174 *) echo >&2 "Eh? $branch $eh"; exit ;;
175 esac
176 done
177 exit
178 esac
180 if test -n "$update" && test $# = 0
181 then
182 set x $(sed -n -e '2s/^# //p' <"$update") &&
183 shift
186 # Generation (or updating)
188 x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
189 x40="$x40$x40$x40$x40$x40$x40$x40$x40"
190 LF='
193 show_merge () {
194 case "$msg" in
195 "Merge branch '"*"'"*)
196 branch=$(expr "$msg" : "Merge branch '\(.*\)'")
197 merge_hier=heads/
199 "Merge remote branch '"*"'"*)
200 branch=$(expr "$msg" : "Merge remote branch '\(.*\)'")
201 merge_hier=
204 echo 2>&1 "Huh?: $msg"
205 return
207 esac &&
208 tip=$(git rev-parse --verify "refs/$merge_hier$branch" 2>/dev/null) &&
209 merged=$(git name-rev --refs="refs/$merge_hier$branch" "$other" 2>/dev/null) &&
210 merged=$(expr "$merged" : "$x40 \(.*\)") &&
211 test "$merged" != undefined || {
212 other=$(git log -1 --pretty='format:%s' $other) &&
213 merged="$branch :rebased? $other"
217 show_pick () {
218 case "$msg" in
219 "### "* | "###")
220 merged="$msg"
223 merged="$(git rev-parse --verify "$commit") pick $msg"
225 esac
229 generate () {
230 PROGRAM=$1
231 shift
232 echo '#!/bin/sh'
233 echo "# $1"
234 echo 'case "$#,$1" in'
235 echo '1,-u|1,-d)'
236 echo " exec $PROGRAM" '"$1" "$0"'
237 echo 'esac'
238 echo "$PROGRAM" '"$@" <<\EOF'
239 git log --no-decorate --pretty=oneline --first-parent "$1" |
241 series=
242 while read commit msg
244 if other=$(git rev-parse -q --verify "$commit^2")
245 then
246 show_merge
247 else
248 show_pick
251 if test -z "$series"
252 then
253 series="$merged"
254 else
255 series="$merged$LF$series"
257 done
258 echo "$series"
260 echo EOF
263 if test -z "$update"
264 then
265 generate "$0" "$@"
266 elif test -z "$diff"
267 then
268 generate "$0" "$@" | diff -u "$update" -
269 if test $? = 0
270 then
271 echo >&2 "No changes."
272 else
273 echo >&2 -n "Update [y/N]? "
274 read yesno
275 case "$yesno" in
276 [Yy]*)
277 generate "$0" "$@" |
278 sed -e 's/ :rebased?.*//' >"$update" ;;
280 echo >&2 "No update then." ;;
281 esac
283 else
284 generate "$0" "$@" | diff -u "$update" -