quilt-dev
[Top][All Lists]
Advanced

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

Re: [Quilt-dev] status query for patch description feature


From: Joe Green
Subject: Re: [Quilt-dev] status query for patch description feature
Date: Tue, 29 Jun 2004 19:15:20 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113

Yasushi SHOJI wrote:
could you briefly explain how you implemented "quilt header", if
possible? or send me the patch?

Patch is attached.

Basically, "quilt header" prints the existing header, if any.
"quilt header -e" creates a header if none exists, or edits an existing one.

When creating a new header it fetches a template from $QUILT_PATCHES/default_header if it exists, else /usr/lib/quilt/default_header. Comment lines can be added to templates (lines starting with "// ") which will be deleted when the header is saved.

At least for me, once I fix the format, I'd be using same header
format again and again for a project.  I don't want to "quilt header"
every single time we "quilt ref" for new patch.

For me, the main purpose of "quilt header -e" is to enter a description of each patch, so my intention is that it would be executed for each patch. I don't know if this matches your needs.

I'm _not_ against "quilt header" (I can't be because I haven't seen it
yet.)  I just thought that if we have, say, "header" file in the
patches dir, "quilt ref" can use it as a default header for the first
time patch generation.  "qulit header" feature is, if my guess is
right, orthogonal to "header" format file feature.

Could be.

--
Joe Green <address@hidden>
MontaVista Software, Inc.
Add "header" subcommand, used to view or edit patch headers.

Joe Green <address@hidden>


Index: quilt-0.34/Makefile.in
===================================================================
--- quilt-0.34.orig/Makefile.in 2004-06-30 01:32:03.000000000 +0000
+++ quilt-0.34/Makefile.in      2004-06-30 01:32:35.000000000 +0000
@@ -56,8 +56,8 @@
 DIRT +=                $(BIN_IN:%=bin/%)
 
 QUILT_IN :=    add applied delete diff edit files fold fork graph grep \
-               import new next patches pop previous push refresh remove \
-               series setup snapshot top unapplied upgrade
+               header import new next patches pop previous push refresh \
+               remove series setup snapshot top unapplied upgrade
 
 QUILT_SRC :=   $(QUILT_IN:%=%.in)
 QUILT :=       $(QUILT_IN)
@@ -242,6 +242,7 @@
 
        @INSTALL@ -d $(BUILD_ROOT)$(LIB_DIR)
        @INSTALL@ -m 755 -s $(LIB:%=lib/%) $(BUILD_ROOT)$(LIB_DIR)/
+       @INSTALL@ -m 644 default_header $(BUILD_ROOT)$(LIB_DIR)/
 
        @INSTALL@ -d $(BUILD_ROOT)$(docdir)/$(PACKAGE)-$(VERSION)/
        @INSTALL@ -m 644 doc/README \
Index: quilt-0.34/bash_completion
===================================================================
--- quilt-0.34.orig/bash_completion     2004-06-30 01:32:04.000000000 +0000
+++ quilt-0.34/bash_completion  2004-06-30 01:32:04.000000000 +0000
@@ -25,8 +25,8 @@
 
     # 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'
+          header import new next patches pop previous push refresh \
+         remove series setup snapshot top unapplied'
 
     # if no command were given, complete on commands
     if [[ $COMP_CWORD -eq 1 ]] ; then
@@ -103,6 +103,16 @@
        grep)
           COMPREPLY=( address@hidden:-} $( compgen -W "-h" -- $cur ) )
           ;;
+       header)
+          case $prev in
+            -P)
+               COMPREPLY=( $( compgen -W "$(quilt applied)" -- $cur ) )
+               ;;
+            *)
+               COMPREPLY=( $(compgen -W "-e -P -h" -- $cur) )
+               ;;
+          esac
+          ;;
        import)
           case $prev in
             -p)
