quilt-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Quilt-dev] [PATCH] Add a rename command


From: Jean Delvare
Subject: [Quilt-dev] [PATCH] Add a rename command
Date: Wed, 8 Jun 2005 22:06:37 +0200

Hi all,

Some times ago I proposed to add a rename command to quilt, to let the
user rename patches:
  http://lists.gnu.org/archive/html/quilt-dev/2005-04/msg00014.html

I did write it back then, posted it on this list and am using it since,
and it seems to work just fine. As I think this is a useful feature to
have (one other person asked me for it already), I am posting it here
again as a patch against current CVS, asking for it to be considered for
inclusion.

I am personally using this function to import patches first, then rename
them if and only if they applied and worked as intended, saving the
burden and frustration of renaming a patch at import time and delete it
a few seconds later. This command could also be useful to people using
subdirectories to organize their patches, to easily move a given patch
from one subdirectory to another.

The rename function works on the topmost or named patch, whether applied
or not. My patch includes bash_completion support and a complete test
case.

Comments welcome, of course. Thanks.

Index: Makefile.in
===================================================================
RCS file: /cvsroot/quilt/quilt/Makefile.in,v
retrieving revision 1.52
diff -u -r1.52 Makefile.in
--- Makefile.in 23 Jan 2005 05:01:00 -0000      1.52
+++ Makefile.in 8 Jun 2005 19:43:29 -0000
@@ -58,7 +58,7 @@
 
 QUILT_IN :=    add applied delete diff edit files fold fork graph grep \
                import mail new next patches pop previous push refresh remove \
-               series setup snapshot top unapplied upgrade
+               rename series setup snapshot top unapplied upgrade
 
 QUILT_SRC :=   $(QUILT_IN:%=%.in)
 QUILT :=       $(QUILT_IN)
Index: bash_completion
===================================================================
RCS file: /cvsroot/quilt/quilt/bash_completion,v
retrieving revision 1.12
diff -u -r1.12 bash_completion
--- bash_completion     20 Jan 2005 11:35:22 -0000      1.12
+++ bash_completion     8 Jun 2005 19:43:29 -0000
@@ -97,7 +97,7 @@
     # quilt sub commands 
     cmds='add applied delete diff edit files fold fork graph grep  \
           import new next patches pop previous push refresh remove \
-         series setup snapshot top unapplied'
+         rename series setup snapshot top unapplied'
 
     # if no command were given, complete on commands
     if [[ $COMP_CWORD -eq 1 ]] ; then
@@ -230,6 +230,16 @@
                ;;
           esac
           ;;
+        rename)
+          case $prev in
+            -p)
+               COMPREPLY=( $( compgen -W "$(quilt series)" -- $cur ) )
+               ;;
+            *)
+               COMPREPLY=( $( compgen -W "-p" -- $cur ) )
+               ;;
+          esac
+          ;;
         series)
           COMPREPLY=( $( compgen -W "-n -v -h" -- $cur ) )
           ;;
Index: quilt/.cvsignore
===================================================================
RCS file: /cvsroot/quilt/quilt/quilt/.cvsignore,v
retrieving revision 1.5
diff -u -r1.5 .cvsignore
--- quilt/.cvsignore    29 Apr 2005 07:33:50 -0000      1.5
+++ quilt/.cvsignore    8 Jun 2005 19:43:29 -0000
@@ -18,6 +18,7 @@
 push
 refresh
 remove
+rename
 rest
 series
 setup
