зеркало из https://github.com/microsoft/git.git
describe: teach describe negative pattern matches
Teach git-describe the `--exclude` option which will allow specifying a glob pattern of tags to ignore. This can be combined with the `--match` patterns to enable more flexibility in determining which tags to consider. For example, suppose you wish to find the first official release tag that contains a certain commit. If we assume that official release tags are of the form "v*" and pre-release candidates include "*rc*" in their name, we can now find the first release tag that introduces the commit abcdef: git describe --contains --match="v*" --exclude="*rc*" abcdef Add documentation, tests, and completion for this change. Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
43f8080eaf
Коммит
77d21f29ea
|
@ -88,6 +88,16 @@ OPTIONS
|
||||||
patterns will be considered. Use `--no-match` to clear and reset the
|
patterns will be considered. Use `--no-match` to clear and reset the
|
||||||
list of patterns.
|
list of patterns.
|
||||||
|
|
||||||
|
--exclude <pattern>::
|
||||||
|
Do not consider tags matching the given `glob(7)` pattern, excluding
|
||||||
|
the "refs/tags/" prefix. This can be used to narrow the tag space and
|
||||||
|
find only tags matching some meaningful criteria. If given multiple
|
||||||
|
times, a list of patterns will be accumulated and tags matching any
|
||||||
|
of the patterns will be excluded. When combined with --match a tag will
|
||||||
|
be considered when it matches at least one --match pattern and does not
|
||||||
|
match any of the --exclude patterns. Use `--no-exclude` to clear and
|
||||||
|
reset the list of patterns.
|
||||||
|
|
||||||
--always::
|
--always::
|
||||||
Show uniquely abbreviated commit object as fallback.
|
Show uniquely abbreviated commit object as fallback.
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ static int max_candidates = 10;
|
||||||
static struct hashmap names;
|
static struct hashmap names;
|
||||||
static int have_util;
|
static int have_util;
|
||||||
static struct string_list patterns = STRING_LIST_INIT_NODUP;
|
static struct string_list patterns = STRING_LIST_INIT_NODUP;
|
||||||
|
static struct string_list exclude_patterns = STRING_LIST_INIT_NODUP;
|
||||||
static int always;
|
static int always;
|
||||||
static const char *dirty;
|
static const char *dirty;
|
||||||
|
|
||||||
|
@ -129,6 +130,22 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
|
||||||
if (!all && !is_tag)
|
if (!all && !is_tag)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we're given exclude patterns, first exclude any tag which match
|
||||||
|
* any of the exclude pattern.
|
||||||
|
*/
|
||||||
|
if (exclude_patterns.nr) {
|
||||||
|
struct string_list_item *item;
|
||||||
|
|
||||||
|
if (!is_tag)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for_each_string_list_item(item, &exclude_patterns) {
|
||||||
|
if (!wildmatch(item->string, path + 10, 0, NULL))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we're given patterns, accept only tags which match at least one
|
* If we're given patterns, accept only tags which match at least one
|
||||||
* pattern.
|
* pattern.
|
||||||
|
@ -421,6 +438,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
|
||||||
N_("consider <n> most recent tags (default: 10)")),
|
N_("consider <n> most recent tags (default: 10)")),
|
||||||
OPT_STRING_LIST(0, "match", &patterns, N_("pattern"),
|
OPT_STRING_LIST(0, "match", &patterns, N_("pattern"),
|
||||||
N_("only consider tags matching <pattern>")),
|
N_("only consider tags matching <pattern>")),
|
||||||
|
OPT_STRING_LIST(0, "exclude", &exclude_patterns, N_("pattern"),
|
||||||
|
N_("do not consider tags matching <pattern>")),
|
||||||
OPT_BOOL(0, "always", &always,
|
OPT_BOOL(0, "always", &always,
|
||||||
N_("show abbreviated commit object as fallback")),
|
N_("show abbreviated commit object as fallback")),
|
||||||
{OPTION_STRING, 0, "dirty", &dirty, N_("mark"),
|
{OPTION_STRING, 0, "dirty", &dirty, N_("mark"),
|
||||||
|
@ -458,6 +477,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
|
||||||
argv_array_push(&args, "--tags");
|
argv_array_push(&args, "--tags");
|
||||||
for_each_string_list_item(item, &patterns)
|
for_each_string_list_item(item, &patterns)
|
||||||
argv_array_pushf(&args, "--refs=refs/tags/%s", item->string);
|
argv_array_pushf(&args, "--refs=refs/tags/%s", item->string);
|
||||||
|
for_each_string_list_item(item, &exclude_patterns)
|
||||||
|
argv_array_pushf(&args, "--exclude=refs/tags/%s", item->string);
|
||||||
}
|
}
|
||||||
if (argc)
|
if (argc)
|
||||||
argv_array_pushv(&args, argv);
|
argv_array_pushv(&args, argv);
|
||||||
|
|
|
@ -1198,6 +1198,7 @@ _git_describe ()
|
||||||
__gitcomp "
|
__gitcomp "
|
||||||
--all --tags --contains --abbrev= --candidates=
|
--all --tags --contains --abbrev= --candidates=
|
||||||
--exact-match --debug --long --match --always
|
--exact-match --debug --long --match --always
|
||||||
|
--exclude
|
||||||
"
|
"
|
||||||
return
|
return
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -218,6 +218,14 @@ test_expect_success 'describe --contains and --match' '
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'describe --exclude' '
|
||||||
|
echo "c~1" >expect &&
|
||||||
|
tagged_commit=$(git rev-parse "refs/tags/A^0") &&
|
||||||
|
test_must_fail git describe --contains --match="B" $tagged_commit &&
|
||||||
|
git describe --contains --match="?" --exclude="A" $tagged_commit >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'describe --contains and --no-match' '
|
test_expect_success 'describe --contains and --no-match' '
|
||||||
echo "A^0" >expect &&
|
echo "A^0" >expect &&
|
||||||
tagged_commit=$(git rev-parse "refs/tags/A^0") &&
|
tagged_commit=$(git rev-parse "refs/tags/A^0") &&
|
||||||
|
|
Загрузка…
Ссылка в новой задаче