git: add optional support for full pattern in fetch refspecs
PATCH 1/1 git: add optional support for full pattern in fetch refspecs
This patch updates the refs.c check_refname_component logic in order to allow for the possibility of using arbitrary patterns in fetch refspecs. Specifically, patterns similar to refs/tags/prefix-*:refs/tags/prefix-*.
In order to ensure that standard users do not accidentally setup refspecs which could cause issues, tie this feature to remote.<name>.arbitrary_pattern boolean configuration option. This ensures that no user will have this enabled on accident.
The primary reason against this is the ability to pull refs incorrectly and then later push them again. Ie:
refs/tags/some-prefix-*:/refs/tags/other-prefix-*
This ref will essentially re-name the references locally. This is generally not what you would want but there is no easy way to validate this doesn't occur. Note this can already occur to normal pattern refspecs via refs/tags/*:refs/tags/namespace/* refspecs, but these are a bit more difficult to typo.
However, the additional functionality is useful for specifying to pull certain patterns of refs, and can be useful if the power user decides to enable it for a given remote.
--- Documentation/config.txt | 7 +++++ Documentation/git-check-ref-format.txt | 12 ++++++--- builtin/check-ref-format.c | 2 ++ refs.c | 48 ++++++++++++++++++++++------------ refs.h | 15 ++++++----- remote.c | 2 ++ remote.h | 1 + 7 files changed, 61 insertions(+), 26 deletions(-)
Documentation/config.txt +7 -0
@@ -2331,6 +2331,13 @@ remote.<name>.prune:: remote (as if the `--prune` option was given on the command line). Overrides `fetch.prune` settings, if any. +remote.<name>.arbitrarypattern:: + When set to true, fetching from this remote will allow arbitrary complex + patterns for the fetch refspecs. For example, + refs/tags/prefix-*:refs/tags/prefix-* will work as expected. Care should be + taken as you could fetch refs into names that don't exist on the remote and + may end up pushing them again later by accident. + remotes.<group>:: The list of remotes which are fetched by "git remote update <group>". See linkgit:git-remote[1].
Documentation/git-check-ref-format.txt +9 -3
@@ -43,8 +43,8 @@ Git imposes the following rules on how references are named: caret `^`, or colon `:` anywhere. . They cannot have question-mark `?`, asterisk `*`, or open - bracket `[` anywhere. See the `--refspec-pattern` option below for - an exception to this rule. + bracket `[` anywhere. See the `--refspec-pattern` and `--arbitrary-pattern` + options below for exceptions to this rule. . They cannot begin or end with a slash `/` or contain multiple consecutive slashes (see the `--normalize` option below for an
@@ -95,7 +95,13 @@ OPTIONS (as used with remote repositories). If this option is enabled, <refname> is allowed to contain a single `*` in place of a one full pathname component (e.g., - `foo/*/bar` but not `foo/bar*`). + `foo/*/bar` but not `foo/bar*`). If '--arbitrary-pattern' is set, then + a single `foo/bar*baz` pattern will be accepted. + +--arbitrary-pattern:: + If '--refspec-pattern' is set, allow arbitrary patterns instead of the + default simple case. Implies '--refspec-pattern'. Note that only one '*' + pattern will be accepted. --normalize:: Normalize 'refname' by removing any leading slash (`/`)
builtin/check-ref-format.c +2 -0
@@ -70,6 +70,8 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix) flags &= ~REFNAME_ALLOW_ONELEVEL ; else if (!strcmp(argv[i], "--refspec-pattern")) flags |= REFNAME_REFSPEC_PATTERN; + else if (!strcmp(argv[i], "--arbitrary-pattern")) + flags |= REFNAME_ARBITRARY_PATTERN | REFNAME_REFSPEC_PATTERN; elseusage (builtin_check_ref_format_usage ); }
refs.c +31 -17
77 lines not on this page · raw message
refs.h +9 -6
@@ -218,14 +218,17 @@ extern int for_each_reflog(each_ref_fn, void *);#define REFNAME_ALLOW_ONELEVEL 1#define REFNAME_REFSPEC_PATTERN 2 +#define REFNAME_ARBITRARY_PATTERN 4/* -* Return 0 iff refname has the correct format for a refname according -* to the rules described in Documentation/git-check-ref-format.txt. -* If REFNAME_ALLOW_ONELEVEL is set in flags, then accept one-level -* reference names. If REFNAME_REFSPEC_PATTERN is set in flags, then -* allow a "*" wildcard character in place of one of the name -* components. No leading or repeated slashes are accepted. +* Return 0 iff refname has the correct format for a refname according to the +* rules described in Documentation/git-check-ref-format.txt. If +* REFNAME_ALLOW_ONELEVEL is set in flags, then accept one-level reference +* names. If REFNAME_REFSPEC_PATTERN is set in flags, then allow a "*" +* wildcard character in place of one of the name components. If +* REFNAME_ARBITRARY_PATTERN is set in flags, then allow an arbitrary pattern +* with a single '*' wildcard character as one of the name components as well. +* No leading or repeated slashes are accepted. */ extern int check_refname_format (const char *refname,int flags);
remote.c +2 -0
@@ -420,6 +420,8 @@ static int handle_config(const char *key, const char *value, void *cb) remote->skip_default_update =git_config_bool (key, value); else if (!strcmp(subkey, ".prune")) remote->prune =git_config_bool (key, value); + else if (!strcmp(subkey, ".arbitrarypattern")) + remote->arbitrary_pattern =git_config_bool (key, value); else if (!strcmp(subkey, ".url")) {const char *v;if (git_config_string (&v, key, value))
remote.h +1 -0
@@ -46,6 +46,7 @@ struct remote {int skip_default_update;int mirror;int prune; +int arbitrary_pattern;const char *receivepack;const char *uploadpack;
Signature · 1 line
2.4.3
Documentation/config.txt remote.<name>.prune:: · line 2339
Quoted 6 lines · Jacob Keller
Documentation/config.txt +6
-0+remote.<name>.arbitrarypattern:: + When set to true, fetching from this remote will allow arbitrary complex + patterns for the fetch refspecs. For example, + refs/tags/prefix-*:refs/tags/prefix-* will work as expected. Care should be + taken as you could fetch refs into names that don't exist on the remote and + may end up pushing them again later by accident.
Bad name and explanation, unless you truly mean "arbitrary", like taking something like "refs/ta*/prefix-*-*-foo:refs/*".
More importantly, this is not "pattern"; you are talking about refspec, I think.
But that probably does not matter. I do not think this even needs to exist as an option.
People's existing settings would not have anything other than an asterisk as a whole path component on each side (or no asterisk anywhere), and if they had an asterisk anywhere else they would have gotten an error and wouldn't have made any progress until they fixed it. So if you loosen the current rule sligntly and tell them "If your refspec has an asterisk in it, then you must have one asterisk on each side of it. That rule hasn't changed. But your asterisks no longer have to be a whole path component", such a change would not hurt them. Their existing setting that work would not notice, and existing users would not be relying on a refspec with an asterisk as part of a path component to error out.
Quoted 9 lines · Junio C Hamano
Documentation/config.txt remote.<name>.prune:: · line 2339
Quoted 6 lines · Jacob Keller
Documentation/config.txt +6
-0+remote.<name>.arbitrarypattern:: + When set to true, fetching from this remote will allow arbitrary complex + patterns for the fetch refspecs. For example, + refs/tags/prefix-*:refs/tags/prefix-* will work as expected. Care should be + taken as you could fetch refs into names that don't exist on the remote and + may end up pushing them again later by accident.
Quoted 3 lines
Bad name and explanation, unless you truly mean "arbitrary", like taking something like "refs/ta*/prefix-*-*-foo:refs/*".
I couldn't figure out what to use, and the original intent was to add an option.. but see below,
Quoted 3 lines
More importantly, this is not "pattern"; you are talking about refspec, I think.
In this case the option was an additional modifier to the refspec_patterns, and I was talking about how the pattern could be slightly more arbitrary. I do agree it is a bad name, but i couldn't actually come up with anything better.
Quoted 3 lines
But that probably does not matter. I do not think this even needs to exist as an option.
Yes, I agree especially as I look at it more. I'll work up a patch version which does this without the option.
Quoted 12 lines
People's existing settings would not have anything other than an asterisk as a whole path component on each side (or no asterisk anywhere), and if they had an asterisk anywhere else they would have gotten an error and wouldn't have made any progress until they fixed it. So if you loosen the current rule sligntly and tell them "If your refspec has an asterisk in it, then you must have one asterisk on each side of it. That rule hasn't changed. But your asterisks no longer have to be a whole path component", such a change would not hurt them. Their existing setting that work would not notice, and existing users would not be relying on a refspec with an asterisk as part of a path component to error out.
Right. We aren't breaking anyones current functionality, just adding new functionality. We already check for a * in both sides, and my code will ensure only 1 star total. It will then work for the new somewhat more expanded patterns and we don't need an option.
I'll work up a v2.
Regards,
Jake