自动构建和先前应用的补丁

Automated build and previously applied patches

当检测到之前应用的补丁时,我如何防止构建中止:

补丁本身能够识别以前应用的补丁。必须有一种方法来避免以前应用的补丁的非零退出状态,对吗?

这行不通:

yes 'n' | patch -p<w/e> -i <w/e>

因为补丁从 /dev/tty(我猜)而不是标准输入读取。即使它确实从 stdin 读取,它仍然给出 1 的退出状态。

我好像漏掉了什么。我不是第一个 运行 遇到这个问题的人。

我想我可能刚刚解决了我的问题。

diff --git a/src/common.h b/src/common.h
index 9e355fe..e1b1555 100644
--- a/src/common.h
+++ b/src/common.h
@@ -108,8 +108,10 @@ XTERN bool force;
 XTERN bool batch;
 XTERN bool noreverse;
 XTERN bool reverse;
+XTERN bool applied;
 XTERN enum { DEFAULT_VERBOSITY, SILENT, VERBOSE } verbosity;
 XTERN bool skip_rest_of_patch;
+XTERN bool applied_is_cause;
 XTERN int strippath;
 XTERN bool canonicalize;
 XTERN int patch_get;
diff --git a/src/patch.c b/src/patch.c
index a60e631..3d375b3 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -613,7 +613,8 @@ main (int argc, char **argv)
        if (fstat (fileno (rejfp), &rejst) != 0 || fclose (rejfp) != 0)
          write_fatal ();
        rejfp = NULL;
-       somefailed = true;
+       if (! somefailed && ! (applied && applied_is_cause))
+         somefailed = true;
        say ("%d out of %d hunk%s %s", failed, hunk, "s" + (hunk == 1),
         skip_rest_of_patch ? "ignored" : "FAILED");
        if (outname && (! rejname || strcmp (rejname, "-") != 0)) {
@@ -629,7 +630,7 @@ main (int argc, char **argv)
              rej[len - 1] = '#';
            simple_backup_suffix = s;
        }
-       if (! dry_run)
+       if (! dry_run && ! (applied && applied_is_cause))
          {
            say (" -- saving rejects to file %s\n", quotearg (rej));
            if (rejname)
@@ -706,9 +707,10 @@ reinitialize_almost_everything (void)

     reverse = reverse_flag_specified;
     skip_rest_of_patch = false;
+    applied_is_cause = false;
 }

-static char const shortopts[] = "bB:cd:D:eEfF:g:i:l"
+static char const shortopts[] = "abB:cd:D:eEfF:g:i:l"
 #if 0 && defined ENABLE_MERGE
                "m"
 #endif
@@ -716,6 +718,7 @@ static char const shortopts[] = "bB:cd:D:eEfF:g:i:l"

 static struct option const longopts[] =
 {
+  {"applied", no_argument, NULL, 'a'},
   {"backup", no_argument, NULL, 'b'},
   {"prefix", required_argument, NULL, 'B'},
   {"context", no_argument, NULL, 'c'},
@@ -777,6 +780,7 @@ static char const *const option_help[] =
 "",
 "  -N  --forward  Ignore patches that appear to be reversed or already applied.",
 "  -R  --reverse  Assume patches were created with old and new files swapped.",
+"  -a  --applied  Ignore error and save no rejects on applied or reversed patch.",
 "",
 "  -i PATCHFILE  --input=PATCHFILE  Read patch from PATCHFILE instead of stdin.",
 "",
@@ -869,6 +873,9 @@ get_some_switches (void)
     while ((optc = getopt_long (Argc, Argv, shortopts, longopts, (int *) 0))
       != -1) {
    switch (optc) {
+       case 'a':
+       applied = true;
+       break;
        case 'b':
        make_backups = true;
         /* Special hack for backward compatibility with CVS 1.9.
diff --git a/src/util.c b/src/util.c
index ee88c13..432bc5c 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1056,6 +1056,7 @@ ok_to_reverse (char const *format, ...)
     {
       say ("  Skipping patch.\n");
       skip_rest_of_patch = true;
+      applied_is_cause = true;
     }
   else if (force)
     {
@@ -1079,6 +1080,7 @@ ok_to_reverse (char const *format, ...)
          if (verbosity != SILENT)
        say ("Skipping patch.\n");
          skip_rest_of_patch = true;
+         applied_is_cause = true;
            }
        }
         }