forked from pool/patch
93 lines
3.2 KiB
Diff
93 lines
3.2 KiB
Diff
|
From: Andreas Gruenbacher <agruen@suse.de>
|
||
|
Subject: diff3-style merges: add file labels
|
||
|
|
||
|
Add a --label=LABEL option for overriding the labels in the diff3-style
|
||
|
format. The option can be given up to three times for overriding the
|
||
|
old, new, and output filename.
|
||
|
|
||
|
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
|
||
|
|
||
|
---
|
||
|
patch.c | 19 +++++++++++++++----
|
||
|
1 file changed, 15 insertions(+), 4 deletions(-)
|
||
|
|
||
|
Index: b/patch.c
|
||
|
===================================================================
|
||
|
--- a/patch.c
|
||
|
+++ b/patch.c
|
||
|
@@ -82,6 +82,7 @@ static void usage (FILE *, int) __attrib
|
||
|
enum mergetype { SHOW_ALL = 1, SHOW_FUZZ = 2, MERGE_REJECTS = 4 };
|
||
|
static enum mergetype mergetype;
|
||
|
|
||
|
+const char *file_label[2];
|
||
|
static bool make_backups;
|
||
|
static bool backup_if_mismatch;
|
||
|
static char const *version_control;
|
||
|
@@ -538,7 +539,7 @@ reinitialize_almost_everything (void)
|
||
|
skip_rest_of_patch = false;
|
||
|
}
|
||
|
|
||
|
-static char const shortopts[] = "bB:cd:D:eEfF:g:i:lMnNo:p:r:RstTuvV:x:Y:z:Z";
|
||
|
+static char const shortopts[] = "bB:cd:D:eEfF:g:i:lL:MnNo:p:r:RstTuvV:x:Y:z:Z";
|
||
|
static struct option const longopts[] =
|
||
|
{
|
||
|
{"backup", no_argument, NULL, 'b'},
|
||
|
@@ -553,6 +554,7 @@ static struct option const longopts[] =
|
||
|
{"get", no_argument, NULL, 'g'},
|
||
|
{"input", required_argument, NULL, 'i'},
|
||
|
{"ignore-whitespace", no_argument, NULL, 'l'},
|
||
|
+ {"label", required_argument, NULL, 'L'},
|
||
|
{"normal", no_argument, NULL, 'n'},
|
||
|
{"forward", no_argument, NULL, 'N'},
|
||
|
{"output", required_argument, NULL, 'o'},
|
||
|
@@ -609,6 +611,7 @@ static char const *const option_help[] =
|
||
|
"",
|
||
|
" -D NAME --ifdef=NAME Make merged if-then-else output using NAME.",
|
||
|
" --merge={rejects,fuzz,all} Produce a diff3-style merge.",
|
||
|
+" -L LABEL --label=LABEL Use LABEL instead of file name in merge.",
|
||
|
" -E --remove-empty-files Remove output files that are empty after patching.",
|
||
|
"",
|
||
|
" -Z --set-utc Set times of patched files, assuming diff uses UTC (GMT).",
|
||
|
@@ -747,6 +750,14 @@ get_some_switches (void)
|
||
|
case 'l':
|
||
|
canonicalize = true;
|
||
|
break;
|
||
|
+ case 'L':
|
||
|
+ if (!file_label[0])
|
||
|
+ file_label[0] = optarg;
|
||
|
+ else if (!file_label[1])
|
||
|
+ file_label[1] = optarg;
|
||
|
+ else
|
||
|
+ fatal ("too many file label options");
|
||
|
+ break;
|
||
|
case 'M':
|
||
|
mergetype |= MERGE_REJECTS;
|
||
|
break;
|
||
|
@@ -1411,7 +1422,7 @@ static bool merge_hunk (struct outstate
|
||
|
}
|
||
|
|
||
|
/* "From" lines in the patch */
|
||
|
- name = pch_name(OLD);
|
||
|
+ name = file_label[OLD] ? file_label[OLD] : pch_name(OLD);
|
||
|
if (!name)
|
||
|
name = "";
|
||
|
fprintf(fp, outstate->after_newline + "\n<<<<<<<%*s\n",
|
||
|
@@ -1426,7 +1437,7 @@ static bool merge_hunk (struct outstate
|
||
|
|
||
|
if (fuzz) {
|
||
|
/* "To" lines in the patch */
|
||
|
- name = pch_name(NEW);
|
||
|
+ name = file_label[NEW] ? file_label[NEW] : pch_name(NEW);
|
||
|
if (!name)
|
||
|
name = "";
|
||
|
fprintf(fp, outstate->after_newline + "\n|||||||%*s\n",
|
||
|
@@ -1453,7 +1464,7 @@ static bool merge_hunk (struct outstate
|
||
|
|
||
|
/* If the merge result and the new file are the same, label the merge
|
||
|
result with the new file's name. */
|
||
|
- name = fuzz ? NULL : pch_name(NEW);
|
||
|
+ name = fuzz ? NULL : (file_label[NEW] ? file_label[NEW] : pch_name(NEW));
|
||
|
if (!name)
|
||
|
name = "";
|
||
|
fprintf(fp, outstate->after_newline + "\n>>>>>>>%*s\n",
|