diff options
author | Jeff King <peff@peff.net> | 2023-06-01 20:41:06 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-06-03 04:34:25 +0300 |
commit | 9eac5954e81037f282ace2efff7110af3440dc19 (patch) | |
tree | ea75389ce1c5dad909ab1488171bfdf7f9ff0f48 /diff.c | |
parent | 8e32caaa783a3a6b1d94834ee6e2d21ac36ff39f (diff) |
diff: factor out --follow pathspec check
In --follow mode, we require exactly one pathspec. We check this
condition in two places:
- in diff_setup_done(), we complain if --follow is used with an
inapropriate pathspec
- in git-log's revision "tweak" function, we enable log.follow only if
the pathspec allows it
The duplication isn't a big deal right now, since the logic is so
simple. But in preparation for it becoming more complex, let's pull it
into a shared function.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -4721,6 +4721,16 @@ unsigned diff_filter_bit(char status) return filter_bit[(int) status]; } +int diff_check_follow_pathspec(struct pathspec *ps, int die_on_error) +{ + if (ps->nr != 1) { + if (die_on_error) + die(_("--follow requires exactly one pathspec")); + return 0; + } + return 1; +} + void diff_setup_done(struct diff_options *options) { unsigned check_mask = DIFF_FORMAT_NAME | @@ -4828,8 +4838,8 @@ void diff_setup_done(struct diff_options *options) options->diff_path_counter = 0; - if (options->flags.follow_renames && options->pathspec.nr != 1) - die(_("--follow requires exactly one pathspec")); + if (options->flags.follow_renames) + diff_check_follow_pathspec(&options->pathspec, 1); if (!options->use_color || external_diff()) options->color_moved = 0; |