branch.c: use 'ref-filter' APIs
Make 'branch.c' use 'ref-filter' APIs for iterating through refs sorting. This removes most of the code used in 'branch.c' replacing it with calls to the 'ref-filter' library. Make 'branch.c' use the 'filter_refs()' function provided by 'ref-filter' to filter out tags based on the options set. We provide a sorting option provided for 'branch.c' by using the sorting options provided by 'ref-filter'. Also by default, we sort by 'refname'. Since 'HEAD' is alphabatically before 'refs/...' we end up with an array consisting of the 'HEAD' ref then the local branches and finally the remote-tracking branches. Also remove the 'ignore' variable from ref_array_item as it was previously used for the '--merged' option and now that is handled by ref-filter. Modify some of the tests in t1430 to check the stderr for a warning regarding the broken ref. This is done as ref-filter throws a warning for broken refs rather than directly printing them. Add tests and documentation for the same. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
1511b22d40
commit
aedcb7dc75
@ -11,7 +11,7 @@ SYNOPSIS
|
||||
'git branch' [--color[=<when>] | --no-color] [-r | -a]
|
||||
[--list] [-v [--abbrev=<length> | --no-abbrev]]
|
||||
[--column[=<options>] | --no-column]
|
||||
[(--merged | --no-merged | --contains) [<commit>]] [<pattern>...]
|
||||
[(--merged | --no-merged | --contains) [<commit>]] [--sort=<key>] [<pattern>...]
|
||||
'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
|
||||
'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
|
||||
'git branch' --unset-upstream [<branchname>]
|
||||
@ -229,6 +229,16 @@ start-point is either a local or remote-tracking branch.
|
||||
The new name for an existing branch. The same restrictions as for
|
||||
<branchname> apply.
|
||||
|
||||
--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. The keys supported are the same as those in `git
|
||||
for-each-ref`. Sort order defaults to sorting based on the
|
||||
full refname (including `refs/...` prefix). This lists
|
||||
detached HEAD (if present) first, then local branches and
|
||||
finally remote-tracking branches.
|
||||
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
Reference in New Issue
Block a user