diff options
author | Rafael Ascensão <rafa.almas@gmail.com> | 2017-11-21 21:33:41 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-11-22 13:18:59 +0900 |
commit | 65516f586b69307f977cd67cc45513a296cabc25 (patch) | |
tree | 54e9ba622b5eed2266fe459b09234e84794165e2 /refs.h | |
parent | 14c63a9dc093d6738454f6369a4f5663ca732cf7 (diff) | |
download | git-65516f586b69307f977cd67cc45513a296cabc25.tar.gz |
log: add option to choose which refs to decoratera/decorate-limit-refs
When `log --decorate` is used, git will decorate commits with all
available refs. While in most cases this may give the desired effect,
under some conditions it can lead to excessively verbose output.
Introduce two command line options, `--decorate-refs=<pattern>` and
`--decorate-refs-exclude=<pattern>` to allow the user to select which
refs are used in decoration.
When "--decorate-refs=<pattern>" is given, only the refs that match the
pattern are used in decoration. The refs that match the pattern when
"--decorate-refs-exclude=<pattern>" is given, are never used in
decoration.
These options follow the same convention for mixing negative and
positive patterns across the system, assuming that the inclusive default
is to match all refs available.
(1) if there is no positive pattern given, pretend as if an
inclusive default positive pattern was given;
(2) for each candidate, reject it if it matches no positive
pattern, or if it matches any one of the negative patterns.
The rules for what is considered a match are slightly different from the
rules used elsewhere.
Commands like `log --glob` assume a trailing '/*' when glob chars are
not present in the pattern. This makes it difficult to specify a single
ref. On the other hand, commands like `describe --match --all` allow
specifying exact refs, but do not have the convenience of allowing
"shorthand refs" like 'refs/heads' or 'heads' to refer to
'refs/heads/*'.
The commands introduced in this patch consider a match if:
(a) the pattern contains globs chars,
and regular pattern matching returns a match.
(b) the pattern does not contain glob chars,
and ref '<pattern>' exists, or if ref exists under '<pattern>/'
This allows both behaviours (allowing single refs and shorthand refs)
yet remaining compatible with existent commands.
Helped-by: Kevin Daudt <me@ikke.info>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Rafael Ascensão <rafa.almas@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.h')
-rw-r--r-- | refs.h | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -312,6 +312,30 @@ int for_each_namespaced_ref(each_ref_fn fn, void *cb_data); int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data); int for_each_rawref(each_ref_fn fn, void *cb_data); +/* + * Normalizes partial refs to their fully qualified form. + * Will prepend <prefix> to the <pattern> if it doesn't start with 'refs/'. + * <prefix> will default to 'refs/' if NULL. + * + * item.string will be set to the result. + * item.util will be set to NULL if <pattern> contains glob characters, or + * non-NULL if it doesn't. + */ +void normalize_glob_ref(struct string_list_item *item, const char *prefix, + const char *pattern); + +/* + * Returns 0 if refname matches any of the exclude_patterns, or if it doesn't + * match any of the include_patterns. Returns 1 otherwise. + * + * If pattern list is NULL or empty, matching against that list is skipped. + * This has the effect of matching everything by default, unless the user + * specifies rules otherwise. + */ +int ref_filter_match(const char *refname, + const struct string_list *include_patterns, + const struct string_list *exclude_patterns); + static inline const char *has_glob_specials(const char *pattern) { return strpbrk(pattern, "?*["); |