3 # Copyright (c) Josef "Jeff" Sipek, 2008
6 DO_NOT_CHECK_STATUS_FILE_FORMAT
=1
8 USAGE
="--full | --status | --autotag"
13 die
"Please read the man page first. (you need to specify repair mode to proceed)."
16 [ $# -ne 1 ] && safety_abort
33 oldrev
=`git show-ref -s "refs/heads/$branch"`
36 # Check whether status file needs fixing/upgrading. If not, just return,
37 # otherwise proceed to rewrite the status file and set up proper refs
41 printf "Checking status file format..."
42 if ! grep "^[0-9a-f]\{40\}:" "$applied" > /dev
/null
; then
43 echo "ok; no upgrade necessary."
46 echo "old; about to upgrade."
48 # we got an old format status file
50 printf "" > "$applied.new"
52 cat "$applied" |
while read line
; do
53 hash=`echo "$line" | cut -d: -f1`
54 pname
=`echo "$line" | cut -d: -f2-`
56 npname
=`echo "$pname" | sed -e 's/ /-/g'`
57 [ "$pname" != "$npname" -a -e "$npname" ] && die
"Patch name collision"
59 git update-ref
"refs/patches/$branch/$npname" "$hash"
60 echo "$npname" >> "$applied.new"
62 if [ "$pname" != "$npname" ]; then
63 series_rename_patch
"$pname" "$npname"
65 mv "$GUILT_DIR/$branch/$pname" "$GUILT_DIR/$branch/$npname"
69 # replace the status file
70 mv "$applied" "$applied~"
71 mv "$applied.new" "$applied"
73 echo "Upgrade complete."
79 # Pop all patches - forcefully.
83 if [ -s "$applied" ]; then
84 # there were some patches applied
85 newrev
=`git rev-parse refs/patches/$branch/$(head -1 < "$applied")^`
87 # no patches were applied, but let's do all the work anyway
91 echo "Current HEAD commit $oldrev"
92 echo "New HEAD commit $newrev"
94 echo "About to forcefully pop all patches..."
95 echo -n "Are you sure you want to proceed? [y/N] "
97 if [ "$n" != "y" ] && [ "$n" != "Y" ]; then
101 # blow away any commits
102 git
reset --hard "$newrev" > /dev
/null
104 # blow away the applied stack
105 remove_patch_refs
< "$applied"
106 printf "" > "$applied"
108 # remove the ${branch}_{top,bottom,base} tags
109 update_stack_tags
"force"
111 echo "Patches should be popped."
115 # update the top/bottom/base tags
137 echo "Repair complete."