3 # Copyright (c) Josef "Jeff" Sipek, 2007-2013
6 USAGE
="[<hash> | <since>..[<until>] | ..<until>]"
7 if [ -z "$GUILT_VERSION" ]; then
8 echo "Invoking `basename "$0"` directly is no longer supported." >&2
14 if [ $# -ne 1 ] ||
[ -z "$1" ]; then
15 die
"You must specify a range of commits"
18 rhash
=`munge_hash_range $1`
20 # make sure that there are no unapplied changes
21 if ! must_commit_first
; then
22 die
"Uncommited changes detected. Refresh first."
25 disp
"About to begin conversion..." >&2
26 disp
"Current head: `git rev-parse \`git_branch\``" >&2
28 for rev in `git rev-list $rhash`; do
29 s
=`git log --no-decorate --pretty=oneline -1 $rev | cut -c 42-`
31 # Try to convert the first line of the commit message to a
33 fname
=`printf %s "$s" | sed -e "s/&/and/g" -e "s/[ :]/_/g" -e "s,[/\\],-,g" \
34 -e "s/['\\[{}]//g" -e 's/]//g' -e 's/\*/-/g' \
35 -e 's/\?/-/g' -e 's/\.\.\.*/./g' -e 's/^\.//' \
36 -e 's/\.patch$//' -e 's/\.$//' | tr A-Z a-z`
38 if ! valid_patchname
"$fname"; then
39 # Try harder to make it a legal commit name by
40 # removing all but a few safe characters.
41 fname
=`echo $fname|tr -d -c _a-zA-Z0-9---/\\n`
43 if ! valid_patchname
"$fname"; then
44 # If we failed to derive a legal patch name, use the
45 # name "x". (If this happens, we likely have to
46 # append a suffix to make the name unique.)
50 disp
"Converting `echo $rev | cut -c 1-8` as $fname"
54 while [ -f "$GUILT_DIR/$branch/$fname.patch" ]; do
55 fname
="$fname_base-$mangle_prefix"
56 mangle_prefix
=`expr $mangle_prefix + 1`
57 disp
"Patch under that name exists...trying '$fname'"
64 git
diff --binary $rev^..
$rev
65 ) > "$GUILT_DIR/$branch/$fname"
67 # FIXME: grab the GIT_AUTHOR_DATE from the commit object and set the
68 # timestamp on the patch
70 # insert the patch name into the series file
71 series_insert_patch
$fname
73 # Only reset if the commit was on this branch
74 if head_check
$rev 2> /dev
/null
; then
75 # BEWARE: "git reset" ahead! Is there a way to verify that
76 # we really created a patch? - We don't want to lose any
78 git
reset --hard $rev^
> /dev
/null
79 elif [ -z "$warned" ]; then
80 disp
"Warning: commit $rev is not the HEAD...preserving commit" >&2
81 disp
"Warning: (this message is displayed only once)" >&2
87 disp
"Current head: `git rev-parse \`git_branch\``" >&2