+ if verbose cd "$d0/$d"; then
+ verbose "$@"
+ cd "$d0"
+ fi
+ done
+ ;;
+ save-patches)
+ outfile=$1
+ patchdir=`mktemp -d -t save-patches.XXXXXX`
+ for d in $repos; do
+ enter "$d0/$d" verbose
+ git branch -v -v | cut -c 3- | {
+ i=0
+ while read -r BRANCH REV UPSTREAM TEXT; do
+ case "$UPSTREAM" in
+ \[*)
+ UPSTREAM=${UPSTREAM#\[}
+ UPSTREAM=${UPSTREAM%\]}
+ UPSTREAM=${UPSTREAM%:*}
+ TRACK=true
+ ;;
+ *)
+ UPSTREAM=origin/"`repobranch "$d"`"
+ TRACK=false
+ ;;
+ esac
+ if [ x"$REV" = x"->" ]; then
+ continue
+ fi
+ if git format-patch -o "$patchdir/$i" "$UPSTREAM".."$BRANCH"; then
+ echo "$d" > "$patchdir/$i/info.txt"
+ echo "$BRANCH" >> "$patchdir/$i/info.txt"
+ echo "$UPSTREAM" >> "$patchdir/$i/info.txt"
+ echo "$TRACK" >> "$patchdir/$i/info.txt"
+ i=$(($i+1))
+ else
+ rm -rf "$patchdir/$i"
+ fi
+ done
+ }
+ done
+ ( cd "$patchdir" && tar cvzf - . ) > "$outfile"
+ rm -rf "$patchdir"
+ ;;
+ restore-patches)
+ infile=$1
+ patchdir=`mktemp -d -t restore-patches.XXXXXX`
+ ( cd "$patchdir" && tar xvzf - ) < "$infile"
+ # detach the head
+ for P in "$patchdir"/*/info.txt; do
+ D=${P%/info.txt}
+ exec 3<"$P"
+ read -r d <&3
+ read -r BRANCH <&3
+ read -r UPSTREAM <&3
+ read -r TRACK <&3
+ verbose git checkout HEAD^0
+ verbose git branch -D "$BRANCH"
+ if [ x"$TRACK" = x"true" ]; then
+ verbose git checkout --track -b "$BRANCH" "$UPSTREAM"
+ else
+ verbose git branch -b "$BRANCH" "$UPSTREAM"
+ fi
+ verbose git am "$D"
+ done
+ rm -rf "$patchdir"
+ ;;
+ admin-merge)
+ if [ "$#" = 1 ]; then
+ set -- "${1%%/*}" "${1#*/}"
+ fi
+ for d in $repos; do
+ enter "$d0/$d" verbose
+ git rev-parse "$1/$2" || continue
+ # 1. review
+ {
+ git log HEAD.."$1/$2"
+ git diff HEAD..."$1/$2"
+ } | less
+ if yesno "Merge \"$1/$2\" into `git symbolic-ref HEAD` of $d?"; then
+ git merge "$1/$2"
+ if "$SELF" compile && yesno "Still merge \"$1/$2\" into `git symbolic-ref HEAD` of $d? Maybe you want to test first."; then
+ git push origin HEAD
+ git push "$1" :"$2"
+ else
+ git reset --hard HEAD@{1}
+ fi
+ fi
+ done
+ ;;
+ admin-merge-2)
+ t=`mktemp`
+ report=""
+ reportecho()
+ {
+ report=$report"$*$LF"
+ echo "$*"
+ }
+ reportecho4()
+ {
+ report=$report" $*$LF"
+ echo " $*"
+ }
+ reportdo4()
+ {
+ o=`"$@" | sed 's/^/ /' || true`
+ reportecho "$o"
+ }
+ for d in $repos; do
+ enter "$d0/$d" verbose
+ reportecho "In $d:"
+ for ref in `git for-each-ref --format='%(refname)' refs/remotes/origin/`; do
+ case "${ref#refs/remotes/origin/}" in
+ "`repobranch "$d"`")
+ continue
+ ;;
+ HEAD|master)
+ continue
+ ;;
+ esac
+ reportecho " Branch $ref:"
+ note=`git notes --ref "refs/notes/admin-merge" show "$ref" 2>/dev/null || true`
+ if [ -n "$note" ]; then
+ reportdo4 echo "$note"
+ reportecho4 "--> not merging, already had this one rejected before"
+ elif yesno "Branch \"$ref\" may want to get merged. Do it?" '{ git log --color HEAD.."$ref"; git diff --color --find-copies-harder --ignore-space-change HEAD..."$ref"; } | less -r'; then
+ git checkout master
+ org=`git rev-parse HEAD`
+ if ! git merge "$ref" 2>&1 | tee "$t"; then
+ git reset --hard "$org"
+ git notes --ref "refs/notes/admin-merge" add -m "Merge failed:$LF`cat "$t"`" "$ref"
+ reportdo4 cat "$t"
+ reportecho4 "--> merge failed"
+ elif ! "$SELF" compile 2>&1 | tee "$t"; then
+ git reset --hard "$org"
+ git notes --ref "refs/notes/admin-merge" add -m "Compile failed:$LF`cat "$t"`" "$ref"
+ reportdo4 cat "$t"
+ reportecho4 "--> compile failed"
+ elif ! yesno "Still merge \"$ref\" into `git symbolic-ref HEAD` of $d? Maybe you want to test first."; then
+ git reset --hard "$org"
+ git notes --ref "refs/notes/admin-merge" add "$ref"
+ note=`git notes --ref "refs/notes/admin-merge" show "$ref" 2>/dev/null || true`
+ reportdo4 echo "$note"
+ reportecho4 "--> test failed"
+ else
+ case ",`repoflags "$d"`," in
+ *,svn,*)
+ git pull
+ git rebase -i "$org"
+ git svn dcommit --add-author-from
+ ;;
+ *)
+ git push origin HEAD
+ ;;
+ esac
+ reportecho4 "--> MERGED"
+ if yesno "Delete original branch \"$ref\"?"; then
+ git push origin :"${ref#refs/remotes/origin/}"
+ reportecho4 "--> branch deleted"
+ fi
+ fi
+ else
+ git notes --ref "refs/notes/admin-merge" add "$ref"
+ note=`git notes --ref "refs/notes/admin-merge" show "$ref" 2>/dev/null || true`
+ if [ -n "$note" ]; then
+ reportdo4 echo "$note"
+ reportecho4 "--> rejected"
+ else
+ reportecho4 "--> postponed"
+ fi
+ fi
+ reportecho ""
+ done
+ reportecho ""