diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-08-21 01:33:19 +0400 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-08-21 01:33:19 +0400 |
commit | d7874ed1d498454b3c7342f9e6df0aacb9873186 (patch) | |
tree | 424e75417b35ccd42cfcfb6ce9c0e519f8dd9c2f | |
parent | 0793491ff884bbb70b51c2b05c42d5dad60bcc5f (diff) |
patch: support -N. By Olivier Duclos (olivier.duclos AT gmail.com)
function old new delta
packed_usage 26646 26656 +10
patch_main 1101 1110 +9
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/patch.c | 12 | ||||
-rw-r--r-- | include/usage.h | 3 |
2 files changed, 13 insertions, 2 deletions
diff --git a/editors/patch.c b/editors/patch.c index e8482a7a9..4a9715144 100644 --- a/editors/patch.c +++ b/editors/patch.c @@ -74,12 +74,18 @@ int patch_main(int argc UNUSED_PARAM, char **argv) int patch_level; int ret = 0; char plus = '+'; + unsigned opt; + enum { + OPT_R = (1 << 2), + OPT_N = (1 << 3), + }; xfunc_error_retval = 2; { const char *p = "-1"; const char *i = "-"; /* compat */ - if (getopt32(argv, "p:i:R", &p, &i) & 4) + opt = getopt32(argv, "p:i:RN", &p, &i); + if (opt & OPT_R) plus = '-'; patch_level = xatoi(p); /* can be negative! */ patch_file = xfopen_stdin(i); @@ -202,6 +208,10 @@ int patch_main(int argc UNUSED_PARAM, char **argv) src_line = NULL; } } + /* Do not patch an already patched hunk with -N */ + if (src_line == 0 && (opt & OPT_N)) { + continue; + } if (!src_line) { bb_error_msg("hunk #%u FAILED at %u", hunk_count, hunk_offset_start); bad_hunk_count++; diff --git a/include/usage.h b/include/usage.h index accda3341..81ddbd23c 100644 --- a/include/usage.h +++ b/include/usage.h @@ -3218,11 +3218,12 @@ ) #define patch_trivial_usage \ - "[-p NUM] [-i DIFF] [-R]" + "[-p NUM] [-i DIFF] [-R] [-N]" #define patch_full_usage "\n\n" \ " -p NUM Strip NUM leading components from file names" \ "\n -i DIFF Read DIFF instead of stdin" \ "\n -R Reverse patch" \ + "\n -N Ignore already applied patches" \ #define patch_example_usage \ "$ patch -p1 < example.diff\n" \ |