Skip to content

Commit 08b1ea4

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 180f48d commit 08b1ea4

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

add-interactive.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ void init_add_i_state(struct add_i_state *s, struct repository *r)
5656
FREE_AND_NULL(s->interactive_diff_filter);
5757
git_config_get_string("interactive.difffilter",
5858
&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);
5963
}
6064

6165
void clear_add_i_state(struct add_i_state *s)
6266
{
6367
FREE_AND_NULL(s->interactive_diff_filter);
68+
FREE_AND_NULL(s->interactive_diff_algorithm);
6469
memset(s, 0, sizeof(*s));
6570
s->use_color = -1;
6671
}

add-interactive.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct add_i_state {
1616
char file_old_color[COLOR_MAXLEN];
1717
char file_new_color[COLOR_MAXLEN];
1818

19-
char *interactive_diff_filter;
19+
char *interactive_diff_filter, *interactive_diff_algorithm;
2020
};
2121

2222
void init_add_i_state(struct add_i_state *s, struct repository *r);

add-patch.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ static int is_octal(const char *p, size_t len)
360360
static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
361361
{
362362
struct argv_array args = ARGV_ARRAY_INIT;
363+
const char *diff_algorithm = s->s.interactive_diff_algorithm;
363364
struct strbuf *plain = &s->plain, *colored = NULL;
364365
struct child_process cp = CHILD_PROCESS_INIT;
365366
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)
369370
int res;
370371

371372
argv_array_pushv(&args, s->mode->diff_cmd);
373+
if (diff_algorithm)
374+
argv_array_pushf(&args, "--diff-algorithm=%s", diff_algorithm);
372375
if (s->revision) {
373376
struct object_id oid;
374377
argv_array_push(&args,

0 commit comments

Comments
 (0)