Index: quilt-0.34/default_header
===================================================================
--- quilt-0.34.orig/default_header      1970-01-01 00:00:00.000000000 +0000
+++ quilt-0.34/default_header   2004-06-30 01:32:04.000000000 +0000
@@ -0,0 +1 @@
+// Lines beginning with "// " will be automatically removed.
Index: quilt-0.34/quilt/header.in
===================================================================
--- quilt-0.34.orig/quilt/header.in     1970-01-01 00:00:00.000000000 +0000
+++ quilt-0.34/quilt/header.in  2004-06-30 01:33:57.000000000 +0000
@@ -0,0 +1,143 @@
+#! @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()
+{
+       echo $"Usage: quilt header [-P patch]"
+       if [ x$1 = x-h ]
+       then
+               echo $"
+View or edit the header for the topmost or named patch.  When \"-e\"
+is not specified, the header currently associated with the patch is
+displayed.
+
+-e     Edit header using editor specified by EDITOR variable.
+
+-P patch
+       Edit header for this patch."
+               exit 0
+       else
+               exit 1
+       fi
+}
+
+: ${EDITOR:=vi}
+
+options=`getopt -o eP:h -- "$@"`
+
+if [ $? -ne 0 ] ; then
+       usage
+fi
+
+eval set -- "$options"
+
+while true ; do
+       case "$1" in
+       -e)
+               opt_edit=1
+               shift ;;
+       -P)
+               if ! patch=$(find_patch $2)
+               then
+                       echo $"Patch $2 is not in series" >&2
+                       exit 1
+               fi
+               shift 2 ;;
+       -h)
+               usage -h ;;
+       --)
+               shift
+               break ;;
+       esac
+done
+
+if [ $# -ne 0 ] ; then
+       usage
+fi
+
+if [ -n "$patch" ] ; then
+       if ! is_applied "$patch" ; then
+               echo $"Patch $patch is not applied" >&2
+               exit 1
+       fi
+else
+       patch="$(top_patch)"
+       if [ -z "$patch" ] ; then
+               echo $"No patches applied" >&2
+               exit 1
+       fi
+fi
+
+# Get header from patch if it hasn't been fetched yet.
+# This should only be necessary if an older version of quilt was used.
+extract_patch_header "$patch"
+
+if [ "$opt_edit" ] ; then
+       if [ -e "$QUILT_PC/$patch/.header" ] ; then
+               original="$QUILT_PC/$patch/.header"
+       elif [ -e "$QUILT_PATCHES/default_header" ] ; then
+               original="$QUILT_PATCHES/default_header"
+       else
+               original="@LIB@/default_header"
+       fi
+
+       tmpfile=$(gen_tempfile)
+       if ! echo $"// Editing header for patch \"$patch\"." > "$tmpfile" \
+           || ! cat "$original" >> "$tmpfile"
+       then
+               rm -f "$tmpfile"
+               echo $"Cannot initialize header for patch $patch" >&2
+               exit 1
+       fi
+
+       check=$(md5sum "$tmpfile")
+
+       $EDITOR "$tmpfile"
+       status=$?
+
+       if [ $status -ne 0 ] ; then
+               echo $"Error invoking editor \"$EDITOR\"" >&2
+               rm -f "$tmpfile"
+               exit $status
+       fi
+
+       if [ "$check" != "$(md5sum $tmpfile)" ] ; then
+               if ! @SED@ -e "/^\/\/ /d" "$tmpfile" > 
"$QUILT_PC/$patch/.header" \
+                   || ( [ "$(tail -n 1 $QUILT_PC/$patch/.header)" != "" ] \
+                       && ! echo >> "$QUILT_PC/$patch/.header" )
+               then
+                       echo $"Cannot create header for patch $patch" >&2
+                       rm -f "$tmpfile"
+                       exit 1
+               fi
+
+       fi
+
+       rm -f "$tmpfile"
+elif [ -e "$QUILT_PC/$patch/.header" ] ; then
+       cat "$QUILT_PC/$patch/.header"
+else
+       echo $"There is no header for patch $patch" >&2
+fi
+
+exit $status
+### Local Variables:
+### mode: shell-script
+### End:
+# vim:filetype=sh
Index: quilt-0.34/quilt/refresh.in
===================================================================
--- quilt-0.34.orig/quilt/refresh.in    2004-06-30 01:32:03.000000000 +0000
+++ quilt-0.34/quilt/refresh.in 2004-06-30 01:32:04.000000000 +0000
@@ -170,9 +170,10 @@
 
 mkdir -p $(dirname $patch_file)
 
-if ! cat_file $patch_file \
-     | patch_description > $tmpfile2 || \
-   ! cat $tmpfile >> $tmpfile2
+extract_patch_header $patch
+if ( [ -e "$QUILT_PC/$patch/.header" ] \
+    && ! cat "$QUILT_PC/$patch/.header" > $tmpfile2 ) \
+    || ! cat $tmpfile >> $tmpfile2
 then
        die 1
 fi
Index: quilt-0.34/scripts/apatch.in
===================================================================
--- quilt-0.34.orig/scripts/apatch.in   2004-06-06 00:20:20.000000000 +0000
+++ quilt-0.34/scripts/apatch.in        2004-06-30 01:32:04.000000000 +0000
@@ -108,6 +108,7 @@
                
                if [ -e "$QUILT_PC/$patch" ]
                then
+                       extract_patch_header "$patch"
                        touch $QUILT_PC/$patch/.timestamp
                fi
 
Index: quilt-0.34/scripts/dependency-graph.in
===================================================================
--- quilt-0.34.orig/scripts/dependency-graph.in 2004-06-06 20:17:06.000000000 
+0000
+++ quilt-0.34/scripts/dependency-graph.in      2004-06-30 01:32:04.000000000 
+0000
@@ -241,7 +241,7 @@
                        print STDERR "$ENV{QUILT_PC}/$patch does not exist; 
skipping\n";
                        next;
                }
