3 accept_rerere="--rerere-autoupdate"
6 update= diff= edit= stop_at_cut= skip_cocci= force_cocci= no_cocci=
7 while case "$#,$1" in 0,*) break;; *,-*) ;; esac
13 -c?*) stop_at_cut=${1#-c} ;;
14 -d) update=${2?"diff with what?"}
18 -u) update=${2?"update what?"}
21 -x) exec=${2?exec}; shift ;;
33 test -f Meta/whats-cooking.txt || return 0
35 # NEEDSWORK: unify with cook::wildo_match
39 if (/^Will (?:\S+ ){0,2}(fast-track|hold|keep|merge|drop|discard|cook|kick|defer|eject|be re-?rolled|wait)[,. ]/ ||
40 /^Not urgent/ || /^Not ready/ || /^Waiting for / ||
41 /^Can wait in / || /^Still / || /^Stuck / || /^On hold/ ||
42 /^Needs? / || /^Expecting / || /^May want to /) {
49 my ($fh, $branch) = @_;
50 my ($in_section, $in_desc);
54 if (/^\* \Q$branch\E /) {
58 last if (/^[-*\[]/ && $in_section);
59 next unless $in_section;
64 next unless ($in_section && $in_desc);
65 next if (/Originally merged to '\''next'\'' on ([-0-9]+)/);
66 last if (wildo_match($_));
69 return ($in_section, @msg);
72 my ($branch) = $ARGV[0];
73 my ($fh, $in_section, @msg);
74 if (open $fh, "<", "Meta/whats-cooking.txt") {
75 ($in_section, @msg) = read_message($fh, $branch);
79 qw(git -C Meta rev-list -32 HEAD -- whats-cooking.txt);
80 while (my $rev = <$revs>) {
83 qw(git -C Meta cat-file blob), "$rev:whats-cooking.txt";
84 ($in_section, @msg) = read_message($fh, $branch);
89 open(my $fh, "-|", qw(git cat-file commit HEAD));
90 my @original = (<$fh>);
96 $in_section = 1 if (/^$/);
99 if (/^Conflicts:$/ && $in_section == 2) {
103 if ($in_section == 3) {
107 if (/^$/ && $in_section == 1) {
113 open($fh, "|-", qw(git commit --amend -F -));
120 cocci_mark="treewide: apply cocci patch"
125 if ! git write-tree 2>/dev/null >/dev/null
130 GIT_EDITOR=: git commit --no-verify
131 echo "Accepted previous resolution"
137 test -n "$stop_at_cut" && return
139 count_since_last_cut=$(( $count_since_last_cut + 1 ))
140 test -z "$prev_cut" && return
141 git commit --allow-empty -m "$prev_cut"
145 cut_seen=0 prev_cut= count_since_last_cut=0 cocci_count=0
148 case "$branch" in '###') cut_seen=$(( $cut_seen + 1 )) ;; esac
149 if test -n "$stop_at_cut" && test $stop_at_cut -le $cut_seen
151 continue ;# slurp the remainder and skip
156 if test "$count_since_last_cut" = 0
160 echo >&2 "$branch $eh"
161 prev_cut="$branch $eh"
162 count_since_last_cut=0
166 if test -n "$no_cocci"
169 elif test 0 = "$cocci_count" && test -z "$force_cocci"
174 if test -n "$skip_cocci" && test -n "$eh"
176 git cherry-pick --no-commit "$eh"
178 rm -f contrib/coccinelle/*.patch
179 Meta/Make -j8 coccicheck
180 if grep coccicheck-pending Makefile >/dev/null
182 Meta/Make -j8 coccicheck-pending
184 cat contrib/coccinelle/*.patch >cocci.patch
185 if ! test -s cocci.patch
189 git apply --index -3 cocci.patch || exit
191 git diff --quiet HEAD && continue
193 git commit -m "$cocci_mark" || exit
203 "" | "#"* | [0-9][0-9]-[0-9][0-9]*)
206 save=$(git rev-parse --verify HEAD) &&
207 tip=$(git rev-parse --verify "$branch^0") &&
208 mb=$(git merge-base "$tip" "$save") ||
211 test "$mb" = "$tip" && continue
214 cocci_count=$(( $cocci_count + 1 ))
216 rebuild=$(git config "branch.$branch.rebuild" || :)
218 GIT_EDITOR=: git merge --no-ff $rebuild $accept_rerere --edit "$branch" ||
222 annotate_merge "$branch" || exit
224 git commit --amend || exit
226 this=$(git rev-parse --verify HEAD)
227 if test "$this" = "$save"
230 elif git show-ref -q --verify "refs/merge-fix/$branch"
232 echo >&2 "Fixing up the merge"
233 git cherry-pick --no-commit "refs/merge-fix/$branch" &&
234 git diff --stat HEAD &&
235 GIT_EDITOR=: git commit --amend -a || exit
243 git cherry-pick "$branch" || exit ;;
244 *) echo >&2 "Eh? $branch $eh"; exit ;;
252 if test -n "$update" && test $# = 0
254 set x $(sed -n -e '2s/^# //p' <"$update") &&
258 # Generation (or updating)
260 x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
261 x40="$x40$x40$x40$x40$x40$x40$x40$x40"
267 "Merge branch '"*"'"*)
268 branch=$(expr "$msg" : "Merge branch '\(.*\)'")
271 "Merge remote branch '"*"'"*)
272 branch=$(expr "$msg" : "Merge remote branch '\(.*\)'")
276 echo 2>&1 "Huh?: $msg"
280 tip=$(git rev-parse --verify "refs/$merge_hier$branch" 2>/dev/null) &&
281 merged=$(git name-rev --refs="refs/$merge_hier$branch" "$other" 2>/dev/null) &&
282 merged=$(expr "$merged" : "$x40 \(.*\)") &&
283 test "$merged" != undefined || {
284 other=$(git log -1 --pretty='format:%s' $other) &&
285 merged="$branch :rebased? $other"
295 merged="$(git rev-parse --verify "$commit") pick $msg"
306 echo 'case "$#,$1" in'
308 echo " exec $PROGRAM" '"$1" "$0"'
310 echo "$PROGRAM" '"$@" <<\EOF'
311 git log --no-decorate --pretty=oneline --first-parent "$1" |
314 while read commit msg
316 if other=$(git rev-parse -q --verify "$commit^2")
319 elif test "$msg" = "$cocci_mark"
321 merged="#cocci "$(git rev-parse "$commit^0")
330 series="$merged$LF$series"
343 generate "$0" "$@" | diff -w -u "$update" -
346 echo >&2 "No changes."
348 echo >&2 -n "Update [y/N]? "
353 sed -e 's/ :rebased?.*//' >"$update" ;;
355 echo >&2 "No update then." ;;
359 generate "$0" "$@" | diff -w -u "$update" -