diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-06-20 22:53:13 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-06-20 22:53:13 (GMT) |
commit | de00f4b7f3fd3aca18e4bea286bf060c595efd3b (patch) | |
tree | 48131ebe8ff1e9980da040c9afa61b738995769b /diff.c | |
parent | 7cb4274d2606775b0d5b373756f76f386a31bb64 (diff) | |
parent | 8260bc59023136edeaed1f1006a03f44cc849883 (diff) | |
download | git-de00f4b7f3fd3aca18e4bea286bf060c595efd3b.zip git-de00f4b7f3fd3aca18e4bea286bf060c595efd3b.tar.gz git-de00f4b7f3fd3aca18e4bea286bf060c595efd3b.tar.bz2 |
Merge branch 'jk/log-follow-with-non-literal-pathspec'
"git [-c log.follow=true] log [--follow] ':(glob)f**'" used to barf.
* jk/log-follow-with-non-literal-pathspec:
diff: detect pathspec magic not supported by --follow
diff: factor out --follow pathspec check
pathspec: factor out magic-to-name function
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 29 |
1 files changed, 27 insertions, 2 deletions
@@ -4751,6 +4751,31 @@ unsigned diff_filter_bit(char status) return filter_bit[(int) status]; } +int diff_check_follow_pathspec(struct pathspec *ps, int die_on_error) +{ + unsigned forbidden_magic; + + if (ps->nr != 1) { + if (die_on_error) + die(_("--follow requires exactly one pathspec")); + return 0; + } + + forbidden_magic = ps->items[0].magic & ~(PATHSPEC_FROMTOP | + PATHSPEC_LITERAL); + if (forbidden_magic) { + if (die_on_error) { + struct strbuf sb = STRBUF_INIT; + pathspec_magic_names(forbidden_magic, &sb); + die(_("pathspec magic not supported by --follow: %s"), + sb.buf); + } + return 0; + } + + return 1; +} + void diff_setup_done(struct diff_options *options) { unsigned check_mask = DIFF_FORMAT_NAME | @@ -4858,8 +4883,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; |