3 # Copyright (c) Josef "Jeff" Sipek, 2008
6 DO_NOT_CHECK_STATUS_FILE_FORMAT
=1
8 USAGE
="--full | --status"
13 die
"Please read the man page first. (you need to specify repair mode to proceed)."
16 [ $# -ne 1 ] && safety_abort
26 echo "Autotagging is no longer supported" >&2
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 _disp
"Checking status file format..."
42 if ! grep "^[0-9a-f]\{40\}:" "$applied" > /dev
/null
; then
43 disp
"ok; no upgrade necessary."
46 disp
"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 disp
"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 disp
"Current HEAD commit $oldrev"
92 disp
"New HEAD commit $newrev"
94 disp
"About to forcefully pop all patches..."
95 _disp
"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 disp
"Patches should be popped."
125 disp
"Repair complete."