Hi,

  the attached patch adds the "interactive" feature for patching:
when specifying the -I  (or --interactive) option, "patch" asks whether to
apply or not each hunk.

Based on 2.6.1.

HTH,

  Daniel.





-- 
Who’s got the sweetest disposition?
One guess, that’s who?
Who’d never, ever start an argument?
Who never shows a bit of temperament?
Who's never wrong but always right?
Who'd never dream of starting a fight?
Who get stuck with all the bad luck?
diff -Naur patch-2.6.1-orig/src/common.h patch-2.6.1/src/common.h
--- patch-2.6.1-orig/src/common.h	2009-12-30 09:56:30.000000000 -0300
+++ patch-2.6.1/src/common.h	2011-10-04 13:25:01.000000000 -0300
@@ -149,6 +149,7 @@
 XTERN int patch_get;
 XTERN bool set_time;
 XTERN bool set_utc;
+XTERN bool interactive_patch;
 
 enum diff
   {
diff -Naur patch-2.6.1-orig/src/patch.c patch-2.6.1/src/patch.c
--- patch-2.6.1-orig/src/patch.c	2009-12-30 09:56:30.000000000 -0300
+++ patch-2.6.1/src/patch.c	2011-10-04 13:45:25.000000000 -0300
@@ -523,7 +523,7 @@
     skip_rest_of_patch = false;
 }
 
-static char const shortopts[] = "bB:cd:D:eEfF:g:i:l"
+static char const shortopts[] = "bB:cd:D:eEfF:g:i:Il"
 #if 0 && defined(ENABLE_MERGE)
 				"m"
 #endif
@@ -536,6 +536,7 @@
   {"context", no_argument, NULL, 'c'},
   {"directory", required_argument, NULL, 'd'},
   {"ifdef", required_argument, NULL, 'D'},
+  {"interactive", no_argument, NULL, 'I'},
   {"ed", no_argument, NULL, 'e'},
   {"remove-empty-files", no_argument, NULL, 'E'},
   {"force", no_argument, NULL, 'f'},
@@ -593,6 +594,8 @@
 "",
 "  -i PATCHFILE  --input=PATCHFILE  Read patch from PATCHFILE instead of stdin.",
 "",
+"  -I  --interactive  Prompt user before applying each hunk.",
+"",
 "Output options:",
 "",
 "  -o FILE  --output=FILE  Output patched files to FILE.",
@@ -732,6 +735,9 @@
 	    case 'i':
 		patchname = savestr (optarg);
 		break;
+	    case 'I':
+		interactive_patch = true;
+		break;
 	    case 'l':
 		canonicalize = true;
 		break;
@@ -1205,6 +1211,21 @@
     register LINENUM pat_end = pch_end ();
     register FILE *fp = outstate->ofp;
 
+    /* Show hunk and ask the user if apply. */
+    if (interactive_patch) {
+      /* Do a fake abort_hunk just for show it on screen. */
+      FILE* tmp_rejfp = rejfp;
+      rejfp = stdout;
+      abort_hunk (true, false);
+      rejfp = tmp_rejfp;
+      say ("\n");
+      ask ( "Apply patch? [y] " );
+      if (*buf == 'n') {
+        say ("\tpatch skipped.\n");
+        return true;
+      }
+    }
+
     where--;
     while (pch_char(new) == '=' || pch_char(new) == '\n')
 	new++;

Reply via email to