quilt-dev
[Top][All Lists]
Advanced

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

[Quilt-dev] Some enhancements for the "quilt header" command


From: Joe Green
Subject: [Quilt-dev] Some enhancements for the "quilt header" command
Date: Wed, 24 Aug 2005 18:16:37 -0700
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)

Hi,

I have some patches that implement some enhancements to the "quilt header" command.  These have been helpful to us, and I thought others might find them useful.
quilt-header_templates.patch
This patch allows template header files to be created which will be provided to a users who edits a patch header that is currently empty.  It takes the first file it finds of $QUILT_PATCHES/quilt.header, $HOME/.quilt.header, and /etc/quilt.header.  So, default headers can be created by project, user or distribution.
quilt-header_comments.patch
This patch allows comments to be placed in header template files that will be stripped out when the header is saved.  These comments can be used to prompt the user for the kind of information that should be in the header.  This implemenation assumes any line in the header beginning with "//" is a comment, and strips it out.
quilt-padheader.patch
This patch adds a "--pad" option to the header command to automatically add one or more blank lines to separate the header from the body.
-- 
Joe Green <address@hidden>
MontaVista Software, Inc.
Source: MontaVista Software, Inc. <address@hidden>
Type: Enhancement
Disposition: submit to http://savannah.nongnu.org/projects/quilt

Add support for header templates when there is no patch header and editor
is invoked.

Index: quilt-0.42/quilt/header.in
===================================================================
--- quilt-0.42.orig/quilt/header.in
+++ quilt-0.42/quilt/header.in
@@ -174,6 +174,20 @@ else
 
        if [ -n "$opt_edit" ]
        then
+               if ! [ -s "$tmp" ]
+               then
+                       for template in \
+                               $QUILT_PATCHES/quilt.header \
+                               $HOME/.quilt.header \
+                               /etc/quilt.header
+                       do
+                               if [ -e "$template" ]
+                               then
+                                       cat "$template" > $tmp
+                                       break
+                               fi
+                       done
+               fi
                $EDITOR "$tmp" || exit 1
        fi
 
Source: MontaVista Software, Inc. <address@hidden>
Type: Enhancement
Disposition: submit to http://savannah.nongnu.org/projects/quilt

Add support for comments in header templates that will be automatically
stripped out after the header is edited.

Comments are any line that begins with "//".


Index: quilt-0.42/quilt/header.in
===================================================================
--- quilt-0.42.orig/quilt/header.in
+++ quilt-0.42/quilt/header.in
@@ -183,12 +183,17 @@ else
                        do
                                if [ -e "$template" ]
                                then
-                                       cat "$template" > $tmp
+                                       cat "$template" > "$tmp2"
                                        break
                                fi
                        done
+               else
+                       cat "$tmp" > "$tmp2"
                fi
-               $EDITOR "$tmp" || exit 1
+
+               $EDITOR "$tmp2" || exit 1
+
+               grep -v "^//" < "$tmp2" > "$tmp"
        fi
 
        maybe_strip_diffstat < $tmp \
Source: MontaVista Software, Inc. <address@hidden>
Type: Enhancement
Disposition: submit to http://savannah.nongnu.org/projects/quilt

Add "--pad" option to header command to allow forced padding by a specified
number of blank lines.

Index: quilt-0.42/quilt/header.in
===================================================================
--- quilt-0.42.orig/quilt/header.in
+++ quilt-0.42/quilt/header.in
@@ -21,7 +21,7 @@ fi
 
 usage()
 {
-       printf $"Usage: quilt header [-a|-r|-e] [--backup] [--strip-diffstat] 
[--strip-trailing-whitespace] [patch]\n"
+       printf $"Usage: quilt header [-a|-r|-e] [--backup] [--pad[=n]] 
[--strip-diffstat] [--strip-trailing-whitespace] [patch]\n"
 
        if [ x$1 = x-h ]
        then
@@ -33,6 +33,10 @@ Print or change the header of the topmos
        edit (-e) the header in \$EDITOR (%s). If none of these options is
        given, print the patch header.
        
+--pad[=n]
+       Make sure a new header ends with at least \"n\" blank lines.
+       If \"--pad\" is specified alone, \"n\" is assumed to be 1.
+
 --strip-diffstat
        Strip diffstat output from the header.
 
@@ -48,6 +52,23 @@ Print or change the header of the topmos
        fi
 }
 
+maybe_pad_header()
+{
+       [ "$opt_pad" ] || opt_pad=0
+       @AWK@ -v pad=$opt_pad '
+           BEGIN       { blanks = pad }
+                       { print }
+           /^[ \t]*$/  { blanks += 1; next }
+                       { blanks = 0 }
+           END         {
+                           while (blanks < pad) {
+                               print ""
+                               blanks += 1
+                           }
+                       }
+       '
+}
+
 maybe_strip_trailing_whitespace()
 {
        if [ -n "$opt_strip_trailing_whitespace" ]
@@ -77,7 +98,7 @@ maybe_strip_diffstat()
        fi
 }
 
-options=`getopt -o areh --long backup,strip-trailing-whitespace,strip-diffstat 
-- "$@"`
+options=`getopt -o areh --long 
backup,pad::,strip-trailing-whitespace,strip-diffstat -- "$@"`
 
 if [ $? -ne 0 ]
 then
@@ -101,6 +122,16 @@ do
        --backup)
                QUILT_BACKUP=1
                shift ;;
+       --pad)
+               case "$2" in
+               "")
+                       opt_pad=1 ;;
+               [0-9])
+                       opt_pad="$2" ;;
+               *)
+                       usage ;;
+               esac
+               shift 2 ;;
        --strip-diffstat)
                opt_strip_diffstat=1
                shift ;;
@@ -197,7 +228,8 @@ else
        fi
 
        maybe_strip_diffstat < $tmp \
-       | maybe_strip_trailing_whitespace > $tmp2
+       | maybe_strip_trailing_whitespace \
+       | maybe_pad_header > $tmp2
        
        cat_file "$patch_file_or_null" | patch_body >> $tmp2 || exit 1
 

reply via email to

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