quilt-dev
[Top][All Lists]
Advanced

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

Re: [Quilt-dev] [patch] Quilt support for committing patches to CVS.


From: Joe Green
Subject: Re: [Quilt-dev] [patch] Quilt support for committing patches to CVS.
Date: Wed, 11 Aug 2004 11:11:54 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113

Dean Roehrich wrote:
From:  "Jason M. Felice" <address@hidden>

Attached is a patch which implements `quilt commit'.  There's no reason
the command needs to be CVS-specific in the future, but that's what I
use.

I'll try to look at this over the next few days.  I have some generic quilt
extensions that allow quilt to work on top of source control systems like BK
and an internal SGI tool that sits on top of RCS.

I guess a bunch of us have been carrying patches like these :). I've attached the patch I use for CVS support. It detects whether CVS is being used by looking for a "CVS" directory. It also has a "commit" command :).

Andreas Gruenbacher wrote:
> I am not happy about hard-coding CVS specifics into quilt. We could
> provide some sort of hook mechanism to fix this.

Yes, I figured changes like this would not be accepted in this form. Looking at the various patches should make it easy to figure out where the hooks need to go, though.

> What's relevant to
> version control is which files have been modified, added, and removed,
> so a simple function in .quiltrc like this would probably do:

I'm a bit uncomfortable about the idea of putting code in .quiltrc from a maintenance perspective. It could break due to future changes.

It's probably also true that many people work with multiple SCMs (e.g. BK for kernel, CVS for other things), so figuring out dynamically which (if any) SCM to use, or letting it be configured by tree somehow might be better.

--
Joe Green <address@hidden>
MontaVista Software, Inc.
Add support for doing CVS operations directly from quilt commands.
cvs edit, add and remove commands are executed as necessary.
The "commit" subcommand is added to allow commiting patches and
series file through quilt.

Joe Green <address@hidden>

Index: quilt-0.35/Makefile.in
===================================================================
--- quilt-0.35.orig/Makefile.in
+++ quilt-0.35/Makefile.in
@@ -55,9 +55,9 @@ BIN :=                $(BIN_IN)
 SRC +=         $(BIN_SRC:%=bin/%)
 DIRT +=                $(BIN_IN:%=bin/%)
 
-QUILT_IN :=    add applied delete diff edit files fold fork graph grep \
-               header import new next patches pop previous push refresh \
-               remove series setup snapshot top unapplied upgrade
+QUILT_IN :=    add applied commit delete diff edit files fold fork graph \
+               grep header import new next patches pop previous push \
+               refresh remove series setup snapshot top unapplied upgrade
 
 QUILT_SRC :=   $(QUILT_IN:%=%.in)
 QUILT :=       $(QUILT_IN)
Index: quilt-0.35/bash_completion
===================================================================
--- quilt-0.35.orig/bash_completion
+++ quilt-0.35/bash_completion
@@ -82,7 +82,7 @@ _quilt_completion()
     prev=${COMP_WORDS[COMP_CWORD-1]}
 
     # quilt sub commands 
-    cmds='add applied delete diff edit files fold fork graph grep  \
+    cmds='add applied commit delete diff edit files fold fork graph grep  \
           header import new next patches pop previous push refresh \
          remove series setup snapshot top unapplied'
 
@@ -121,6 +121,9 @@ _quilt_completion()
        applied) 
           COMPREPLY=( $( compgen -W "-n -h $(quilt applied)" -- $cur ) )
           ;;
+       commit)
+          COMPREPLY=( $(compgen -W "-n -h" -- $cur) )
+          ;;
        delete) 
           COMPREPLY=( $( compgen -W "-h $(quilt series)" -- $cur ) )
           ;;
Index: quilt-0.35/quilt/commit.in
===================================================================
--- /dev/null
+++ quilt-0.35/quilt/commit.in
@@ -0,0 +1,130 @@
+#! @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 commit [-n]\n"
+       if [ x$1 = x-h ]
+       then
+               printf $"
+Commit patch changes to source control.
+
+-n     Do not commit; just report what would be done.
+"
+               exit 0
+       else
+               exit 1
+       fi
+}
+
+options=`getopt -o nh -- "$@"`
+
+if [ $? -ne 0 ]
+then
+       usage
+fi
+
+eval set -- "$options"
+
+while true
+do
+       case "$1" in
+       -h)
+               usage -h ;;
+       -n)
+               opt_nocommit=1
+               shift ;;
+       --)
+               shift
+               break ;;
+       esac
+done
+
+if [ $# -ne 0 ]
+then
+       usage
+fi
+
+if [ ! -d "$QUILT_PATCHES" ] ; then
+       printf $"Patches directory \"%s\" not found.\n" \
+               "$QUILT_PATCHES" >&2
+       exit 1
+fi
+
+# Make sure patches are under CVS control.
+if [ ! -d "$QUILT_PATCHES/CVS" ] ; then
+       printf $"Patches directory \"%s\" does not appear to be under CVS 
control.\n" \
+               "$QUILT_PATCHES" >&2
+       exit 1
+fi
+
+# Check series file separately in case it's in a different directory.
+seriesfile=$(realfile "$SERIES")
+if ! is_cvs_file "$seriesfile" ; then
+       printf $"Series file \"%s\" does not appear to be under CVS control.\n" 
\
+               "$seriesfile" >&2
+       exit 1
+fi
+
+if [ ! "$opt_nocommit" ] ; then
+       top=$(top_patch)
+
+       # Make sure all patches in series have been applied.
+       # This is to ensure that any patch conflicts have been resolved.
+       if [ "$(patches_after $top)" ] ; then
+               printf $"All patches must be applied before committing (use 
\"push -a\").\n" >&2
+               exit 1
+       fi
+
+       if [ "$top" ] ; then
+               # Make sure the current patch has no unsaved changes.
+               if [ -e "$QUILT_PC/$top~refresh" ] ||
+                   ( files_may_have_changed "$top" &&
+                       ! no_pending_changes "$top" )
+               then
+                       printf $"The topmost patch %s must be refreshed before 
committing.\n" "$top" >&2
+                       exit 1
+               fi
+       fi
+fi
+
+seriesdir=$(dirname "$seriesfile")
+
+# Commit all changes in patches directory.
+# Commit series file separately if not in patches directory.
+
+cvs_command="cvs commit"
+[ "$opt_nocommit" ] && cvs_command="cvs -n update"
+
+if ! (cd "$QUILT_PATCHES" && $cvs_command -l) ; then
+       printf $"Cannot process contents of patches directory \"%s\".\n" \
+               "$QUILT_PATCHES" >&2
+       exit 1
+elif ! [ "$QUILT_PATCHES" -ef "$seriesdir" ] &&
+    ! (cd "$seriesdir" && $cvs_command "$(basename $seriesfile)")
+then
+       printf $"Cannot process series file \"%s\".\n" "$seriesfile" >&2
+       exit 1
+fi
+
+exit 0
+### Local Variables:
+### mode: shell-script
+### End:
+# vim:filetype=sh
Index: quilt-0.35/quilt/delete.in
===================================================================
--- quilt-0.35.orig/quilt/delete.in
+++ quilt-0.35/quilt/delete.in
@@ -90,7 +90,22 @@ fi
 if ! remove_from_series $patch
 then
        printf $"Failed to remove patch %s\n" "$patch" >&2
+       exit 1
 fi
+
+patch_file=$(patch_file_name "$patch")
+if [ -e "$patch_file" ] && is_cvs_file "$patch_file" ; then
+       if mv "$patch_file" "$patch_file~" || rm -f "$patch_file" ; then
+               if ! cvs_remove "$patch_file" ; then
+                       exit 1
+               fi
+       else
+               printf $"Cannot remove patch file \"%s\".\n" "$patch_file"
+               exit 1
+       fi
+fi
+
+exit 0
 ### Local Variables:
 ### mode: shell-script
 ### End:
Index: quilt-0.35/quilt/fork.in
===================================================================
--- quilt-0.35.orig/quilt/fork.in
+++ quilt-0.35/quilt/fork.in
@@ -106,6 +106,11 @@ then
        exit 1
 fi
 
+patch_file=$(patch_file_name "$new_patch")
+if is_cvs_file "$patch_file" && ! cvs_add "$patch_file" ; then
+       exit 1
+fi
+
 printf $"Fork of patch %s created as %s\n" \
        "$(print_patch $top_patch)" \
        "$(print_patch $new_patch)"
Index: quilt-0.35/quilt/import.in
===================================================================
--- quilt-0.35.orig/quilt/import.in
+++ quilt-0.35/quilt/import.in
@@ -119,7 +119,15 @@ do
                fi
                printf $"Replacing patch %s with new version\n" \
                       "$(print_patch $patch)" >&2
+
+               if is_cvs_file "$QUILT_PATCHES/$patch" &&
+                   [ ! -w "$QUILT_PATCHES/$patch" ] &&
+                   ! cvs_edit "$QUILT_PATCHES/$patch"
+               then
+                       exit 1
+               fi
        else
+               newpatch=yes
                printf $"Importing patch %s (stored as %s)\n" \
                       "$(print_patch $patch_file)" \
                       "$(print_patch $patch)"
@@ -132,6 +140,12 @@ do
                status=1
        fi
 
+       if is_cvs_file "$QUILT_PATCHES/$patch" &&
+           [ "$newpatch" ] && ! cvs_add "$QUILT_PATCHES/$patch"
+       then
+               exit 1
+       fi
+
        if ! patch_in_series $patch &&
           ! insert_in_series $patch "$patch_args"
        then
Index: quilt-0.35/quilt/refresh.in
===================================================================
--- quilt-0.35.orig/quilt/refresh.in
+++ quilt-0.35/quilt/refresh.in
@@ -244,6 +244,16 @@ then
        exit 0
 fi
 
+if is_cvs_file "$patch_file" ; then
+       if [ -e "$patch_file" ] ; then
+               if [ ! -w "$patch_file" ] && ! cvs_edit "$patch_file" ; then
+                       die 1
+               fi
+       else
+               newpatch=yes
+       fi
+fi
+
 if ( [ -n "$QUILT_BACKUP" -a -e $patch_file ] && \
      ! cp $patch_file $patch_file~ ) || \
    ! cat_to_file $patch_file < $tmp_result
@@ -256,6 +266,13 @@ touch $QUILT_PC/$patch/.timestamp
 
 rm -f $QUILT_PC/$patch~refresh
 printf $"Refreshed patch %s\n" "$(print_patch $patch)"
+
+if is_cvs_file "$patch_file" ; then
+       if [ "$newpatch" ] && ! cvs_add "$patch_file" ; then
+               die 1
+       fi
+fi
+
 if ! change_db_strip_level -p$opt_strip_level $patch
 then
        die 1
Index: quilt-0.35/scripts/patchfns.in
===================================================================
--- quilt-0.35.orig/scripts/patchfns.in
+++ quilt-0.35/scripts/patchfns.in
@@ -106,6 +106,70 @@ patch_strip_level()
        echo "1"
 }
 
+is_cvs_file() {
+       [ -d "$(dirname $1)/CVS" ]
+}
+
+cvs_add() {
+       if ! (cd "$(dirname $1)" && cvs -Q add "$(basename $1)") ; then
+               printf $"CVS add failed for file \"%s\".\n" "$1" >&2
+               return 1
+       fi
+       return 0
+}
+
+cvs_edit() {
+       if ! (cd "$(dirname $1)" && cvs edit "$(basename $1)") ; then
+               printf $"CVS edit failed for file \"%s\".\n" "$1" >&2
+               return 1
+       fi
+       return 0
+}
+
+cvs_remove() {
+       if ! (cd "$(dirname $1)" && cvs -Q remove "$(basename $1)") ; then
+               printf $"CVS remove failed for file \"%s\".\n" "$1" >&2
+               return 1
+       fi
+       return 0
+}
+
+# If input file names a symbolic link, print path to real file.
+# If non-existent or not a link, print the input path.
+realfile() {
+       local path=$(find "$1" -printf "%l" 2> /dev/null)
+       if [ "$path" ] ; then
+               if [ "${path:0:1}" != "/" ] ; then
+                       path=$(dirname "$1")"/$path"
+               fi
+       else
+               path="$1"
+       fi
+       echo "$path"
+}
+
+# Make the series file writable
+make_series_writable()
+{
+       seriesfile=$(realfile "$SERIES")
+       if is_cvs_file "$seriesfile" ; then
+               if [ ! -e "$seriesfile" ] ; then
+                       if ! touch "$seriesfile" &> /dev/null ; then
+                               printf $"Cannot create series file \"%s\"." \
+                                       "$SERIES" >&2
+                               return 1
+                       fi
+                       if ! cvs_add "$seriesfile" ; then
+                               rm "$seriesfile"
+                               return 1
+                       fi
+               elif [ ! -w "$seriesfile" ] && ! cvs_edit "$seriesfile" ; then
+                       return 1
+               fi
+       fi
+       return 0
+}
+
 change_db_strip_level()
 {
        local level=$1 patch=$2
@@ -134,6 +198,10 @@ change_db_strip_level()
                ' $SERIES > $tmpfile
                if ! cmp $SERIES $tmpfile >/dev/null 2>/dev/null
                then
+                       if ! make_series_writable ; then
+                               rm -f $tmpfile
+                               return 1
+                       fi
                        cat $tmpfile > $SERIES
                fi
                rm -f $tmpfile
@@ -205,6 +273,10 @@ insert_in_series()
        else
                echo "$patch$patch_args" > $tmpfile
        fi
+       if ! make_series_writable ; then
+               rm -f $tmpfile
+               return 1
+       fi
        cat $tmpfile > $SERIES
        rm -f $tmpfile
 }
@@ -218,7 +290,7 @@ remove_from_series()
        ! /^'"$(quote_re $patch)"'([ \t]|$)/ \
                                { print }
        ' $SERIES > $tmpfile
-       if [ $? -ne 0 ]
+       if [ $? -ne 0 ] || ! make_series_writable
        then
                rm -f $tmpfile
                return 1
@@ -239,7 +311,7 @@ rename_in_series()
                { print }
        END     { exit(! good) }
        ' $SERIES > $tmpfile
-       if [ $? -ne 0 ]
+       if [ $? -ne 0 ] || ! make_series_writable
        then
                rm -f $tmpfile
                return 1

reply via email to

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