-               @files = split(/\n/, `cd $ENV{QUILT_PC}/$patch ; find -type f ! 
-name .timestamp`);
+               @files = split(/\n/, `cd $ENV{QUILT_PC}/$patch ; find -type f ! 
-name .timestamp ! -name .header`);
                @files = map { s:\./::; $_ } @files;
        }
        push @nodes, {number=>$n++, name=>$patch, file=>$patch,
Index: quilt-0.34/scripts/patchfns.in
===================================================================
--- quilt-0.34.orig/scripts/patchfns.in 2004-06-30 01:32:04.000000000 +0000
+++ quilt-0.34/scripts/patchfns.in      2004-06-30 01:32:04.000000000 +0000
@@ -443,7 +443,8 @@
        if [ -d "$path" ]
        then
                for file in $(find "$path" -type f \
-                                  -a ! -path "$path/.timestamp")
+                                  -a ! -path "$path/.timestamp" \
+                                  -a ! -path "$path/.header")
                do
                        echo "${file:${#path}+1}"
                done
@@ -717,6 +718,24 @@
        return 1
 }
 
+extract_patch_header()
+{
+       local patch=$1
+       local patch_file=$(patch_file_name "$patch")
+       local header_file="$QUILT_PC/$patch/.header"
+
+       if [ -e "$QUILT_PC/$patch" -a ! -e "$header_file" -a -e "$patch_file" ]
+       then
+               patch_description "$patch_file" > "$header_file"
+               if [ ! -s "$header_file" ]
+               then
+                       rm -f "$header_file"
+               elif [ "$(tail -n 1 $header_file)" != "" ] ; then
+                       echo >> "$header_file"
+               fi
+       fi
+}
+
 
 #
 # If the working directory does not contain a $QUILT_PATCHES directory,
Index: quilt-0.34/scripts/rpatch.in
===================================================================
--- quilt-0.34.orig/scripts/rpatch.in   2004-06-06 00:20:20.000000000 +0000
+++ quilt-0.34/scripts/rpatch.in        2004-06-30 01:32:04.000000000 +0000
@@ -121,6 +121,7 @@
        then
                echo $"Removing $patch"
                rm -f "$QUILT_PC/$patch/.timestamp"
+               rm -f "$QUILT_PC/$patch/.header"
                @LIB@/backup-files $silent -r -B $QUILT_PC/$patch/ -
                status=$?
                remove_from_db $patch

reply via email to

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