@matheusbsbs / matheus-bagliano / commits / eab9a40b6d
Fork 0

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>

Johannes Schindelin committed Dec 18, 2007 at 19:32 UTC eab9a40b6dd5c1c571b1deb264133db47bb4794d
3 files changed +27 -8
Documentation/diff-options.txt
+9
@@ -211,5 +211,14 @@ endif::git-format-patch[]
211 --no-ext-diff::
212 Disallow external diff drivers.
213
214 +--src-prefix=<prefix>::
215 + Show the given source prefix instead of "a/".
216 +
217 +--dst-prefix=<prefix>::
218 + Show the given destination prefix instead of "b/".
219 +
220 +--no-prefix::
221 + Do not show any source or destination prefix.
222 +
223 For more detailed explanation on these common options, see also
224 link:diffcore.html[diffcore documentation].
diff.c
+17 -8
@@ -290,9 +290,10 @@ static void emit_rewrite_diff(const char *name_a,
290 const char *name_b,
291 struct diff_filespec *one,
292 struct diff_filespec *two,
293 - int color_diff)
293 + struct diff_options *o)
294 {
295 int lc_a, lc_b;
296 + int color_diff = DIFF_OPT_TST(o, COLOR_DIFF);
297 const char *name_a_tab, *name_b_tab;
298 const char *metainfo = diff_get_color(color_diff, DIFF_METAINFO);
299 const char *fraginfo = diff_get_color(color_diff, DIFF_FRAGINFO);
@@ -309,9 +310,9 @@ static void emit_rewrite_diff(const char *name_a,
310 diff_populate_filespec(two, 0);
311 lc_a = count_lines(one->data, one->size);
312 lc_b = count_lines(two->data, two->size);
312 - printf("%s--- a/%s%s%s\n%s+++ b/%s%s%s\n%s@@ -",
313 - metainfo, name_a, name_a_tab, reset,
314 - metainfo, name_b, name_b_tab, reset, fraginfo);
313 + printf("%s--- %s%s%s%s\n%s+++ %s%s%s%s\n%s@@ -",
314 + metainfo, o->a_prefix, name_a, name_a_tab, reset,
315 + metainfo, o->b_prefix, name_b, name_b_tab, reset, fraginfo);
316 print_line_count(lc_a);
317 printf(" +");
318 print_line_count(lc_b);
@@ -1212,8 +1213,8 @@ static void builtin_diff(const char *name_a,
1213 const char *set = diff_get_color_opt(o, DIFF_METAINFO);
1214 const char *reset = diff_get_color_opt(o, DIFF_RESET);
1215
1215 - a_one = quote_two("a/", name_a + (*name_a == '/'));
1216 - b_two = quote_two("b/", name_b + (*name_b == '/'));
1216 + a_one = quote_two(o->a_prefix, name_a + (*name_a == '/'));
1217 + b_two = quote_two(o->b_prefix, name_b + (*name_b == '/'));
1218 lbl[0] = DIFF_FILE_VALID(one) ? a_one : "/dev/null";
1219 lbl[1] = DIFF_FILE_VALID(two) ? b_two : "/dev/null";
1220 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,
1243 if ((one->mode ^ two->mode) & S_IFMT)
1244 goto free_ab_and_return;
1245 if (complete_rewrite) {
1245 - emit_rewrite_diff(name_a, name_b, one, two,
1246 - DIFF_OPT_TST(o, COLOR_DIFF));
1246 + emit_rewrite_diff(name_a, name_b, one, two, o);
1247 o->found_changes = 1;
1248 goto free_ab_and_return;
1249 }
@@ -2020,6 +2020,9 @@ void diff_setup(struct diff_options *options)
2020 else
2021 DIFF_OPT_CLR(options, COLOR_DIFF);
2022 options->detect_rename = diff_detect_rename_default;
2023 +
2024 + options->a_prefix = "a/";
2025 + options->b_prefix = "b/";
2026 }
2027
2028 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)
2294 else if (40 < options->abbrev)
2295 options->abbrev = 40;
2296 }
2297 + else if (!prefixcmp(arg, "--src-prefix="))
2298 + options->a_prefix = arg + 13;
2299 + else if (!prefixcmp(arg, "--dst-prefix="))
2300 + options->b_prefix = arg + 13;
2301 + else if (!strcmp(arg, "--no-prefix"))
2302 + options->a_prefix = options->b_prefix = "";
2303 else
2304 return 0;
2305 return 1;
diff.h
+1
@@ -69,6 +69,7 @@ struct diff_options {
69 const char *orderfile;
70 const char *pickaxe;
71 const char *single_follow;
72 + const char *a_prefix, *b_prefix;
73 unsigned flags;
74 int context;
75 int break_opt;