Skip to content

Commit

Permalink
Merge branch 'kn/for-each-tag'
Browse files Browse the repository at this point in the history
The "ref-filter" code was taught about many parts of what "tag -l"
does and then "tag -l" is being reimplemented in terms of "ref-filter".

* kn/for-each-tag:
  tag.c: implement '--merged' and '--no-merged' options
  tag.c: implement '--format' option
  tag.c: use 'ref-filter' APIs
  tag.c: use 'ref-filter' data structures
  ref-filter: add option to match literal pattern
  ref-filter: add support to sort by version
  ref-filter: add support for %(contents:lines=X)
  ref-filter: add option to filter out tags, branches and remotes
  ref-filter: implement an `align` atom
  ref-filter: introduce match_atom_name()
  ref-filter: introduce handler function for each atom
  utf8: add function to align a string into given strbuf
  ref-filter: introduce ref_formatting_state and ref_formatting_stack
  ref-filter: move `struct atom_value` to ref-filter.c
  strtoul_ui: reject negative values
  • Loading branch information
gitster committed Oct 5, 2015
2 parents 416e2b3 + 5242860 commit 8a54523
Show file tree
Hide file tree
Showing 13 changed files with 746 additions and 379 deletions.
17 changes: 16 additions & 1 deletion Documentation/git-for-each-ref.txt
Expand Up @@ -127,6 +127,17 @@ color::
Change output color. Followed by `:<colorname>`, where names
are described in `color.branch.*`.

align::
Left-, middle-, or right-align the content between
%(align:...) and %(end). The "align:" is followed by `<width>`
and `<position>` in any order separated by a comma, where the
`<position>` is either left, right or middle, default being
left and `<width>` is the total length of the content with
alignment. If the contents length is more than the width then
no alignment is performed. If used with '--quote' everything
in between %(align:...) and %(end) is quoted, but if nested
then only the topmost level performs quoting.

In addition to the above, for commit and tag objects, the header
field names (`tree`, `parent`, `object`, `type`, and `tag`) can
be used to specify the value in the header field.
Expand All @@ -139,12 +150,16 @@ The complete message in a commit and tag object is `contents`.
Its first line is `contents:subject`, where subject is the concatenation
of all lines of the commit message up to the first blank line. The next
line is 'contents:body', where body is all of the lines after the first
blank line. Finally, the optional GPG signature is `contents:signature`.
blank line. The optional GPG signature is `contents:signature`. The
first `N` lines of the message is obtained using `contents:lines=N`.

For sorting purposes, fields with numeric values sort in numeric
order (`objectsize`, `authordate`, `committerdate`, `taggerdate`).
All other fields are used to sort in their byte-value order.

There is also an option to sort by versions, this can be done by using
the fieldname `version:refname` or its alias `v:refname`.

In any case, a field name that refers to a field inapplicable to
the object referred by the ref does not cause an error. It
returns an empty string instead.
Expand Down
27 changes: 20 additions & 7 deletions Documentation/git-tag.txt
Expand Up @@ -13,7 +13,8 @@ SYNOPSIS
<tagname> [<commit> | <object>]
'git tag' -d <tagname>...
'git tag' [-n[<num>]] -l [--contains <commit>] [--points-at <object>]
[--column[=<options>] | --no-column] [--create-reflog] [<pattern>...]
[--column[=<options>] | --no-column] [--create-reflog] [--sort=<key>]
[--format=<format>] [--[no-]merged [<commit>]] [<pattern>...]
'git tag' -v <tagname>...

DESCRIPTION
Expand Down Expand Up @@ -94,14 +95,16 @@ OPTIONS
using fnmatch(3)). Multiple patterns may be given; if any of
them matches, the tag is shown.

--sort=<type>::
Sort in a specific order. Supported type is "refname"
(lexicographic order), "version:refname" or "v:refname" (tag
--sort=<key>::
Sort based on the key given. Prefix `-` to sort in
descending order of the value. You may use the --sort=<key> option
multiple times, in which case the last key becomes the primary
key. Also supports "version:refname" or "v:refname" (tag
names are treated as versions). The "version:refname" sort
order can also be affected by the
"versionsort.prereleaseSuffix" configuration variable. Prepend
"-" to reverse sort order. When this option is not given, the
sort order defaults to the value configured for the 'tag.sort'
"versionsort.prereleaseSuffix" configuration variable.
The keys supported are the same as those in `git for-each-ref`.
Sort order defaults to the value configured for the 'tag.sort'
variable if it exists, or lexicographic order otherwise. See
linkgit:git-config[1].

Expand Down Expand Up @@ -156,6 +159,16 @@ This option is only applicable when listing tags without annotation lines.
The object that the new tag will refer to, usually a commit.
Defaults to HEAD.

<format>::
A string that interpolates `%(fieldname)` from the object
pointed at by a ref being shown. The format is the same as
that of linkgit:git-for-each-ref[1]. When unspecified,
defaults to `%(refname:short)`.

--[no-]merged [<commit>]::
Only list tags whose tips are reachable, or not reachable
if '--no-merged' is used, from the specified commit ('HEAD'
if not specified).

CONFIGURATION
-------------
Expand Down
1 change: 1 addition & 0 deletions builtin/for-each-ref.c
Expand Up @@ -68,6 +68,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
git_config(git_default_config, NULL);

filter.name_patterns = argv;
filter.match_as_path = 1;
filter_refs(&array, &filter, FILTER_REFS_ALL | FILTER_REFS_INCLUDE_BROKEN);
ref_array_sort(sorting, &array);

Expand Down

0 comments on commit 8a54523

Please sign in to comment.