aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2010-10-04 00:49:48 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-10-04 00:49:48 +0200
commit9d113cac425d7f496da4d7b6f309b707cedd6b61 (patch)
treefbb6ba5da0145c5ebb9cd5fa960735778b0db917
parente2069fb325f598c81a37222c8e44436439757029 (diff)
downloadbusybox-w32-9d113cac425d7f496da4d7b6f309b707cedd6b61.tar.gz
busybox-w32-9d113cac425d7f496da4d7b6f309b707cedd6b61.tar.bz2
busybox-w32-9d113cac425d7f496da4d7b6f309b707cedd6b61.zip
patch: tweaks
1) Eliminate spurious warnings about possibly reduced hunks. Instead only note a possible location if we don't find a non-reversed place to apply it. (Otherwise, hunks that move code forward around within a file look reversed at the removal site.) 2) Open the source file read-only, so we can apply patches to read-only files. Signed-off-by: Rob Landley <rob@landley.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/patch.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/editors/patch.c b/editors/patch.c
index c40f54155..0bde2cab3 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -344,14 +344,12 @@ static int apply_one_hunk(void)
344 while (plist && *plist->data == "+-"[reverse]) { 344 while (plist && *plist->data == "+-"[reverse]) {
345 if (data && !strcmp(data, plist->data+1)) { 345 if (data && !strcmp(data, plist->data+1)) {
346 if (!backwarn) { 346 if (!backwarn) {
347 backwarn++; 347 backwarn = TT.linenum;
348 if (option_mask32 & FLAG_IGNORE) { 348 if (option_mask32 & FLAG_IGNORE) {
349 dummy_revert = 1; 349 dummy_revert = 1;
350 reverse ^= 1; 350 reverse ^= 1;
351 continue; 351 continue;
352 } 352 }
353 fdprintf(2,"Possibly reversed hunk %d at %ld\n",
354 TT.hunknum, TT.linenum);
355 } 353 }
356 } 354 }
357 plist = plist->next; 355 plist = plist->next;
@@ -364,6 +362,10 @@ static int apply_one_hunk(void)
364 // Does this hunk need to match EOF? 362 // Does this hunk need to match EOF?
365 if (!plist && matcheof) break; 363 if (!plist && matcheof) break;
366 364
365 if (backwarn)
366 fdprintf(2,"Possibly reversed hunk %d at %ld\n",
367 TT.hunknum, TT.linenum);
368
367 // File ended before we found a place for this hunk. 369 // File ended before we found a place for this hunk.
368 fail_hunk(); 370 fail_hunk();
369 goto done; 371 goto done;
@@ -592,7 +594,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
592 TT.filein = xopen3(name, O_CREAT|O_EXCL|O_RDWR, 0666); 594 TT.filein = xopen3(name, O_CREAT|O_EXCL|O_RDWR, 0666);
593 } else { 595 } else {
594 printf("patching file %s\n", name); 596 printf("patching file %s\n", name);
595 TT.filein = xopen(name, O_RDWR); 597 TT.filein = xopen(name, O_RDONLY);
596 } 598 }
597 TT.fileout = copy_tempfile(TT.filein, name, &TT.tempname); 599 TT.fileout = copy_tempfile(TT.filein, name, &TT.tempname);
598 TT.linenum = 0; 600 TT.linenum = 0;