Hello,
I finally have some time for improving quilt. Attached is a version of
`quilt fork' that forks the top-most patch. I think that this is even
simpler to understand that forking the next patch. Are you fine with
that?
Sorry for the long delay ...
Cheers,
------------------------------------------------------------------------
Index: Makefile.in
===================================================================
RCS file: /cvsroot/quilt/quilt/Makefile.in,v
retrieving revision 1.26
diff -u -r1.26 Makefile.in
--- Makefile.in 9 Sep 2003 07:00:01 -0000 1.26
+++ Makefile.in 20 Oct 2003 17:23:21 -0000
@@ -56,7 +56,8 @@
DIRT += $(BIN_IN:%=bin/%)
QUILT_IN := add applied delete diff files import new next patches \
- pop previous push refresh remove series setup top unapplied
+ pop previous push refresh remove series setup top unapplied \
+ fork
QUILT_SRC := $(QUILT_IN:%=%.in)
QUILT := $(QUILT_IN)
Index: quilt/fork.in
===================================================================
RCS file: quilt/fork.in
diff -N quilt/fork.in
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ quilt/fork.in 20 Oct 2003 17:23:21 -0000
@@ -0,0 +1,109 @@
+#! @BASH@ -x
+
+# This script is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# See the COPYING and AUTHORS files for more details.
+
+# Read in library functions
+if [ "$(type -t patch_file_name)" != function ]
+then
+ if ! [ -r @SCRIPTS@/patchfns ]
+ then
+ echo "Cannot read library @SCRIPTS@/patchfns" >&2
+ exit 1
+ fi
+ . @SCRIPTS@/patchfns
+fi
+
+usage()
+{
+ echo $"Usage: quilt fork [new_name]"
+ if [ x$1 = x-h ]
+ then
+ echo $"
+Fork the topmost patch. If new_name is missing, the name of the
+forked patch will be the current patch name, followed by \"-2\". If the
+If the patch name already ends in a dash and number, the number is
+further incremented: \"patch\", \"patch-2\", \"patch-3\", etc. The
+new patch is only created when \"quilt refresh\" is run.
+"
+ exit 0
+ else
+ exit 1
+ fi
+}
+
+options=`getopt -o h -- "$@"`
+
+if [ $? -ne 0 ]
+then
+ usage
+fi
+
+eval set -- "$options"
+
+while true
+do
+ case "$1" in
+ -h)
+ usage -h ;;
+ --)
+ shift
+ break ;;
+ esac
+done
+
+if [ $# -gt 1 ]
+then
+ usage
+fi
+
+top="$(top_patch)"
+if [ -z "$top" ]
+then
+ echo $"No patches applied" >&2
+ exit 1
+fi
+top_file_name="$(patch_file_name $top)"
+
+if [ $# -eq 1 ]
+then
+ patch_file="$1"
+else
+ set -- $(echo "$top" \
+ | @SED@ -e 's: :\ :g' -e 's:-\([0-9]\+\)$: \1:')
+ if [ $# -eq 1 ]; then
+ patch_file="$1-2"
+ else
+ patch_file="$1-$[$2+1]"
+ fi
+fi
+
+patch_file=$(echo $patch_file | @SED@ -e 's/^'"$(quote_bre $P)"'patches\///')
+patch=$(stripit $patch_file)
+pc_dir=".pc/$patch"
+
+if patch_in_series $patch || \
+ [ -d "$pc_dir" ] || \
+ [ -e "patches/$patch_file" ]
+then
+ echo $"Patch $patch exists already, please choose a new name"
+ exit 1
+fi
+
+if ! rename_in_db "$top" "$patch" || \
+ ! rename_in_series "$top" "$patch_file" || \
+ ! mv ".pc/$top" $pc_dir
+then
+ echo $"Fork of $top_file_name to $patch_file failed" >&2
+ exit 1
+fi
+
+echo $"Fork of $top_file_name created as $(patch_file_name $patch)"
+
+### Local Variables:
+### mode: shell-script
+### End:
+# vim:filetype=sh
Index: scripts/patchfns.in
===================================================================
RCS file: /cvsroot/quilt/quilt/scripts/patchfns.in,v
retrieving revision 1.19
diff -u -r1.19 patchfns.in
--- scripts/patchfns.in 26 Jul 2003 11:06:55 -0000 1.19
+++ scripts/patchfns.in 20 Oct 2003 17:23:21 -0000
@@ -217,6 +217,27 @@
fi
}
+rename_in_series()
+{
+ local from=$1 to=$2
+
+ tmpfile=$(gen_tempfile) || return 1
+ /usr/bin/gawk '
+ /^'"$(quote_re $from)"'(|\.patch|\.diff?)(|\.gz|\.bz2)([ \t]|$)/ \
+ { sub(/'"$(quote_re $from)"'/, "'"$(quote_re $to)"'")
+ print
+ good=1 }
+ END { exit(! good) }
+ ' $SERIES > $tmpfile
+ if [ $? -eq 0 ]
+ then
+ mv -f $tmpfile $SERIES
+ else
+ rm -f $tmpfile
+ return 1
+ fi
+}
+
pc_file_name()
{
while [ $# -gt 0 ]
@@ -462,6 +483,27 @@
mv -f $tmpfile $DB
rm -f $tmpfile
[ -s $DB ] || rm -f $DB
+ fi
+}
+
+rename_in_db()
+{
+ local from=$1 to=$2
+ local tmpfile
+ tmpfile=$(gen_tempfile) || return 1
+ /usr/bin/gawk '
+ /^'"$(quote_re $from)"'$/ \
+ { sub(/'"$(quote_re $from)"'/, "'"$(quote_re $to)"'")
+ print
+ good=1 }
+ END { exit(! good) }
+ ' $DB > $tmpfile
+ if [ $? -eq 0 ]
+ then
+ mv -f $tmpfile $DB
+ else
+ rm -f $tmpfile
+ return 1
fi
}