[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Quilt-dev] handling empty new files
From: |
Joe Green |
Subject: |
Re: [Quilt-dev] handling empty new files |
Date: |
Wed, 10 Aug 2005 18:28:09 -0700 |
User-agent: |
Mozilla Thunderbird 1.0.2 (X11/20050317) |
Joe Green wrote:
The problem is that quilt forces the "-E" option when it invokes
patch. If this option is not specified, patch can determine the
difference between an empty file and a removed or added file by
looking at the patch file names (/dev/null "to" file means removed,
on "from" file means added) or the file timestamps (epoch means
removed/added).
I've attached a sample patch to remove this option. Warning: I've
just updated this to 0.42; I haven't tested it yet, but it's fairly
straightforward.
OK, now that I've done the testing, it's not quite that straightforward. :)
The attached patch shows the changes that are needed. This gets it
working the way I've used it before: you can remove all the lines from
a file in a patch, and patch knows the difference between this and
removing a file.
However, it doesn't look like diff or patch will support creating an
empty file in one step. Diff won't generate the output for an empty
file, and patch won't accept it if I cobble it up by hand, using what I
think would be the correct syntax. It seems a bit odd that patch would
only implement part of the solution, but I wasn't able to find a way to
make it work.
So, with this patch applied you could have empty files by having one
patch add the file with some dummy content, and then have a subsequent
patch remove that content, but that's pretty gross. In practice, it's
probably best to just avoid empty files as Jean Devere originally
suggested. Sorry for the unnecessary runaround.
--
Joe Green <address@hidden>
MontaVista Software, Inc.
Source: MontaVista Software, Inc <address@hidden>
Type: Enhancement
Don't assume empty files are the same as removed files. Allow patch
to recognize the difference.
Index: quilt-0.42/quilt/diff.in
===================================================================
--- quilt-0.42.orig/quilt/diff.in
+++ quilt-0.42/quilt/diff.in
@@ -114,8 +114,8 @@ do_diff()
if [ -n "$opt_diff" ]
then
- [ -s "$old_file" ] || old_file=/dev/null
- [ -s "$new_file" ] || new_file=/dev/null
+ [ -r "$old_file" ] || old_file=/dev/null
+ [ -r "$new_file" ] || new_file=/dev/null
if ! @DIFF@ -qN $old_file $new_file >/dev/null
then
export LANG=$ORIGINAL_LANG
@@ -353,7 +353,7 @@ then
then
if ! cat_file $patch_file \
| @PATCH@ -d $workdir $QUILT_PATCH_OPTS $patch_args \
- --no-backup-if-mismatch -Ef \
+ --no-backup-if-mismatch -f \
>/dev/null 2>/dev/null
then
# Generating a relative diff for a subset of files in
Index: quilt-0.42/quilt/fold.in
===================================================================
--- quilt-0.42.orig/quilt/fold.in
+++ quilt-0.42/quilt/fold.in
@@ -83,7 +83,7 @@ fi
trap "failed=1" SIGINT
workdir=$(gen_tempfile -d $PWD)
address@hidden@ $QUILT_PATCH_OPTS -p$opt_strip_level $silent --backup
--prefix="$workdir/" -E \
address@hidden@ $QUILT_PATCH_OPTS -p$opt_strip_level $silent --backup
--prefix="$workdir/" \
|| failed=1
if [ -z "$failed" ]
Index: quilt-0.42/quilt/pop.in
===================================================================
--- quilt-0.42.orig/quilt/pop.in
+++ quilt-0.42/quilt/pop.in
@@ -130,7 +130,7 @@ check_for_pending_changes()
if ! cat_file $patch_file \
| @PATCH@ -d $workdir $QUILT_PATCH_OPTS \
$(patch_args $patch) \
- --no-backup-if-mismatch -E \
+ --no-backup-if-mismatch \
>/dev/null 2>/dev/null
then
if ! [ -e $QUILT_PC/$patch ]
Index: quilt-0.42/quilt/push.in
===================================================================
--- quilt-0.42.orig/quilt/push.in
+++ quilt-0.42/quilt/push.in
@@ -99,19 +99,19 @@ apply_patch()
| @PATCH@ $QUILT_PATCH_OPTS $(patch_args $patch) \
--backup --prefix="$QUILT_PC/$patch/" \
$no_reject_files \
- -E $silent $force_apply 2>&1
+ $silent $force_apply 2>&1
elif [ "${patch_file:(-4)}" = ".bz2" ]
then
bzip2 -cd $patch_file \
| @PATCH@ $QUILT_PATCH_OPTS $(patch_args $patch) \
--backup --prefix="$QUILT_PC/$patch/" \
$no_reject_files \
- -E $silent $force_apply 2>&1
+ $silent $force_apply 2>&1
else
@PATCH@ $QUILT_PATCH_OPTS $(patch_args $patch) \
--backup --prefix="$QUILT_PC/$patch/" \
$no_reject_files \
- -E $silent $force_apply -i $patch_file 2>&1
+ $silent $force_apply -i $patch_file 2>&1
fi
}
Index: quilt-0.42/scripts/patchfns.in
===================================================================
--- quilt-0.42.orig/scripts/patchfns.in
+++ quilt-0.42/scripts/patchfns.in
@@ -534,7 +534,7 @@ diff_file()
fi
index=$new_hdr
- if ! [ -s "$old_file" ]
+ if ! [ -r "$old_file" ]
then
old_file=/dev/null
old_hdr=/dev/null
@@ -545,7 +545,7 @@ diff_file()
|| old_date=$'\t'$(date +'%Y-%m-%d %H:%M:%S.%N %z' \
-r "$old_file")
fi
- if ! [ -s "$new_file" ]
+ if ! [ -r "$new_file" ]
then
new_file=/dev/null
new_hdr=/dev/null
Index: quilt-0.42/lib/backup-files.c
===================================================================
--- quilt-0.42.orig/lib/backup-files.c
+++ quilt-0.42/lib/backup-files.c
@@ -263,7 +263,7 @@ process_file(const char *file)
perror(backup);
return 1;
}
- if (st.st_size == 0) {
+ if (!(st.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO))) {
if (unlink(file) == 0 || errno == ENOENT) {
if (!opt_silent)
printf("Removing %s\n", file);