Teach diff machinery to display other prefixes than "a/" and "b/"
With the new options "--src-prefix=<prefix>", "--dst-prefix=<prefix>" and "--no-prefix", you can now control the path prefixes of the diff machinery. These used to by hardwired to "a/" for the source prefix and "b/" for the destination prefix. Initial patch by Pascal Obry. Sane option names suggested by Linus. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
74f6b03c5c
commit
eab9a40b6d
@ -211,5 +211,14 @@ endif::git-format-patch[]
|
|||||||
--no-ext-diff::
|
--no-ext-diff::
|
||||||
Disallow external diff drivers.
|
Disallow external diff drivers.
|
||||||
|
|
||||||
|
--src-prefix=<prefix>::
|
||||||
|
Show the given source prefix instead of "a/".
|
||||||
|
|
||||||
|
--dst-prefix=<prefix>::
|
||||||
|
Show the given destination prefix instead of "b/".
|
||||||
|
|
||||||
|
--no-prefix::
|
||||||
|
Do not show any source or destination prefix.
|
||||||
|
|
||||||
For more detailed explanation on these common options, see also
|
For more detailed explanation on these common options, see also
|
||||||
link:diffcore.html[diffcore documentation].
|
link:diffcore.html[diffcore documentation].
|
||||||
|
25
diff.c
25
diff.c
@ -290,9 +290,10 @@ static void emit_rewrite_diff(const char *name_a,
|
|||||||
const char *name_b,
|
const char *name_b,
|
||||||
struct diff_filespec *one,
|
struct diff_filespec *one,
|
||||||
struct diff_filespec *two,
|
struct diff_filespec *two,
|
||||||
int color_diff)
|
struct diff_options *o)
|
||||||
{
|
{
|
||||||
int lc_a, lc_b;
|
int lc_a, lc_b;
|
||||||
|
int color_diff = DIFF_OPT_TST(o, COLOR_DIFF);
|
||||||
const char *name_a_tab, *name_b_tab;
|
const char *name_a_tab, *name_b_tab;
|
||||||
const char *metainfo = diff_get_color(color_diff, DIFF_METAINFO);
|
const char *metainfo = diff_get_color(color_diff, DIFF_METAINFO);
|
||||||
const char *fraginfo = diff_get_color(color_diff, DIFF_FRAGINFO);
|
const char *fraginfo = diff_get_color(color_diff, DIFF_FRAGINFO);
|
||||||
@ -309,9 +310,9 @@ static void emit_rewrite_diff(const char *name_a,
|
|||||||
diff_populate_filespec(two, 0);
|
diff_populate_filespec(two, 0);
|
||||||
lc_a = count_lines(one->data, one->size);
|
lc_a = count_lines(one->data, one->size);
|
||||||
lc_b = count_lines(two->data, two->size);
|
lc_b = count_lines(two->data, two->size);
|
||||||
printf("%s--- a/%s%s%s\n%s+++ b/%s%s%s\n%s@@ -",
|
printf("%s--- %s%s%s%s\n%s+++ %s%s%s%s\n%s@@ -",
|
||||||
metainfo, name_a, name_a_tab, reset,
|
metainfo, o->a_prefix, name_a, name_a_tab, reset,
|
||||||
metainfo, name_b, name_b_tab, reset, fraginfo);
|
metainfo, o->b_prefix, name_b, name_b_tab, reset, fraginfo);
|
||||||
print_line_count(lc_a);
|
print_line_count(lc_a);
|
||||||
printf(" +");
|
printf(" +");
|
||||||
print_line_count(lc_b);
|
print_line_count(lc_b);
|
||||||
@ -1212,8 +1213,8 @@ static void builtin_diff(const char *name_a,
|
|||||||
const char *set = diff_get_color_opt(o, DIFF_METAINFO);
|
const char *set = diff_get_color_opt(o, DIFF_METAINFO);
|
||||||
const char *reset = diff_get_color_opt(o, DIFF_RESET);
|
const char *reset = diff_get_color_opt(o, DIFF_RESET);
|
||||||
|
|
||||||
a_one = quote_two("a/", name_a + (*name_a == '/'));
|
a_one = quote_two(o->a_prefix, name_a + (*name_a == '/'));
|
||||||
b_two = quote_two("b/", name_b + (*name_b == '/'));
|
b_two = quote_two(o->b_prefix, name_b + (*name_b == '/'));
|
||||||
lbl[0] = DIFF_FILE_VALID(one) ? a_one : "/dev/null";
|
lbl[0] = DIFF_FILE_VALID(one) ? a_one : "/dev/null";
|
||||||
lbl[1] = DIFF_FILE_VALID(two) ? b_two : "/dev/null";
|
lbl[1] = DIFF_FILE_VALID(two) ? b_two : "/dev/null";
|
||||||
printf("%sdiff --git %s %s%s\n", set, a_one, b_two, reset);
|
printf("%sdiff --git %s %s%s\n", set, a_one, b_two, reset);
|
||||||
@ -1242,8 +1243,7 @@ static void builtin_diff(const char *name_a,
|
|||||||
if ((one->mode ^ two->mode) & S_IFMT)
|
if ((one->mode ^ two->mode) & S_IFMT)
|
||||||
goto free_ab_and_return;
|
goto free_ab_and_return;
|
||||||
if (complete_rewrite) {
|
if (complete_rewrite) {
|
||||||
emit_rewrite_diff(name_a, name_b, one, two,
|
emit_rewrite_diff(name_a, name_b, one, two, o);
|
||||||
DIFF_OPT_TST(o, COLOR_DIFF));
|
|
||||||
o->found_changes = 1;
|
o->found_changes = 1;
|
||||||
goto free_ab_and_return;
|
goto free_ab_and_return;
|
||||||
}
|
}
|
||||||
@ -2020,6 +2020,9 @@ void diff_setup(struct diff_options *options)
|
|||||||
else
|
else
|
||||||
DIFF_OPT_CLR(options, COLOR_DIFF);
|
DIFF_OPT_CLR(options, COLOR_DIFF);
|
||||||
options->detect_rename = diff_detect_rename_default;
|
options->detect_rename = diff_detect_rename_default;
|
||||||
|
|
||||||
|
options->a_prefix = "a/";
|
||||||
|
options->b_prefix = "b/";
|
||||||
}
|
}
|
||||||
|
|
||||||
int diff_setup_done(struct diff_options *options)
|
int diff_setup_done(struct diff_options *options)
|
||||||
@ -2291,6 +2294,12 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
|
|||||||
else if (40 < options->abbrev)
|
else if (40 < options->abbrev)
|
||||||
options->abbrev = 40;
|
options->abbrev = 40;
|
||||||
}
|
}
|
||||||
|
else if (!prefixcmp(arg, "--src-prefix="))
|
||||||
|
options->a_prefix = arg + 13;
|
||||||
|
else if (!prefixcmp(arg, "--dst-prefix="))
|
||||||
|
options->b_prefix = arg + 13;
|
||||||
|
else if (!strcmp(arg, "--no-prefix"))
|
||||||
|
options->a_prefix = options->b_prefix = "";
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
|
1
diff.h
1
diff.h
@ -69,6 +69,7 @@ struct diff_options {
|
|||||||
const char *orderfile;
|
const char *orderfile;
|
||||||
const char *pickaxe;
|
const char *pickaxe;
|
||||||
const char *single_follow;
|
const char *single_follow;
|
||||||
|
const char *a_prefix, *b_prefix;
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
int context;
|
int context;
|
||||||
int break_opt;
|
int break_opt;
|
||||||
|
Loading…
Reference in New Issue
Block a user