diff.c: move the diff filter bits definitions up a bit

This prepares for a more careful handling of the `--diff-filter` options over the next few commits. This commit is best viewed with `--color-moved`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jan 28, 2022 at 12:02 UTC 4d4d4eaa7b7f7ceda0648273ad33b71fc68e36c1
1 file changed +37 -37
diff.c
+37 -37
@@ -4570,6 +4570,43 @@ void repo_diff_setup(struct repository *r, struct diff_options *options)
4570 prep_parse_options(options);
4571 }
4572
4573 +static const char diff_status_letters[] = {
4574 + DIFF_STATUS_ADDED,
4575 + DIFF_STATUS_COPIED,
4576 + DIFF_STATUS_DELETED,
4577 + DIFF_STATUS_MODIFIED,
4578 + DIFF_STATUS_RENAMED,
4579 + DIFF_STATUS_TYPE_CHANGED,
4580 + DIFF_STATUS_UNKNOWN,
4581 + DIFF_STATUS_UNMERGED,
4582 + DIFF_STATUS_FILTER_AON,
4583 + DIFF_STATUS_FILTER_BROKEN,
4584 + '\0',
4585 +};
4586 +
4587 +static unsigned int filter_bit['Z' + 1];
4588 +
4589 +static void prepare_filter_bits(void)
4590 +{
4591 + int i;
4592 +
4593 + if (!filter_bit[DIFF_STATUS_ADDED]) {
4594 + for (i = 0; diff_status_letters[i]; i++)
4595 + filter_bit[(int) diff_status_letters[i]] = (1 << i);
4596 + }
4597 +}
4598 +
4599 +static unsigned filter_bit_tst(char status, const struct diff_options *opt)
4600 +{
4601 + return opt->filter & filter_bit[(int) status];
4602 +}
4603 +
4604 +unsigned diff_filter_bit(char status)
4605 +{
4606 + prepare_filter_bits();
4607 + return filter_bit[(int) status];
4608 +}
4609 +
4610 void diff_setup_done(struct diff_options *options)
4611 {
4612 unsigned check_mask = DIFF_FORMAT_NAME |
@@ -4774,43 +4811,6 @@ static int parse_dirstat_opt(struct diff_options *options, const char *params)
4811 return 1;
4812 }
4813
4777 -static const char diff_status_letters[] = {
4778 - DIFF_STATUS_ADDED,
4779 - DIFF_STATUS_COPIED,
4780 - DIFF_STATUS_DELETED,
4781 - DIFF_STATUS_MODIFIED,
4782 - DIFF_STATUS_RENAMED,
4783 - DIFF_STATUS_TYPE_CHANGED,
4784 - DIFF_STATUS_UNKNOWN,
4785 - DIFF_STATUS_UNMERGED,
4786 - DIFF_STATUS_FILTER_AON,
4787 - DIFF_STATUS_FILTER_BROKEN,
4788 - '\0',
4789 -};
4790 -
4791 -static unsigned int filter_bit['Z' + 1];
4792 -
4793 -static void prepare_filter_bits(void)
4794 -{
4795 - int i;
4796 -
4797 - if (!filter_bit[DIFF_STATUS_ADDED]) {
4798 - for (i = 0; diff_status_letters[i]; i++)
4799 - filter_bit[(int) diff_status_letters[i]] = (1 << i);
4800 - }
4801 -}
4802 -
4803 -static unsigned filter_bit_tst(char status, const struct diff_options *opt)
4804 -{
4805 - return opt->filter & filter_bit[(int) status];
4806 -}
4807 -
4808 -unsigned diff_filter_bit(char status)
4809 -{
4810 - prepare_filter_bits();
4811 - return filter_bit[(int) status];
4812 -}
4813 -
4814 static int diff_opt_diff_filter(const struct option *option,
4815 const char *optarg, int unset)
4816 {