quilt-dev
[Top][All Lists]
Advanced

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

[Quilt-dev] [patch 6/6] select/merge documentation on import


From: jayvdb
Subject: [Quilt-dev] [patch 6/6] select/merge documentation on import
Date: Tue, 27 Sep 2005 19:19:28 +1000
User-agent: quilt/0.42-1

Compare imported patch descriptions to prevent destruction.
Remove unused file scripts/parse-patch.in

 quilt/import.in        |   68 +++++++++++++
 scripts/patchfns.in    |   12 ++
 test/import.test       |   26 ++++-
 contrib/import.diff    |  251 -------------------------------------------------
 scripts/parse-patch.in |  160 -------------------------------
 Makefile.in            |    2 
 TODO                   |    4 
 7 files changed, 102 insertions(+), 421 deletions(-)

--- quilt-files.orig/quilt/import.in
+++ quilt-files/quilt/import.in
@@ -33,6 +33,10 @@ current top patch, and must be pushed af
        Patch filename to use inside quilt. This option can only be
        used when importing a single patch.
 
+-d {o|a|n}
+       Keep the old (o), all (a), or new (n) description. This option
+       must be specified if both patches include a description.
+
 -f     Overwite/update existing patches.
 "
                exit 0
@@ -41,7 +45,58 @@ current top patch, and must be pushed af
        fi
 }
 
-options=`getopt -o fn:p:h -- "$@"`
+merge_description()
+{
+       local old="$1" new="$2"
+
+       local old_desc=$(gen_tempfile) new_desc=$(gen_tempfile)
+
+       quilt_command header --strip-diffstat "$old" > $old_desc
+       quilt_command header --strip-diffstat "$new" > $new_desc
+
+       if [ -z $opt_desc ]
+       then
+               # default to reasonable
+               is_empty $old_desc && opt_desc=n
+               [ -z $opt_desc ] && is_empty $new_desc && opt_desc=o
+
+               if [ -z $opt_desc ] && ! diff -q $old_desc $new_desc >/dev/null
+               then
+                       QUILT_NO_DIFF_TIMESTAMPS=1
+                       QUILT_NO_DIFF_INDEX=1
+                       QUILT_DIFF_OPTS="$QUILT_DIFF_OPTS -u"
+                       opt_strip_level=0
+                       printf $"Documentation difference:\n" >&2
+                       diff_file description $old_desc $new_desc | \
+                               sed -e '/[+-][+-][+-].description/d' >&2
+                       printf $"Please use -d {o|a|n} to specify which 
documentation to keep.\n" >&2
+                       return 1
+               fi
+       fi
+
+       local merged_patch=$(gen_tempfile)
+
+       if [ $opt_desc != 'n' ]
+       then
+               cat $old_desc > $merged_patch
+       fi
+
+       if [ $opt_desc = 'a' ]
+       then
+               echo '---' >> $merged_patch
+       fi
+
+       if [ $opt_desc = 'o' ]
+       then
+               cat "$new" | patch_body >> $merged_patch
+       else
+               cat "$new" >> $merged_patch
+       fi
+
+       echo $merged_patch
+}
+
+options=`getopt -o d:fn:p:h -- "$@"`
 
 if [ $? -ne 0 ]
 then
@@ -59,6 +114,12 @@ do
        -p)
                opt_strip=$2
                shift 2 ;;
+       -d)
+               case "$2" in
+                       o|n|a) opt_desc=$2 ;;
+                       *) usage ;;
+               esac
+               shift 2 ;;
        -f)
                opt_force=1
                shift ;;
@@ -110,6 +171,11 @@ do
                               "$(print_patch $patch)" >&2
                        exit 1
                fi
+               if [ "$opt_desc" != 'n' ]
+               then
+                       patch_file=$(merge_description "$dest" "$patch_file") \
+                               || exit 1
+               fi
                printf $"Replacing patch %s with new version\n" \
                       "$(print_patch $patch)" >&2
        elif [ -e "$dest" ]
