diff options
-rw-r--r-- | lib/backup-files.c | 37 | ||||
-rw-r--r-- | po/de.po | 4 | ||||
-rw-r--r-- | po/fr.po | 4 | ||||
-rw-r--r-- | po/quilt.pot | 4 | ||||
-rw-r--r-- | quilt/add.in | 3 | ||||
-rw-r--r-- | quilt/diff.in | 11 | ||||
-rw-r--r-- | quilt/new.in | 4 | ||||
-rw-r--r-- | quilt/refresh.in | 2 | ||||
-rw-r--r-- | quilt/remove.in | 6 | ||||
-rw-r--r-- | quilt/snapshot.in | 20 | ||||
-rwxr-xr-x | scripts/apatch.in | 63 | ||||
-rw-r--r-- | scripts/patchfns.in | 83 | ||||
-rwxr-xr-x | scripts/rpatch.in | 63 | ||||
-rw-r--r-- | test/one.test | 35 |
14 files changed, 133 insertions, 206 deletions
diff --git a/lib/backup-files.c b/lib/backup-files.c index e4cd45a..43449e5 100644 --- a/lib/backup-files.c +++ b/lib/backup-files.c @@ -38,7 +38,7 @@ const char *progname; enum { what_backup, what_restore, what_remove }; const char *opt_prefix="", *opt_suffix="", *opt_file=NULL; -int opt_silent=0, opt_what=what_backup; +int opt_silent=0, opt_what=what_backup, opt_ignore_missing=0; #define LINE_LENGTH 1024 @@ -99,7 +99,7 @@ remove_parents(char *filename) } static int -link_or_copy(const char *from, const char *to) +link_or_copy(const char *from, struct stat *st, const char *to) { char buffer[4096]; int from_fd, to_fd, error = 1; @@ -117,7 +117,8 @@ link_or_copy(const char *from, const char *to) perror(from); return 1; } - if ((to_fd = open(to, O_WRONLY|O_TRUNC))) { + unlink(to); /* make sure we don't inherit this file's mode. */ + if ((to_fd = creat(to, st->st_mode))) { perror(to); close(from_fd); return 1; @@ -168,7 +169,8 @@ process_file(char *file) if (!opt_silent) printf("New file %s\n", file); - if ((fd = creat(backup, 0666)) == -1) { + /* GNU patch creates new files with mode==0. */ + if ((fd = creat(backup, 0)) == -1) { perror(backup); return 1; } @@ -176,7 +178,7 @@ process_file(char *file) } else { if (!opt_silent) printf("Copying %s\n", file); - if (link_or_copy(file, backup) != 0) + if (link_or_copy(file, &st, backup) != 0) return 1; } return 0; @@ -185,6 +187,8 @@ process_file(char *file) create_parents(file); if (stat(backup, &st) != 0) { + if (opt_ignore_missing && errno == ENOENT) + return 0; perror(backup); return 1; } @@ -192,8 +196,6 @@ process_file(char *file) if (unlink(file) == 0 || errno == ENOENT) { if (!opt_silent) printf("Removing %s\n", file); - unlink(backup); - remove_parents(backup); } else { perror(file); return 1; @@ -202,13 +204,20 @@ process_file(char *file) if (!opt_silent) printf("Restoring %s\n", file); unlink(file); - if (link_or_copy(backup, file) != 0) + if (link_or_copy(backup, &st, file) != 0) return 1; - unlink(backup); - remove_parents(backup); } + if (!(st.st_mode & S_IWUSR)) { + /* Change mode of backup file so that we + can later remove it. */ + chmod(backup, st.st_mode | S_IWUSR); + } + unlink(backup); + remove_parents(backup); return 0; } else if (opt_what == what_remove) { + /* Change mode of backup file so that we can remove it. */ + chmod(backup, S_IWUSR); unlink(backup); remove_parents(backup); return 0; @@ -216,14 +225,14 @@ process_file(char *file) return 1; } -int + int main(int argc, char *argv[]) { int opt, status=0; progname = argv[0]; - while ((opt = getopt(argc, argv, "rxB:z:f:sh")) != -1) { + while ((opt = getopt(argc, argv, "rxB:z:f:shF")) != -1) { switch(opt) { case 'r': opt_what = what_restore; @@ -241,6 +250,10 @@ main(int argc, char *argv[]) opt_file = optarg; break; + case 'F': /* ignore missing input files */ + opt_ignore_missing = 1; + break; + case 'z': opt_suffix = optarg; break; @@ -812,10 +812,6 @@ msgstr "Unterbrechung durch Benutzer; Patch $patch wurde nicht angewandt." msgid "Patch file $patch_file appears to be empty" msgstr "Patch-Datei $patch_file scheint leer zu sein" -#: ../scripts/apatch.in:80 -msgid "refresh_file_list failed" -msgstr "Fehler in refresh_file_list" - #: ../scripts/apatch.in:84 msgid "Applying $patch" msgstr "Anwenden von $patch" @@ -834,10 +834,6 @@ msgstr "Interrompu par l'utilisateur ; le patch $patch n'a pas été appliqué." msgid "Patch file $patch_file appears to be empty" msgstr "Le fichier de patch $patch_file semble vide" -#: ../scripts/apatch.in:80 -msgid "refresh_file_list failed" -msgstr "refresh_file_list a échoué." - #: ../scripts/apatch.in:84 msgid "Applying $patch" msgstr "Application de $patch" diff --git a/po/quilt.pot b/po/quilt.pot index 6367028..e55b43f 100644 --- a/po/quilt.pot +++ b/po/quilt.pot @@ -620,10 +620,6 @@ msgstr "" msgid "Patch file $patch_file appears to be empty" msgstr "" -#: ../scripts/apatch.in:80 -msgid "refresh_file_list failed" -msgstr "" - #: ../scripts/apatch.in:84 msgid "Applying $patch" msgstr "" diff --git a/quilt/add.in b/quilt/add.in index b6074f7..a2640d2 100644 --- a/quilt/add.in +++ b/quilt/add.in @@ -98,8 +98,7 @@ do continue fi - if ! @LIB@/backup-files -s -B .pc/$patch/ $file || \ - ! echo $file >> $(pc_file_name $patch) + if ! @LIB@/backup-files -s -B .pc/$patch/ $file then echo $"Failed to back up file $file" >&2 status=1 diff --git a/quilt/diff.in b/quilt/diff.in index 2603f0b..6cb5c8a 100644 --- a/quilt/diff.in +++ b/quilt/diff.in @@ -70,6 +70,8 @@ do_diff() if [ -n "$opt_diff" ] then + [ -s "$old_file" ] || old_file=/dev/null + [ -s "$new_file" ] || new_file=/dev/null if ! @DIFF@ -qN $old_file $new_file >/dev/null then $opt_diff $old_file $new_file @@ -223,7 +225,6 @@ files=( $(sort -u $tmp_files) ) if [ -n "$opt_relative" ] then patch_file=$(patch_file_name $last_patch) - pc_file=$(pc_file_name $last_patch) patch_args=$(patch_args $last_patch) workdir=$(gen_tempfile -d $PWD/quilt) pwd=$PWD @@ -238,6 +239,12 @@ then echo $"Failed to copy files to temporary directory" die 1 fi + # Now we may have some zero-size files that have no permissions + # (which represent files that the patch creates). Those may have + # been created in the meantime, but patch would refuse to touch + # them: We must remove them here. + find $workdir -type f -size 0 -exec rm -f '{}' ';' + if ! cd $workdir then echo $"Cannot change to temporary directory" @@ -255,7 +262,7 @@ then # files won't succeed, either. So, ignore the error # in that particular case. - if ! [ -e $pwd/$pc_file~refresh ] + if ! [ -e $pwd/.pc/$last_patch~refresh ] then echo $"Failed to patch temporary files" die 1 diff --git a/quilt/new.in b/quilt/new.in index 301de2d..2266e19 100644 --- a/quilt/new.in +++ b/quilt/new.in @@ -68,8 +68,8 @@ then exit 1 fi -mkdir -p $(dirname $(pc_file_name $patch)) -rm -f $(pc_file_name $patch) +rm -rf ".pc/$patch" +mkdir -p ".pc/$patch" if ! insert_in_series $patch_file || \ ! add_to_db $patch diff --git a/quilt/refresh.in b/quilt/refresh.in index 25fca13..16fa88a 100644 --- a/quilt/refresh.in +++ b/quilt/refresh.in @@ -193,7 +193,7 @@ then die 1 fi -rm -f $(pc_file_name $patch)~refresh +rm -f .pc/$patch~refresh echo $"Refreshed patch $patch" if ! change_db_strip_level -p$opt_strip_level $patch then diff --git a/quilt/remove.in b/quilt/remove.in index d48300b..6e5511e 100644 --- a/quilt/remove.in +++ b/quilt/remove.in @@ -107,12 +107,6 @@ do continue fi - pc_file=$(pc_file_name $patch) - tmpfile=$(gen_tempfile) - grep -v -E '^'"$(quote_re $file)"'$' $pc_file > $tmpfile - mv -f $tmpfile $pc_file - rm -f $tmpfile - echo $"File $file removed from patch $patch" done exit $status diff --git a/quilt/snapshot.in b/quilt/snapshot.in index 6883a59..453f265 100644 --- a/quilt/snapshot.in +++ b/quilt/snapshot.in @@ -63,11 +63,11 @@ then usage fi -snap_dir=.pc/.snap +snap_subdir=.snap # Clean up from previous snapshot -rm -rf $snap_dir -mkdir -p $snap_dir +rm -rf .pc/$snap_subdir +mkdir -p .pc/$snap_subdir if [ -n "$opt_remove" ] then @@ -79,19 +79,25 @@ for patch in $(applied_patches | tac) do for file in $(files_in_patch $patch) do - if ! [ -e "$snap_dir/$file" ] + if ! [ -e ".pc/$snap_subdir/$file" ] then - mkdir -p "$snap_dir/$(dirname $file)" + mkdir -p ".pc/$snap_subdir/$(dirname $file)" if [ -e "$file" ] then - ln "$file" "$snap_dir/$file" + ln "$file" ".pc/$snap_subdir/$file" else - touch "$snap_dir/$file" + touch ".pc/$snap_subdir/$file" fi fi done done +# Now we may have some zero-size files that have no permissions +# (which represent files that the patch creates). Those may have +# been created in the meantime, but patch would refuse to touch +# them: We must remove them here. +find .pc/$snap_subdir -type f -size 0 -exec rm -f '{}' ';' + ### Local Variables: ### mode: shell-script ### End: diff --git a/scripts/apatch.in b/scripts/apatch.in index 973988a..69f327f 100755 --- a/scripts/apatch.in +++ b/scripts/apatch.in @@ -25,13 +25,16 @@ usage() rollback_patch() { - local patch=$1 pc_file=$(pc_file_name $patch) - @LIB@/backup-files $silent_unless_verbose \ - -f $pc_file -B .pc/$patch/ -r + local patch=$1 pc_file=$(gen_tempfile) + + # FIXME backup_files should scan the directory hierarchy itself. + files_in_patch $patch > $pc_file + @LIB@/backup-files $silent_unless_verbose -f $pc_file -B .pc/$patch/ -r if [ -z "$opt_leave_rejects" ] then - rm -f $(files_in_patch $patch | @SED@ -e 's/$/\.rej/') + @SED@ -e 's/$/\.rej/' $pc_file | xargs rm -f fi + rm -f $pc_file } interrupt() @@ -55,15 +58,15 @@ apply_patch() if [ "x${patch_file:(-3)}" = "x.gz" ] then gzip -cd $patch_file \ - | @PATCH@ $(patch_args $patch) --no-backup-if-mismatch \ + | @PATCH@ $(patch_args $patch) --backup --prefix=".pc/$patch/" \ -E $silent $force_apply elif [ "x${patch_file:(-4)}" = "x.bz2" ] then bzip2 -cd $patch_file \ - | @PATCH@ $(patch_args $patch) --no-backup-if-mismatch \ + | @PATCH@ $(patch_args $patch) --backup --prefix=".pc/$patch/" \ -E $silent $force_apply else - @PATCH@ $(patch_args $patch) --no-backup-if-mismatch \ + @PATCH@ $(patch_args $patch) --backup --prefix=".pc/$patch/" \ -E $silent -i $patch_file $force_apply fi } @@ -71,39 +74,9 @@ apply_patch() apatch() { local patch=$(stripit $1) - local pc_file=$(pc_file_name $patch) local file status - trap "" SIGINT - if ! refresh_file_list $patch - then - echo $"refresh_file_list failed" - return 1 - fi - echo $"Applying $patch" - if ! [ -e $pc_file ] - then - echo $"Patch $patch appears to be empty, applied" - add_to_db $patch - return 0 - fi - - status=$? - if [ $status -eq 2 ] - then - [ -z "$opt_quiet" ] && echo $"Recreated file list for $patch" - elif [ $status -ne 0 ] - then - return 1 - fi - - if ! @LIB@/backup-files $silent_unless_verbose \ - -f $pc_file -B .pc/$patch/ - then - exit 1 - fi - trap "interrupt $patch" SIGINT apply_patch $patch @@ -111,18 +84,20 @@ apatch() trap "" SIGINT - # Remember date/time of applying so that pop can - # avoid reverse applying the patch in the usual cases. - touch $pc_file - if [ $status -eq 0 -o -n "$opt_force" ] then add_to_db $patch if [ $status -eq 0 ] then - rm -f $pc_file~refresh + rm -f .pc/$patch~refresh else - touch $pc_file~refresh + touch .pc/$patch~refresh + fi + if [ "$(shopt -s nullglob ; echo .pc/$patch/*)" = "" ] + then + echo $"Patch $patch appears to be empty, applied" + elif [ $status -ne 0 ] + then echo $"Applied $patch (forced; needs refresh)" fi else @@ -181,7 +156,7 @@ fi patch=$(stripit $1) top=$(top_patch) -if [ -n "$top" -a -e $(pc_file_name $top)~refresh ] +if [ -n "$top" -a -e .pc/$top~refresh ] then echo $"The topmost patch $top needs to be refreshed first." exit 1 diff --git a/scripts/patchfns.in b/scripts/patchfns.in index e8f0808..a4329df 100644 --- a/scripts/patchfns.in +++ b/scripts/patchfns.in @@ -234,16 +234,6 @@ rename_in_series() rm -f $tmpfile } -pc_file_name() -{ - while [ $# -gt 0 ] - do - echo ".pc/$1/.pc" - shift - done - -} - backup_file_name() { local patch=$1 @@ -357,10 +347,14 @@ next_patch_for_file() if [ -n "$patches_on_top" ] then - grep -l -E "^$(quote_re $file)\$" \ - $(pc_file_name $patches_on_top) \ - | head -n 1 \ - | @SED@ -e 's:^\.pc/::' -e 's:/\.pc$::' + for patch in $patches_on_top + do + if [ -f $(backup_file_name $patch $file) ] + then + echo $patch + break + fi + done fi } @@ -397,16 +391,19 @@ stripit() file_in_patch() { local file=$1 patch=$2 - files_in_patch $patch \ - | grep -q -E "^$(quote_re $file)\$" + [ -f ".pc/$patch/$file" ] } files_in_patch() { - local pc_file=$(pc_file_name $1) - if [ -e "$pc_file" ] + local patch="$1" + local path=".pc/$patch" + if [ -d "$path" ] then - cat $pc_file + for file in $(find "$path" -type f) + do + echo "${file:${#path}+1}" + done fi } @@ -425,47 +422,6 @@ touched_by_patch() }' } -refresh_file_list() -{ - local patch=$1 - local pc_file=$(pc_file_name $patch) - local patch_file=$(patch_file_name $patch) - - if ! [ -e "$patch_file" ] - then - return 0 - fi - if [ ! -e $pc_file -o \ - $pc_file -ot $patch_file -o \ - $pc_file -ot $SERIES ] - then - local tmpfile status - if ! mkdir -p $(dirname $pc_file) || \ - ! tmpfile=$(gen_tempfile) - then - return 1 - fi - - # Do not reorder files in the file list... - - if [ -e $pc_file ] - then - cat $pc_file >> $tmpfile - fi - if ! touched_by_patch $(patch_strip_level $patch) \ - $patch >> $tmpfile - then - return 1 - fi - @AWK@ ' { if (seen[$0]) next - seen[$0]=1 - print - }' $tmpfile > $pc_file - rm $tmpfile - return 0 - fi -} - fix_diff_header() { local from=$1 to=$2 @@ -478,10 +434,9 @@ diff_file() local file=$1 old_file=$2 new_file=$3 local old_hdr new_hdr line - if [ ! -e "$old_file" -a ! -e "$new_file" ] - then - return 0 - fi + [ -s "$old_file" ] || old_file=/dev/null + [ -s "$new_file" ] || new_file=/dev/null + if [ $opt_strip_level -eq 0 ] then old_hdr=$file.orig diff --git a/scripts/rpatch.in b/scripts/rpatch.in index 286ccd7..9f07f36 100755 --- a/scripts/rpatch.in +++ b/scripts/rpatch.in @@ -57,16 +57,10 @@ files_may_have_changed() { local patch=$1 file local patch_file=$(patch_file_name $patch) - local pc_file=$(pc_file_name $patch) - - if ! [ -e $pc_file ] - then - return 1 - fi - local apply_ts=$(date -r $pc_file '+%s') ts + local apply_ts=$(date -r ".pc/$patch" '+%s') ts - if [ -e "$patch_file" -a $pc_file -ot "$patch_file" ] + if [ -e "$patch_file" -a ".pc/$patch" -ot "$patch_file" ] then return 0 fi @@ -89,18 +83,12 @@ files_may_have_changed() rollback_patch() { - local patch=$1 pc_file=$(pc_file_name $patch) - @LIB@/backup-files $silent_unless_verbose \ - -f $pc_file -z ~rpatch -r - rm -f $(files_in_patch $patch | @SED@ -e 's/$/\.rej/') -} + local patch=$1 pc_file=$2 -interrupt() -{ - local patch=$1 - rollback_patch $patch - echo $"Interrupted by user; patch $patch was not removed." - exit 1 + # We may only have applied the patch half-way, so only some of the + # backup files may exist. Ignore missing files (-F). + @LIB@/backup-files $silent_unless_verbose -f $pc_file -z ~rpatch -rF + @SED@ -e 's/$/\.rej/' $pc_file | xargs rm -f } reverse_patch() @@ -117,24 +105,26 @@ reverse_patch() if [ "x${patch_file:(-3)}" = "x.gz" ] then gzip -cd $patch_file \ - | @PATCH@ $(patch_args $patch) --no-backup-if-mismatch \ + | @PATCH@ $(patch_args $patch) --backup --suffix="~rpatch" \ -R -E $silent elif [ "x${patch_file:(-4)}" = "x.bz2" ] then bzip2 -cd $patch_file \ - | @PATCH@ $(patch_args $patch) --no-backup-if-mismatch \ + | @PATCH@ $(patch_args $patch) --backup --suffix="~rpatch" \ -R -E $silent else - @PATCH@ $(patch_args $patch) --no-backup-if-mismatch \ + @PATCH@ $(patch_args $patch) --backup --suffix="~rpatch" \ -R -E $silent -i $patch_file fi } rpatch() { - local patch=$1 pc_file=$(pc_file_name $patch) + local patch=$1 pc_file=$(gen_tempfile) - if ! [ -e $pc_file ] + # FIXME backup-files should scan the directory tree itself. + files_in_patch $patch > $pc_file + if ! [ -s $pc_file ] then echo $"Patch $patch appears to be empty, removed" remove_from_db $patch @@ -153,24 +143,15 @@ rpatch() @LIB@/backup-files $silent -f $pc_file -B .pc/$patch/ -r status=$? remove_from_db $patch - rm -f $pc_file~refresh + rm -f .pc/$patch~refresh if [ $status != 0 ] then exit $status fi else - if ! @LIB@/backup-files $silent_unless_verbose \ - -f $pc_file -z ~rpatch - then - echo $"Failed to create temporary files" >&2 - return 1 - fi - - trap "interrupt $patch" SIGINT - + trap "interrupted=1" SIGINT reverse_patch $patch status=$? - trap "" SIGINT if [ $status -eq 0 ] && verify_removal $patch @@ -182,11 +163,17 @@ rpatch() remove_from_db $patch else - rollback_patch $patch - echo $"Patch $patch does not remove (enforce with -f)" + rollback_patch $patch $pc_file + if [ -n "$interrupted" ] + then + echo $"Interrupted by user; patch $patch was not removed." + else + echo $"Patch $patch does not remove (enforce with -f)" + fi return 1 fi fi + rm -f $pc_file trap - SIGINT } @@ -233,7 +220,7 @@ patch=$(stripit $1) [ -z "$opt_verbose" ] && silent_unless_verbose=-s top=$(top_patch) -if [ -n "$top" -a -e $(pc_file_name $top)~refresh -a -z "$opt_force" ] +if [ -n "$top" -a -e .pc/$top~refresh -a -z "$opt_force" ] then echo $"The topmost patch $top needs to be refreshed first." exit 1 diff --git a/test/one.test b/test/one.test index 40329a9..b5bbeb1 100644 --- a/test/one.test +++ b/test/one.test @@ -5,6 +5,8 @@ of the installed quilt with `make check'. (To run, type `./run one.test' in this directory.) + $ mkdir d + $ cd d $ mkdir dir $ echo "This is file one." > dir/file1 $ quilt new patch1.diff @@ -27,18 +29,18 @@ of the installed quilt with `make check'. $ echo "This is file two." > file2 $ quilt diff | sed -e "s/\\t.*//" - > Index: test/file2 + > Index: d/file2 > =================================================================== - > --- test.orig/file2 - > +++ test/file2 + > --- d.orig/file2 + > +++ d/file2 > @@ -0,0 +1 @@ > +This is file two. $ quilt diff -z | sed -e "s/\\t.*//" - > Index: test/file2 + > Index: d/file2 > =================================================================== - > --- test.orig/file2 - > +++ test/file2 + > --- d.orig/file2 + > +++ d/file2 > @@ -0,0 +1 @@ > +This is file two. @@ -48,10 +50,10 @@ of the installed quilt with `make check'. $ quilt diff -z $ echo "Another line has been added." >> dir/file1 $ quilt diff -z | sed -e "s/\\t.*//" - > Index: test/dir/file1 + > Index: d/dir/file1 > =================================================================== - > --- test.orig/dir/file1 - > +++ test/dir/file1 + > --- d.orig/dir/file1 + > +++ d/dir/file1 > @@ -1 +1,2 @@ > This is file one. > +Another line has been added. @@ -99,10 +101,10 @@ of the installed quilt with `make check'. $ rm file4 $ quilt diff | sed -e "s/\\t.*//" - > Index: test/file4 + > Index: d/file4 > =================================================================== - > --- test.orig/file4 - > +++ test/file4 + > --- d.orig/file4 + > +++ d/file4 > @@ -1 +0,0 @@ > -This is file 4. @@ -118,10 +120,10 @@ of the installed quilt with `make check'. $ echo "Another line added." >> file2 $ quilt diff -z -P patch1 | sed -e "s/\\t.*//" - > Index: test/file2 + > Index: d/file2 > =================================================================== - > --- test.orig/file2 - > +++ test/file2 + > --- d.orig/file2 + > +++ d/file2 > @@ -1 +1,2 @@ > This is file two. > +Another line added. @@ -148,4 +150,5 @@ of the installed quilt with `make check'. > Removing patch1 > No patches applied - $ rm -r dir patches + $ cd .. + $ rm -rf d |