Skip to contentSkip to conversation

add a perl compatible regex match flag to git describe

PATCH In review Mostyn Bramley-Moore 2 participants 4 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

cover add a perl compatible regex match flag to git describe

git describe currently only supports glob matching with the --matches flag. It would be useful to support regular expressions.

PCRE is already an optional dependency from git grep, I wonder if posix or extended regexes would be preferable?

Some old discussion of this as a candidate feature is here, though nobody put together a patch as far as I can see:
http://comments.gmane.org/gmane.comp.version-control.git/173873

Mostyn Bramley-Moore (2):
describe: mention glob in the --matches help text
describe: add --pcre-match option

 Documentation/git-describe.txt |  5 +++
 builtin/describe.c             | 73 ++++++++++++++++++++++++++++++++++++++++--
 t/README                       |  3 +-
 t/t6120-describe.sh            | 29 ++++++++++++++---
 4 files changed, 103 insertions(+), 7 deletions(-)
Signature · 1 line
2.5.0
#1 lore raw

PATCH 1/2 describe: mention glob in the --matches help text

This saves the user from needing to consult to manpage to learn the format of the --matches argument.

---
 builtin/describe.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
builtin/describe.c +2 -2
index 8a25abe..2386c64 100644
@@ -404,8 +404,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
 			    N_("only output exact matches"), 0),
 		OPT_INTEGER(0, "candidates", &max_candidates,
 			    N_("consider <n> most recent tags (default: 10)")),
-		OPT_STRING(0, "match",       &pattern, N_("pattern"),
-			   N_("only consider tags matching <pattern>")),
+		OPT_STRING(0, "match",       &pattern, N_("glob"),
+			   N_("only consider tags matching <glob>")),
 		OPT_BOOL(0, "always",        &always,
 			N_("show abbreviated commit object as fallback")),
 		{OPTION_STRING, 0, "dirty",  &dirty, N_("mark"),
Signature · 1 line
2.5.0
#2 lore raw

PATCH 2/2 describe: add --pcre-match option

In reply to Mostyn Bramley-Moore

Add a perl-compatible regular expression version of the --match option, which allows more flexible pattern matching.

---
 Documentation/git-describe.txt |  5 +++
 builtin/describe.c             | 69 ++++++++++++++++++++++++++++++++++++++++++
 t/README                       |  3 +-
 t/t6120-describe.sh            | 29 +++++++++++++++---
 4 files changed, 101 insertions(+), 5 deletions(-)
Documentation/git-describe.txt +5 -0
index c8f28c8..f646560 100644
@@ -85,6 +85,11 @@ OPTIONS
 	excluding the "refs/tags/" prefix.  This can be used to avoid
 	leaking private tags from the repository.
 
+--pcre-match <pattern>::
+	Only consider tags matching the given `PCRE` pattern,
+	excluding the "refs/tags/" prefix.  This can be used to avoid
+	leaking private tags from the repository.
+
 --always::
 	Show uniquely abbreviated commit object as fallback.
 
builtin/describe.c +69 -0

111 lines not on this page · raw message

t/README +2 -1
index 1dc908e..1495f59 100644
@@ -798,7 +798,8 @@ use these, and "test_set_prereq" for how to define your own.
  - LIBPCRE
 
    Git was compiled with USE_LIBPCRE=YesPlease. Wrap any tests
-   that use git-grep --perl-regexp or git-grep -P in these.
+   that use git-grep --perl-regexp, git-grep -P or
+   git describe --pcre-matches in these.
 
  - CASE_INSENSITIVE_FS
 
t/t6120-describe.sh +25 -4
index 85f2694..8290dea 100755
@@ -12,13 +12,14 @@ test_description='test describe
 '
 . ./test-lib.sh
 
-check_describe () {
-	expect="$1"
-	shift
+_check_describe () {
+	pcre="$1"
+	expect="$2"
+	shift 2
 	R=$(git describe "$@" 2>err.actual)
 	S=$?
 	cat err.actual >&3
-	test_expect_success "describe $*" '
+	test_expect_success $pcre "describe $*" '
 	test $S = 0 &&
 	case "$R" in
 	$expect)	echo happy ;;
@@ -28,6 +29,14 @@ check_describe () {
 	'
 }
 
+check_describe() {
+	_check_describe "" $*
+}
+
+check_describe_pcre() {
+	_check_describe LIBPCRE $*
+}
+
 test_expect_success setup '
 
 	test_tick &&
@@ -175,12 +184,24 @@ test_expect_success 'set-up matching pattern tests' '
 '
 
 check_describe "test-annotated-*" --match="test-*"
+check_describe_pcre "test-annotated-*" --pcre-match="^test-"
+check_describe_pcre "test-annotated-*" --match="test-*" --pcre-match="^test-"
 
 check_describe "test1-lightweight-*" --tags --match="test1-*"
+check_describe_pcre "test1-lightweight-*" --tags --pcre-match="^test1-"
+check_describe_pcre "test1-lightweight-*" --tags --match="test1-*" \
+	--pcre-match="^test1-"
 
 check_describe "test2-lightweight-*" --tags --match="test2-*"
+check_describe_pcre "test2-lightweight-*" --tags --pcre-match="^test2-"
+check_describe_pcre "test2-lightweight-*" --tags --match="test2-*" \
+	--pcre-match="^test2-"
 
 check_describe "test2-lightweight-*" --long --tags --match="test2-*" HEAD^
+check_describe_pcre "test2-lightweight-*" --long --tags \
+	--pcre-match="^test2-" HEAD^
+check_describe_pcre "test2-lightweight-*" --long --tags --match="test2-*" \
+	--pcre-match="^test2-" HEAD^
 
 test_expect_success 'name-rev with exact tags' '
 	echo A >expect &&
Signature · 1 line
2.5.0
#3 lore raw
In reply to Mostyn Bramley-Moore
Quoted 6 lines · Mostyn Bramley-Moore

git describe currently only supports glob matching with the --matches flag. It would be useful to support regular expressions.

PCRE is already an optional dependency from git grep, I wonder if posix or extended regexes would be preferable?

Quoted 7 lines

Some old discussion of this as a candidate feature is here, though nobody put together a patch as far as I can see:
http://comments.gmane.org/gmane.comp.version-control.git/173873

Mostyn Bramley-Moore (2):
describe: mention glob in the --matches help text
describe: add --pcre-match option

If you're going to implement this, I'd recommend an option that adjusts --matches to accept a PCRE regexp instead of adding a new option accepting its own pattern. I'd also recommend calling it --perl-regexp for compatibility with git grep.

Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187