[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] tweaks to editors/patch.c
From:       Rob Landley <rob () landley ! net>
Date:       2010-09-28 20:29:45
Message-ID: 201009281529.46295.rob () landley ! net
[Download RAW message or body]

Two things:

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.

Rob
-- 
GPLv3: as worthy a successor as The Phantom Menace, as timely as Duke Nukem 
Forever, and as welcome as New Coke.

["patch1.patch" (text/x-patch)]

diff --git a/editors/patch.c b/editors/patch.c
index c40f541..0bde2ca 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -344,14 +344,12 @@ static int apply_one_hunk(void)
 		while (plist && *plist->data == "+-"[reverse]) {
 			if (data && !strcmp(data, plist->data+1)) {
 				if (!backwarn) {
-					backwarn++;
+					backwarn = TT.linenum;
 					if (option_mask32 & FLAG_IGNORE) {
 						dummy_revert = 1;
 						reverse ^= 1;
 						continue;
 					}
-					fdprintf(2,"Possibly reversed hunk %d at %ld\n",
-						TT.hunknum, TT.linenum);
 				}
 			}
 			plist = plist->next;
@@ -364,6 +362,10 @@ static int apply_one_hunk(void)
 			// Does this hunk need to match EOF?
 			if (!plist && matcheof) break;
 
+			if (backwarn)
+				fdprintf(2,"Possibly reversed hunk %d at %ld\n",
+					TT.hunknum, TT.linenum);
+
 			// File ended before we found a place for this hunk.
 			fail_hunk();
 			goto done;
@@ -592,7 +594,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
 						TT.filein = xopen3(name, O_CREAT|O_EXCL|O_RDWR, 0666);
 					} else {
 						printf("patching file %s\n", name);
-						TT.filein = xopen(name, O_RDWR);
+						TT.filein = xopen(name, O_RDONLY);
 					}
 					TT.fileout = copy_tempfile(TT.filein, name, &TT.tempname);
 					TT.linenum = 0;


_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic