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 [ `expr length "$fname"` -gt 80 ] ; then
39 # Limit the patch length to about 80 chars. While this is
40 # arbitrary, we have to have a limit to avoid trying to
41 # create filenames that are too long for the filesystem to
43 fname
=`expr substr "$fname" 1 80`
46 if ! valid_patchname
"$fname"; then
47 # Try harder to make it a legal commit name by
48 # removing all but a few safe characters.
49 fname
=`echo $fname|tr -d -c _a-zA-Z0-9---/\\n`
51 if ! valid_patchname
"$fname"; then
52 # If we failed to derive a legal patch name, use the
53 # name "x". (If this happens, we likely have to
54 # append a suffix to make the name unique.)
58 disp
"Converting `echo $rev | cut -c 1-8` as $fname"
62 while [ -f "$GUILT_DIR/$branch/$fname.patch" ]; do
63 fname
="$fname_base-$mangle_prefix"
64 mangle_prefix
=`expr $mangle_prefix + 1`
65 disp
"Patch under that name exists...trying '$fname'"
72 git
diff --binary $rev^..
$rev
73 ) > "$GUILT_DIR/$branch/$fname"
75 # FIXME: grab the GIT_AUTHOR_DATE from the commit object and set the
76 # timestamp on the patch
78 # insert the patch name into the series file
79 series_insert_patch
$fname
81 # Only reset if the commit was on this branch
82 if head_check
$rev 2> /dev
/null
; then
83 # BEWARE: "git reset" ahead! Is there a way to verify that
84 # we really created a patch? - We don't want to lose any
86 git
reset --hard $rev^
> /dev
/null
87 elif [ -z "$warned" ]; then
88 disp
"Warning: commit $rev is not the HEAD...preserving commit" >&2
89 disp
"Warning: (this message is displayed only once)" >&2
95 disp
"Current head: `git rev-parse \`git_branch\``" >&2