Skip to content

Commit cdb5330

Browse files
pcloudsgitster
authored andcommitted
am: avoid diff_opt_parse()
diff_opt_parse() is a heavy hammer to just set diff filter. But it's the only way because of the diff_status_letters[] mapping. Add a new API to set diff filter and use it in git-am. diff_opt_parse()'s only remaining call site in revision.c will be gone soon and having it here just because of git-am does not make sense. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 16bb3d7 commit cdb5330

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

builtin/am.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,11 +1515,11 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
15151515
* review them with extra care to spot mismerges.
15161516
*/
15171517
struct rev_info rev_info;
1518-
const char *diff_filter_str = "--diff-filter=AM";
15191518

15201519
repo_init_revisions(the_repository, &rev_info, NULL);
15211520
rev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS;
1522-
diff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1, rev_info.prefix);
1521+
rev_info.diffopt.filter |= diff_filter_bit('A');
1522+
rev_info.diffopt.filter |= diff_filter_bit('M');
15231523
add_pending_oid(&rev_info, "HEAD", &our_tree, 0);
15241524
diff_setup_done(&rev_info.diffopt);
15251525
run_diff_index(&rev_info, 1);

diff.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4692,6 +4692,12 @@ static unsigned filter_bit_tst(char status, const struct diff_options *opt)
46924692
return opt->filter & filter_bit[(int) status];
46934693
}
46944694

4695+
unsigned diff_filter_bit(char status)
4696+
{
4697+
prepare_filter_bits();
4698+
return filter_bit[(int) status];
4699+
}
4700+
46954701
static int diff_opt_diff_filter(const struct option *option,
46964702
const char *optarg, int unset)
46974703
{

diff.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ struct diff_options {
233233
struct option *parseopts;
234234
};
235235

236+
unsigned diff_filter_bit(char status);
237+
236238
void diff_emit_submodule_del(struct diff_options *o, const char *line);
237239
void diff_emit_submodule_add(struct diff_options *o, const char *line);
238240
void diff_emit_submodule_untracked(struct diff_options *o, const char *path);

0 commit comments

Comments
 (0)