--- quilt-files.orig/scripts/patchfns.in
+++ quilt-files/scripts/patchfns.in
@@ -329,6 +329,18 @@ is_applied()
        grep -q "^$(quote_bre $patch)\$" $DB
 }
 
+is_empty()
+{
+       local file="$1"
+       local lines=$(cat "$file" | wc -l | xargs echo)
+       if [ $lines -gt 0 ]
+       then
+               return 1
+       else
+               return 0
+       fi
+}
+
 applied_patches()
 {
        [ -e $DB ] || return 1
--- quilt-files.orig/test/import.test
+++ quilt-files/test/import.test
@@ -81,17 +81,35 @@
 
        # a simple use of import
 
+       $ quilt import t/patch1.diff
+       > Patch patches/patch1.diff exists. Replace with -f.
+
+       $ quilt import -f t/patch1.diff
+       > Replacing patch patches/patch1.diff with new version
+
+       # an import requiring a description merge
        $ sed -e 's/original/new/' patches/patch1.diff > t/patch1.diff
        $ quilt import t/patch1.diff
        > Patch patches/patch1.diff exists. Replace with -f.
 
        $ quilt import -f t/patch1.diff
+       > Documentation difference:
+       > @@ -1 +1 @@
+       > -original description
+       > +new description
+       > Please use -d {o|a|n} to specify which documentation to keep.
+
+       $ quilt import -d a -f t/patch1.diff
        > Replacing patch patches/patch1.diff with new version
 
-       $ ls patches/
-       > patch1.diff
-       > patch2.diff
-       > series
+       # quilt header does not work in this case because it stops at '---'
+       $ head -n 3 patches/patch1.diff
+       > original description
+       > ---
+       > new description
+
+       $ quilt import -d n -f t/patch1.diff
+       > Replacing patch patches/patch1.diff with new version
 
        $ quilt header patch1
        > new description
--- quilt-files.orig/contrib/import.diff
+++ /dev/null
@@ -1,251 +0,0 @@
-diff -Nur quilt-2003-02-01/quilt/import.in quilt-2003-02-02/quilt/import.in
---- quilt-2003-02-01/quilt/import.in   2003-01-31 17:25:06.000000000 +0100
-+++ quilt-2003-02-02/quilt/import.in   2003-02-02 01:47:59.000000000 +0100
-@@ -35,6 +35,10 @@
- -n patch
-       File name relative to patches/ to use.
- 
-+-d {o|a|n}
-+      Keep the old (o), all (a), or new (n) description. This option
-+      must be specified if both patches include a description.
-+
- -f    Overwite/update existing patches.
- 
- EOF
-@@ -44,7 +48,7 @@
-       fi
- }
- 
--options=`getopt -o fn:p:h -- "$@"`
-+options=`getopt -o d:fn:p:h -- "$@"`
- 
- if [ $? -ne 0 ]
- then
-@@ -58,8 +62,7 @@
-         case "$1" in
-         -n)
-               opt_patch=$(echo "$2" |
--                          sed -e 's/^'"$(quote_bre $P)"'patches\///' \
--                              -e 's/^\.pc\///')
-+                          sed -e 's/^'"$(quote_bre $P)"'patches\///')
-               shift 2 ;;
-       -p)
-               opt_strip=$2
-@@ -67,6 +70,9 @@
-       -f)
-               opt_force=1
-               shift ;;
-+      -d)
-+              opt_desc=$2
-+              shift 2 ;;
-       -h)
-               usage -h ;;
-         --)
-@@ -83,122 +89,119 @@
-         usage
- fi
- 
--[ -n "$opt_strip" ] && patch_args="-p$opt_strip"
-+[ -n "$opt_strip" -a "$opt_strip" -ne 1 ] && patch_args="-p$opt_strip"
-+
-+case "$opt_desc" in
-+o)
-+      keep_old_desc=1
-+      keep_new_desc=0 ;;
-+a)
-+      keep_old_desc=1
-+      keep_new_desc=1 ;;
-+n)
-+      keep_old_desc=0
-+      keep_new_desc=1 ;;
-+'')
-+      true ;;
-+*)
-+      echo "Invalid option -d$opt_desc"
-+      exit 1
-+esac
- 
--if [ -n "$opt_patch" ]
-+if ! [ -r "$input_file" ]
- then
--      patch=$(stripit "$opt_patch")
--      patch_file="${P}patches/$opt_patch"
--else
--      patch="$(stripit "$input_file")"
--      if [ -n "$patch" ]
--      then
--              opt_patch="$patch.patch"
--      else
--              echo "Please use -n to specify a patch file name."
--              exit 1
--      fi
--      patch_file="${P}patches/$opt_patch"
-+      echo "Cannot read from file $input_file"
-+      exit 1
- fi
- 
--if echo "$patch_file" | grep -q -e $'[ \t]'
-+if [ -z "$opt_patch" ]
- then
--      echo "Patch file name \"$patch_file\" contains whitespace."
-+      opt_patch="$(stripit "$input_file")"
-+fi
-+
-+patch=$(stripit "$opt_patch")
-+if [ -z "$patch" ]
-+then
-+      echo "Please use -n to specify a patch file name."
-       exit 1
- fi
- 
-+patch_file="${P}patches/$opt_patch"
-+case "$patch_file" in
-+*' '*)
-+      echo "Patch file name \"$patch_file\" contains whitespace."
-+      exit 1 ;;
-+esac
-+
-+# If the specified is topmost, pop?
- if is_applied $patch
- then
-       echo "Patch $patch is applied."
-       exit 1
- fi
- 
--case "$input_file" in
--'')
--      tmpfile=$(@MKTEMP@ /tmp/patch-scripts.XXXXXX)
--      if ! cat > $tmpfile
--      then
--              echo "Cannot read from standard input."
--              rm -f $tmpfile
--              exit 1
--      fi
--      input_file=$tmpfile ;;
--*.gz)
--      tmpfile=$(@MKTEMP@ /tmp/patch-scripts.XXXXXX)
--      if ! gzip -cd "$input_file" > $tmpfile
--      then
--              echo "Cannot decompress file $input_file"
--              rm -f $tmpfile
--              exit 1
--      fi
--      input_file=$tmpfile ;;
--*.bz2)
--      tmpfile=$(@MKTEMP@ /tmp/patch-scripts.XXXXXX)
--      if ! bzip2 -cd "$input_file" > $tmpfile
--      then
--              echo "Cannot decompress file $input_file"
--              rm -f $tmpfile
--              exit
--      fi
--      input_file=$tmpfile ;;
--*)
--      if ! [ -r "$input_file" ]
--      then
--              echo "Cannot read from file $input_file"
--              exit 1
--      fi
--esac
-+if [ -n "$patch_file" -a -z "$opt_force" ]
-+then
-+      echo "Patch $patch exists. Replace with -f."
-+      exit 1
-+fi
- 
--if [ -e "$patch_file" ]
-+if [ -e "$patch_file" -a "$keep_old_desc" != 0 ]
- then
--      if [ -z "$opt_force" ]
--      then
--              echo "Patch $patch exists. Replace with -f."
--              exit 1
--      fi
-+      old_desc=$(@MKTEMP@ /tmp/patch-scripts.XXXXXX)
-+      cat_file "$patch_file" \
-+      | patch_description > $old_doc
-+fi
-+
-+if [ "$keep_new_desc" != 0 ]
-+then
-+      new_desc=$(@MKTEMP@ /tmp/patch-scripts.XXXXXX)
-+      cat_file "$input_file" \
-+      | patch_description > $new_desc
-+fi
- 
--      if grep -q '^%patch$' "$patch_file" &&
--         ! grep -q '^%patch$' "$input_file"
-+if [ -s $old_doc -a -s $new_desc -a -z "$opt_desc" ] && \
-+   ! diff -q $old_doc $new_desc >/dev/null
-+then
-+      echo "Documentation difference:"
-+      diff -u $old_doc $new_desc
-+      echo "Please use -d {o|a|n} to specify which documentation to keep."
-+      exit 1
-+elif [ -z "$opt_desc" ]
-+then
-+      [ -s $old_doc ] ; keep_old_files=$?
-+      [ -s $new_doc ] ; keep_new_files=$?
-+fi
-+
-+if [ $keep_old_desc = 1 ]
-+then
-+      mkdir -p $(dirname "$patch_file")
-+      temp_patch=$(@MKTEMP@ "$patch_file.XXXXXX")
-+      cat $old_doc >> $temp_patch
-+      if [ $keep_new_desc = 1 ]
-       then
--              echo "Updating %patch section of patch $patch"
--              if ! @SCRIPTS@/parse-patch -u patch $patch_file < "$input_file"
--              then
--                      echo "Failed to update %patch section of patch $patch"
--                      exit 1
--              fi
-+              echo "---" >> $temp_patch
-+              cat_file "$input_file" >> $temp_patch
-       else
--              echo "Replacing patch $patch with new version"
--              if ! cat "$input_file" > "$patch_file"
--              then
--                      echo "Failed to replace patch $patch"
--                      exit 1
--              fi
-+              # FIX: cat only the non-description part!
-+              cat "$input_file" >> $temp_patch
-       fi
-+      cat_to_file "$patch_file" < $temp_patch
-+      rm -f $temp_patch
- else
--      echo "Importing patch $patch (stored as $patch_file)"
--      if ! grep -q '^%patch$' "$input_file"
--      then
--              echo "%patch" >> "$patch_file"
--      fi
--      if ! cat "$input_file" >> "$patch_file"
--      then
--              echo "Failed to import patch $patch"
--              exit 1
--      fi
-+      # FIX: Make sure the file extensions (.gz|.bz2|) match, and use cp
-+      # if possible...
-+      cat_file "$input_file" \
-+      | cat_to_file "$patch_file"
- fi
- 
- rm -rf .pc/$patch
- 
--if ! patch_in_series $patch &&
--   ! insert_in_series $opt_patch "$patch_args"
-+remove_from_series $patch
-+if ! insert_in_series $opt_patch "$patch_args"
- then
-       echo "Failed to insert $patch in file series."
- fi
--
--if [ -n "$tmpfile" ]
--then
--      rm -f $tmpfile
--fi
- ### Local Variables:
- ### mode: shell-script
- ### End:
--- quilt-files.orig/scripts/parse-patch.in
+++ /dev/null
@@ -1,160 +0,0 @@
address@hidden@ -w
-
-#  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.
-
-# Extract or update a section from a combined patch + documentation +
-# meta information file.
-
-use FileHandle;
-use Getopt::Long;
-use File::Temp qw(tempfile);
-use strict;
-
-# This ugly trick lets the script work even if gettext support is missing.
-# We did so because Locale::gettext doesn't ship with the standard perl
-# distribution.
-BEGIN {
-    if (eval { require Locale::gettext }) {
-       import Locale::gettext;
-       require POSIX;
-       import POSIX, qw(setlocale);
-    } else {
-       eval '
-           use constant LC_MESSAGES => 0;
-           sub setlocale($$) { }
-           sub bindtextdomain($$) { }
-           sub textdomain($) { }
-           sub gettext($) { shift }
-       '
-    }
-}
-
-setlocale(LC_MESSAGES, "");
-bindtextdomain("quilt", "@LOCALEDIR@");
-textdomain("quilt");
-
-sub _($) {
-    return gettext(shift);
-}
-
-my $select;
-my $update;
-
-if (!GetOptions("s|select=s" => \$select,
-               "u|update=s" => \$update) ||
-    (!defined $select && !defined $update)) {
-       print STDERR sprintf(_("USAGE: %s {-s|-u} section file [< 
replacement]\n"), $0);
-       exit 1;
-}
-
-foreach my $arg (@ARGV) {
-       my $fh;
-
-       if (! -e $arg) {
-               $fh = new FileHandle("/dev/null");
-       } elsif ($arg =~ /\.gz$/) {
-               $fh = new FileHandle("gzip -cd $arg |");
-       } elsif ($arg =~ /\.bz2$/) {
-               $fh = new FileHandle("bzip2 -cd $arg |");
-       } else {
-               $fh = new FileHandle("< $arg");
-       }
-
-       unless ($fh) {
-               print STDERR "$arg: $!\n";
-               next;
-       }
-
-       if (defined $select) {
-               my $section = "head";
-               my $newline = "";
-               while (<$fh>) {
-                       if (/^%(.*)/) {
-                               last if $section eq $select;
-                               $section = $1;
-                               next;
-                       }
-                       if ($section eq $select) {
-                               print $newline;
-                               if ($_ eq "\n") {
-                                       $newline = $_;
-                               } else {
-                                       $newline="";
-                                       print;
-                               }
-                       }
-               }
-       } elsif (defined $update) {
-               my ($fh2, $tempname) = tempfile("$arg.XXXXXX");
-               if ($arg =~ /\.gz$/) {
-                       $fh2->close();
-                       if (! -e $tempname) {
-                               die sprintf(
-_("File %s disappeared!\n"), $tempname);
-                       }
-                       $fh2 = new FileHandle("| gzip -c > $tempname");
-               } elsif ($arg =~ /\.bz2$/) {
-                       $fh2->close();
-                       if (! -e $tempname) {
-                               die sprintf(
-_("File %s disappeared!\n"), $tempname);
-                       }
-                       $fh2 = new FileHandle("| bzip2 -c > $tempname");
-               }
-               unless ($fh2) {
-                       die "$tempname: $!\n";
-               }
-
-               # Copy things before updated section
-               my $last_was_newline=1; # start first section in first line
-               while (<$fh>) {
-                       if (/^%(.*)/ && $1 eq $update) {
-                               last;
-                       }
-                       $last_was_newline = ($_ eq "\n");
-                       print $fh2 $_;
-               }
-               print $fh2 "\n"
-                       unless ($last_was_newline);
-
-               # Create/replace updated section
-               print $fh2 "%$update\n";
-               while (<STDIN>) {
-                       print $fh2 $_;
-               }
-               print $fh2 "\n";
-
-               # Skip obsolete section
-               while (<$fh>) {
-                       if (/^%(.*)/) {
-                               print $fh2 $_;
-                               last;
-                       }
-               }
-               # Copy things after updated section
-               while (<$fh>) {
-                       print $fh2 $_;
-               }
-               unless (close $fh2) {
-                       die "$arg.patch: $!\n";
-               }
-
-               if (-e $arg) {
-                       unlink "$arg~";
-                       unless (rename $arg, "$arg~") {
-                               die sprintf(
-_("Failed to rename %s to %s: %s\n"), $arg, "$arg~", $!);
-                       }
-               }
-               unless (rename $tempname, $arg) {
-                       rename("$arg~", $arg);
-                       die sprintf(
-_("Failed to rename %s to %s: %s\n"), $tempname, $arg, $!);
-               }
-       }
-       close $fh;
-}
--- quilt-files.orig/Makefile.in
+++ quilt-files/Makefile.in
@@ -83,7 +83,7 @@ QUILT :=      $(QUILT_IN)
 SRC +=         $(QUILT_SRC:%=quilt/%)
 DIRT +=                $(QUILT_IN:%=quilt/%)
 
-SCRIPTS_IN :=  patchfns parse-patch inspect dependency-graph edmail \
+SCRIPTS_IN :=  patchfns inspect dependency-graph edmail \
                remove-trailing-ws
 
 SCRIPTS_SRC := $(SCRIPTS_IN:%=%.in)
--- quilt-files.orig/TODO
+++ quilt-files/TODO
@@ -79,10 +79,6 @@ quilt import:
        - Add option to replace the currently applied patch with a new
          one, by backing out the topmost patch first.
 
-       - Diff -u the documentation of the old and new file, unless one
-         of them is empty. Let the user decide whether to keep the left
-         or the right documentation, or to merge them both. (-d{ona}?)
-
 quilt setup:
 
        - Also recognize other uses of tar and patch (with options in the

--
John




reply via email to

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