--- /dev/null   2005-06-08 20:05:55.000000000 +0200
+++ quilt/rename.in     2005-06-06 22:48:19.000000000 +0200
@@ -0,0 +1,111 @@
+#! @BASH@
+
+#  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()
+{
+       printf $"Usage: quilt rename [-p patch] new_name\n"
+       if [ x$1 = x-h ]
+       then
+               printf $"
+Rename the topmost or named patch.
+
+-p patch
+       Patch to rename.
+"
+               exit 0
+       else
+               exit 1
+       fi
+}
+
+options=`getopt -o p:h -- "$@"`
+
+if [ $? -ne 0 ]
+then
+       usage
+fi
+
+eval set -- "$options"
+
+while true
+do
+       case "$1" in
+       -p)
+               if ! patch=$(find_patch $2)
+               then
+                       printf $"Patch %s is not in series\n" "$2" >&2
+                       exit 1
+               fi
+               shift 2 ;;
+       -h)
+               usage -h ;;
+       --)
+               shift
+               break ;;
+       esac
+done
+
+if [ $# -ne 1 ]
+then
+       usage
+fi
+
+if [ ! -n "$patch" ]
+then
+       patch=$(top_patch)
+       if [ -z "$patch" ]
+       then
+               printf $"No patches applied\n" >&2
+               exit 1
+       fi
+fi
+
+new_patch=${1#$QUILT_PATCHES/}
+
+if patch_in_series $new_patch || \
+   [ -d "$QUILT_PC/$new_patch" ] || \
+   [ -e "$(patch_file_name $new_patch)" ]
+then
+       printf $"Patch %s exists already, please choose a different name\n" \
+              "$(print_patch $new_patch)" >&2
+       exit 1
+fi
+
+if ( is_applied $patch && \
+     ( ! rename_in_db "$patch" "$new_patch" || \
+       ! mv "$QUILT_PC/$patch" "$QUILT_PC/$new_patch" ) ) || \
+   ! rename_in_series "$patch" "$new_patch" || \
+   ( [ -e "$(patch_file_name $patch)" ] && \
+     ! mv "$(patch_file_name $patch)" \
+         "$(patch_file_name $new_patch)" )
+then
+       printf $"Renaming of patch %s to %s failed\n" \
+              "$(print_patch $patch)" \
+              "$(print_patch $new_patch)" >&2
+       exit 1
+fi
+
+printf $"Patch %s renamed to %s\n" \
+       "$(print_patch $patch)" \
+       "$(print_patch $new_patch)"
+
+### Local Variables:
+### mode: shell-script
+### End:
+# vim:filetype=sh
--- /dev/null   2005-06-08 20:05:55.000000000 +0200
+++ test/rename.test    2005-06-08 21:25:23.000000000 +0200
@@ -0,0 +1,69 @@
+       $ mkdir d
+       $ cd d
+
+       $ cat > announce.txt
+       < A short summary of the fixes are below.
+
+       $ quilt new original-name.diff
+       > Patch %{P}original-name.diff is now on top
+
+       $ quilt add announce.txt
+       > File announce.txt added to patch %{P}original-name.diff
+
+       $ cat > announce.txt
+       < The diffstat and short summary of the fixes are below.
+
+       $ quilt refresh
+       > Refreshed patch %{P}original-name.diff
+
+       $ quilt series -v
+       > = %{P}original-name.diff
+
+       $ ls -1 .pc
+       > applied-patches
+       > original-name.diff
+
+       $ cat .pc/applied-patches
+       > original-name.diff
+
+       $ quilt rename _tmp_name.diff
+       > Patch %{P}original-name.diff renamed to %{P}_tmp_name.diff
+
+       $ quilt series -v
+       > = %{P}_tmp_name.diff
+
+       $ ls -1 .pc
+       > _tmp_name.diff
+       > applied-patches
+
+       $ cat .pc/applied-patches
+       > _tmp_name.diff
+
+       $ quilt pop
+       > Removing patch %{P}_tmp_name.diff
+       > Restoring announce.txt
+       >
+       > No patches applied
+
+       $ quilt series -v
+       >   %{P}_tmp_name.diff
+
+       $ ls -1 .pc
+
+       $ quilt rename -p random_name.diff final.name.diff
+       > Patch random_name.diff is not in series
+
+       $ quilt rename final.name.diff
+       > No patches applied
+
+       $ quilt rename -p _tmp_name.diff _tmp_name.diff
+       > Patch %{P}_tmp_name.diff exists already, please choose a different 
name
+
+       $ quilt rename -p _tmp_name.diff final.name.diff
+       > Patch %{P}_tmp_name.diff renamed to %{P}final.name.diff
+
+       $ quilt series -v
+       >   %{P}final.name.diff
+
+       $ cd ..
+       $ rm -rf d

-- 
Jean Delvare




reply via email to

[Prev in Thread] Current Thread [Next in Thread]