@matheusbsbs / matheus-bagliano / commits / 08b1ea4c39
Fork 0

built-in add -p: handle diff.algorithm

The Perl version of `git add -p` reads the config setting `diff.algorithm` and if set, uses it to generate the diff using the specified algorithm. This patch ports that functionality to the C version. Note: just like `git-add--interactive.perl`, we do _not_ respect this config setting in `git add -i`'s `diff` command, but _only_ in the `patch` command. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jan 14, 2020 at 18:43 UTC 08b1ea4c39b08b76fe2d1240ccbf6077ef19226a
3 files changed +9 -1
add-interactive.c
+5
@@ -56,11 +56,16 @@ void init_add_i_state(struct add_i_state *s, struct repository *r)
56 FREE_AND_NULL(s->interactive_diff_filter);
57 git_config_get_string("interactive.difffilter",
58 &s->interactive_diff_filter);
59 +
60 + FREE_AND_NULL(s->interactive_diff_algorithm);
61 + git_config_get_string("diff.algorithm",
62 + &s->interactive_diff_algorithm);
63 }
64
65 void clear_add_i_state(struct add_i_state *s)
66 {
67 FREE_AND_NULL(s->interactive_diff_filter);
68 + FREE_AND_NULL(s->interactive_diff_algorithm);
69 memset(s, 0, sizeof(*s));
70 s->use_color = -1;
71 }
add-interactive.h
+1 -1
@@ -16,7 +16,7 @@ struct add_i_state {
16 char file_old_color[COLOR_MAXLEN];
17 char file_new_color[COLOR_MAXLEN];
18
19 - char *interactive_diff_filter;
19 + char *interactive_diff_filter, *interactive_diff_algorithm;
20 };
21
22 void init_add_i_state(struct add_i_state *s, struct repository *r);
add-patch.c
+3
@@ -360,6 +360,7 @@ static int is_octal(const char *p, size_t len)
360 static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
361 {
362 struct argv_array args = ARGV_ARRAY_INIT;
363 + const char *diff_algorithm = s->s.interactive_diff_algorithm;
364 struct strbuf *plain = &s->plain, *colored = NULL;
365 struct child_process cp = CHILD_PROCESS_INIT;
366 char *p, *pend, *colored_p = NULL, *colored_pend = NULL, marker = '\0';
@@ -369,6 +370,8 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
370 int res;
371
372 argv_array_pushv(&args, s->mode->diff_cmd);
373 + if (diff_algorithm)
374 + argv_array_pushf(&args, "--diff-algorithm=%s", diff_algorithm);
375 if (s->revision) {
376 struct object_id oid;
377 argv_array_push(&args,