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>

Nguyễn Thái Ngọc Duy committed Mar 24, 2019 at 15:20 UTC cdb5330a9baa64c28473fb0f446ca2242d6971fb
3 files changed +10 -2
builtin/am.c
+2 -2
@@ -1515,11 +1515,11 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa
1515 * review them with extra care to spot mismerges.
1516 */
1517 struct rev_info rev_info;
1518 - const char *diff_filter_str = "--diff-filter=AM";
1518
1519 repo_init_revisions(the_repository, &rev_info, NULL);
1520 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');
1523 add_pending_oid(&rev_info, "HEAD", &our_tree, 0);
1524 diff_setup_done(&rev_info.diffopt);
1525 run_diff_index(&rev_info, 1);
diff.c
+6
@@ -4692,6 +4692,12 @@ static unsigned filter_bit_tst(char status, const struct diff_options *opt)
4692 return opt->filter & filter_bit[(int) status];
4693 }
4694
4695 +unsigned diff_filter_bit(char status)
4696 +{
4697 + prepare_filter_bits();
4698 + return filter_bit[(int) status];
4699 +}
4700 +
4701 static int diff_opt_diff_filter(const struct option *option,
4702 const char *optarg, int unset)
4703 {
diff.h
+2
@@ -233,6 +233,8 @@ struct diff_options {
233 struct option *parseopts;
234 };
235
236 +unsigned diff_filter_bit(char status);
237 +
238 void diff_emit_submodule_del(struct diff_options *o, const char *line);
239 void diff_emit_submodule_add(struct diff_options *o, const char *line);
240 void diff_emit_submodule_untracked(struct diff_options *o, const char *path);