forked from pool/patch
106 lines
3.3 KiB
Diff
106 lines
3.3 KiB
Diff
---
|
|
common.h | 2 ++
|
|
merge.c | 8 ++++----
|
|
patch.c | 14 +++++++++++++-
|
|
3 files changed, 19 insertions(+), 5 deletions(-)
|
|
|
|
Index: b/common.h
|
|
===================================================================
|
|
--- a/common.h
|
|
+++ b/common.h
|
|
@@ -310,6 +310,8 @@ XTERN LINENUM last_offset;
|
|
/* how many input lines have been irretractably output */
|
|
XTERN LINENUM last_frozen_line;
|
|
|
|
+XTERN const char *file_label[2];
|
|
+
|
|
bool similar (char const *, size_t, char const *, size_t);
|
|
bool copy_till (struct outstate *, LINENUM);
|
|
|
|
Index: b/patch.c
|
|
===================================================================
|
|
--- a/patch.c
|
|
+++ b/patch.c
|
|
@@ -70,6 +70,8 @@ static void usage (FILE *, int) __attrib
|
|
static void (*abort_hunk) (bool, bool) = abort_hunk_context;
|
|
|
|
static bool merge;
|
|
+const char *file_label[2];
|
|
+
|
|
static bool make_backups;
|
|
static bool backup_if_mismatch;
|
|
static char const *version_control;
|
|
@@ -506,7 +508,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'},
|
|
@@ -521,6 +523,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'},
|
|
{"merge", no_argument, NULL, 'M'},
|
|
{"normal", no_argument, NULL, 'n'},
|
|
{"forward", no_argument, NULL, 'N'},
|
|
@@ -577,6 +580,7 @@ static char const *const option_help[] =
|
|
"",
|
|
" -D NAME --ifdef=NAME Make merged if-then-else output using NAME.",
|
|
" -M --merge Produce a diff3-style merge for rejects.",
|
|
+" -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).",
|
|
@@ -718,6 +722,14 @@ get_some_switches (void)
|
|
case 'M':
|
|
merge = 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 'n':
|
|
diff_type = NORMAL_DIFF;
|
|
break;
|
|
Index: b/merge.c
|
|
===================================================================
|
|
--- a/merge.c
|
|
+++ b/merge.c
|
|
@@ -50,7 +50,7 @@ merge_hunk (struct outstate *outstate)
|
|
return false;
|
|
|
|
/* "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",
|
|
@@ -84,7 +84,7 @@ merge_hunk (struct outstate *outstate)
|
|
if (! same_result)
|
|
{
|
|
/* "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",
|
|
@@ -112,8 +112,8 @@ merge_hunk (struct outstate *outstate)
|
|
result with the new file's name. */
|
|
if (same_result)
|
|
{
|
|
- name = pch_name(NEW);
|
|
- if (!name)
|
|
+ name = file_label[NEW] ? file_label[NEW] : pch_name(NEW);
|
|
+ if (! name)
|
|
name = "";
|
|
}
|
|
else
|