Skip to content

extend git-describe pattern matching

Jacob Keller git 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest5 patches 5 repliesIn review
  2. v35 patches 16 repliesSuperseded
  3. v25 patches 2 repliesSuperseded

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5doc: add documentation for OPT_STRING_LISTDocumentation/technical/api-parse-options.txt+5 -00 replies
2/5name-rev: extend --refs to accept multiple patternsDocumentation/git-name-rev.txt builtin/name-rev.c t/t6007-rev-list-cherry-pick-file.sh+59 -134 replies
3/5name-rev: add support to exclude refs by pattern matchDocumentation/git-name-rev.txt builtin/name-rev.c t/t6007-rev-list-cherry-pick-file.sh+34 -11 reply
4/5describe: teach --match to accept multiple patternsDocumentation/git-describe.txt builtin/describe.c t/t6120-describe.sh+46 -80 replies
5/5describe: teach describe negative pattern matchesDocumentation/git-describe.txt builtin/describe.c contrib/completion/git-completion.bash +1 more+40 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH v4 0/5] extend git-describe pattern matching

From: Jacob Keller <[email protected]>

Teach git describe and git name-rev the ability to match multiple patterns inclusively. Additionally, teach these commands to also accept negative patterns to exclude any refs which match.

The pattern lists for positive and negative patterns are inclusive. This means that for the positive patterns, a reference will be considered as long as it matches at least one of the match patterns. It need not match all given patterns. Additionally for negative patterns, we will not consider any ref which matches any negative pattern, even if it matches one of the positive patterns.

Together this allows the ability to express far more sets of tags than a single match pattern alone. It does not provide quite the same depth as would teaching full regexp but it is simpler and easy enough to understand.

- v2
* use --exclude instead of --discard
* use modern style in tests

- v3
* fix broken test (sorry for the thrash!)

- v4
* update documentation and commit messages at Junio's suggestion
* add completion

After even more thought, I do not like the way that git-log works with --exclude, and do not believe it gives enough extra expressive power to bother with the complexity. The current implementation of --match and --exclude is relatively easy to explain and makes some sense. Since we did not have a historical reasoning in the same way that git-log does, I do not think using something like an exclude_list or similar is worth the added complexity.

-- interdiff since v3 --

Documentation/git-describe.txt +3 -1
index 21a43b78924a..8755f3af7bcd 100644
@@ -93,7 +93,9 @@ OPTIONS
 	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. Use `--no-exclude` to clear and
+	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::
Documentation/git-name-rev.txt +5 -3
index 301b4a8d55e6..da83f280ed88 100644
@@ -33,9 +33,11 @@ OPTIONS
 --exclude=<pattern>::
 	Do not use any ref whose name matches a given shell pattern. The
 	pattern can be one of branch name, tag name or fully qualified ref
-	name. If given multiple times, exclude refs that match any of the given
-	shell patterns. Use `--no-exclude` to clear the list of exclude
-	patterns.
+	name. If given multiple times, a ref will be excluded when it matches
+	any of the given patterns. When used together with --refs, a ref will
+	be used as a match only when it matches at least one --ref pattern and
+	does not match any --exclude patterns. Use `--no-exclude` to clear the
+	list of exclude patterns.
 
 --all::
 	List all commits reachable from all refs
Documentation/technical/api-parse-options.txt +3 -3
index 6914f54f5f44..36768b479e16 100644
@@ -168,10 +168,10 @@ There are some macros to easily define options:
 	Introduce an option with string argument.
 	The string argument is put into `str_var`.
 
-`OPT_STRING_LIST(short, long, &list, arg_str, description)`::
+`OPT_STRING_LIST(short, long, &struct string_list, arg_str, description)`::
 	Introduce an option with string argument.
-	The string argument is stored as an element in `&list` which must be a
-	struct string_list. Reset the list using `--no-option`.
+	The string argument is stored as an element in `string_list`.
+	Use of `--no-option` will clear the list of preceding values.
 
 `OPT_INTEGER(short, long, &int_var, description)`::
 	Introduce an option with integer argument.
builtin/name-rev.c +5 -4
index da4a0d7c0fdf..ea8ef48102f8 100644
@@ -166,10 +166,11 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
 
 		/* See if any of the patterns match. */
 		for_each_string_list_item(item, &data->ref_filters) {
-			/*
-			 * We want to check every pattern even if we already
-			 * found a match, just in case one of the later
-			 * patterns could abbreviate the output.
+			/* Check every pattern even after we found a match so
+			 * that we can determine when we should abbreviate the
+			 * output. We will abbreviate the output when any of
+			 * the patterns match a subpath, even if one of the
+			 * patterns matches fully.
 			 */
 			switch (subpath_matches(path, item->string)) {
 			case -1: /* did not match */
contrib/completion/git-completion.bash +1 -0
index 6721ff80fb13..835d7fcfd4f2 100644
@@ -1198,6 +1198,7 @@ _git_describe ()
 		__gitcomp "
 			--all --tags --contains --abbrev= --candidates=
 			--exact-match --debug --long --match --always
+			--exclude
 			"
 		return
 	esac

Jacob Keller (5):
doc: add documentation for OPT_STRING_LIST
name-rev: extend --refs to accept multiple patterns
name-rev: add support to exclude refs by pattern match
describe: teach --match to accept multiple patterns
describe: teach describe negative pattern matches

 Documentation/git-describe.txt                | 15 +++++++-
 Documentation/git-name-rev.txt                | 13 ++++++-
 Documentation/technical/api-parse-options.txt |  5 +++
 builtin/describe.c                            | 51 +++++++++++++++++++++----
 builtin/name-rev.c                            | 54 +++++++++++++++++++++------
 contrib/completion/git-completion.bash        |  1 +
 t/t6007-rev-list-cherry-pick-file.sh          | 38 +++++++++++++++++++
 t/t6120-describe.sh                           | 27 ++++++++++++++
 8 files changed, 183 insertions(+), 21 deletions(-)
Signature · 1 line
2.11.0.488.g1cece4bcb7a5