]> git.ipfire.org Git - thirdparty/git.git/commitdiff
built-in add -p: handle diff.algorithm
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Tue, 14 Jan 2020 18:43:46 +0000 (18:43 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Jan 2020 20:06:16 +0000 (12:06 -0800)
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>
add-interactive.c
add-interactive.h
add-patch.c

index 1786ea29c49f8eebe598c819a578eb4a39b0f8b0..9e4bcb382c527855cb29a5bd4c8f4eb0bc3e9154 100644 (file)
@@ -56,11 +56,16 @@ void init_add_i_state(struct add_i_state *s, struct repository *r)
        FREE_AND_NULL(s->interactive_diff_filter);
        git_config_get_string("interactive.difffilter",
                              &s->interactive_diff_filter);
+
+       FREE_AND_NULL(s->interactive_diff_algorithm);
+       git_config_get_string("diff.algorithm",
+                             &s->interactive_diff_algorithm);
 }
 
 void clear_add_i_state(struct add_i_state *s)
 {
        FREE_AND_NULL(s->interactive_diff_filter);
+       FREE_AND_NULL(s->interactive_diff_algorithm);
        memset(s, 0, sizeof(*s));
        s->use_color = -1;
 }
index 46c73867adda2c9a3b0f0faac111fa38d0356e77..923efaf52718e617ce48b7d4e6d294f5de2ebc13 100644 (file)
@@ -16,7 +16,7 @@ struct add_i_state {
        char file_old_color[COLOR_MAXLEN];
        char file_new_color[COLOR_MAXLEN];
 
-       char *interactive_diff_filter;
+       char *interactive_diff_filter, *interactive_diff_algorithm;
 };
 
 void init_add_i_state(struct add_i_state *s, struct repository *r);
index 78bde41df075b650746843db5a8b80cea1415906..8f2ee8688b5fed4769333fbd8e60cf0fcee95904 100644 (file)
@@ -360,6 +360,7 @@ static int is_octal(const char *p, size_t len)
 static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
 {
        struct argv_array args = ARGV_ARRAY_INIT;
+       const char *diff_algorithm = s->s.interactive_diff_algorithm;
        struct strbuf *plain = &s->plain, *colored = NULL;
        struct child_process cp = CHILD_PROCESS_INIT;
        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)
        int res;
 
        argv_array_pushv(&args, s->mode->diff_cmd);
+       if (diff_algorithm)
+               argv_array_pushf(&args, "--diff-algorithm=%s", diff_algorithm);
        if (s->revision) {
                struct object_id oid;
                argv_array_push(&args,