quilt-dev
[Top][All Lists]
Advanced

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

[Quilt-dev] [PATCH RFC] Add option --preamble to diff and refresh


From: Jean Delvare
Subject: [Quilt-dev] [PATCH RFC] Add option --preamble to diff and refresh
Date: Thu, 13 Oct 2022 14:34:27 +0200

Option --preamble can be used to let quilt generate extra lines
before the actual diff. For now one preamble format is supported,
"diff", which will generate a line like:

> diff -- a/dir/file b/dir/file

This is meant to help other tools recognize the beginning of the
patch body, namely lore.kernel.org.

Suggested-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Jean Delvare <jdelvare@suse.de>
---
Randy, this is a tentative implementation of the feature you requested.
Please give it a try and let me know if it works for you.

Note that I made the line start with "diff --" rather than just "diff".
The reason is that just matching for "^diff " could easily lead to
false positives as this pattern could legitimately appear in the patch
header. This is compatible with the way quilt currently detects the
start of body for git-generated patches.

I am moderately happy with the implementation, somehow it feels like
--no-index and --preamble should be merged into a single option, but it
seems difficult to do that without breaking backward compatibility. But
I don't know if we care.

 doc/quilt.1.in            |    8 ++++++++
 quilt/diff.in             |    8 +++++++-
 quilt/refresh.in          |    8 +++++++-
 quilt/scripts/patchfns.in |   14 ++++++++++----
 4 files changed, 32 insertions(+), 6 deletions(-)

--- quilt.orig/quilt/scripts/patchfns.in
+++ quilt/quilt/scripts/patchfns.in
@@ -745,10 +745,16 @@ diff_file()
                if [[ "$line" =~ ^Binary\ files\ .*\ differ$ ]]
                then
                        status=1
-               elif [ -z "$QUILT_NO_DIFF_INDEX" ]
-               then
-                       echo "Index: $index"
-                       echo 
"==================================================================="
+               else
+                       if [ -z "$QUILT_NO_DIFF_INDEX" ]
+                       then
+                               echo "Index: $index"
+                               echo 
"==================================================================="
+                       fi
+                       if [ "$QUILT_DIFF_PREAMBLE" == "diff" ]
+                       then
+                               echo "diff -- $old_hdr $new_hdr"
+                       fi
                fi
 
                echo "$line"
--- quilt.orig/doc/quilt.1.in
+++ quilt/doc/quilt.1.in
@@ -406,6 +406,14 @@ This is shorthand for adding \\[lq]\\-\\
 and
 .IR QUILT_REFRESH_ARGS .
 .TP 4
+.I QUILT_DIFF_PREAMBLE
+If set to \\[lq]diff\\[rq], a \\[lq]diff\\[rq] line is prepended to
+patches generated by .IR quilt .
+This is shorthand for adding \\[lq]\\-\\-preamble=diff\\[rq] to both
+.I QUILT_DIFF_ARGS
+and
+.IR QUILT_REFRESH_ARGS .
+.TP 4
 .I QUILT_NO_DIFF_TIMESTAMPS
 Boolean flag; if set to anything,
 no timestamps are included in headers when generating patches.
--- quilt.orig/quilt/diff.in
+++ quilt/quilt/diff.in
@@ -34,6 +34,9 @@ included.
 --no-index
        Do not output Index: lines.
 
+--preamble=diff
+       Output diff lines.
+
 -z     Write to standard output the changes that have been made
        relative to the topmost or specified patch.
 
@@ -125,7 +128,7 @@ die()
 
 options=`getopt -o p:P:RuU:cC:zh --long diff:,snapshot,no-timestamps \
                                 --long no-index,combine:,color:: \
-                                --long sort -- "$@"`
+                                --long sort,preamble: -- "$@"`
 
 if [ $? -ne 0 ]
 then
@@ -175,6 +178,9 @@ do
        --no-index)
                QUILT_NO_DIFF_INDEX=1
                shift ;;
+       --preamble)
+               QUILT_DIFF_PREAMBLE=$2
+               shift 2 ;;
        --sort)
                opt_sort=1
                shift ;;
--- quilt.orig/quilt/refresh.in
+++ quilt/quilt/refresh.in
@@ -47,6 +47,9 @@ patch.
 --no-index
        Do not output Index: lines.
 
+--preamble=diff
+       Output diff lines.
+
 --diffstat
        Add a diffstat section to the patch header, or replace the
        existing diffstat section.
@@ -77,7 +80,7 @@ die()
 }
 
 options=`getopt -o p:uU:cC:fz::h --long no-timestamps,diffstat,backup,sort \
-                                --long no-index \
+                                --long no-index,preamble: \
                                 --long strip-trailing-whitespace -- "$@"`
 
 if [ $? -ne 0 ]
@@ -115,6 +118,9 @@ do
        --no-index)
                QUILT_NO_DIFF_INDEX=1
                shift ;;
+       --preamble)
+               QUILT_DIFF_PREAMBLE=$2
+               shift 2 ;;
        --diffstat)
                opt_diffstat=1
                shift ;;


-- 
Jean Delvare
SUSE L3 Support



reply via email to

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