for-each-ref: add new option to include root refs
The git-for-each-ref(1) command doesn't provide a way to print root refs i.e pseudorefs and HEAD with the regular "refs/" prefixed refs. This commit adds a new option "--include-root-refs" to git-for-each-ref(1). When used this would also print pseudorefs and HEAD for the current worktree. 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
810f7a1aac
commit
33d15b5435
@ -20,10 +20,10 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
struct ref_sorting *sorting;
|
||||
struct string_list sorting_options = STRING_LIST_INIT_DUP;
|
||||
int icase = 0;
|
||||
int icase = 0, include_root_refs = 0, from_stdin = 0;
|
||||
struct ref_filter filter = REF_FILTER_INIT;
|
||||
struct ref_format format = REF_FORMAT_INIT;
|
||||
int from_stdin = 0;
|
||||
unsigned int flags = FILTER_REFS_REGULAR;
|
||||
struct strvec vec = STRVEC_INIT;
|
||||
|
||||
struct option opts[] = {
|
||||
@ -53,6 +53,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
|
||||
OPT_NO_CONTAINS(&filter.no_commit, N_("print only refs which don't contain the commit")),
|
||||
OPT_BOOL(0, "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
|
||||
OPT_BOOL(0, "stdin", &from_stdin, N_("read reference patterns from stdin")),
|
||||
OPT_BOOL(0, "include-root-refs", &include_root_refs, N_("also include HEAD ref and pseudorefs")),
|
||||
OPT_END(),
|
||||
};
|
||||
|
||||
@ -96,8 +97,11 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
|
||||
filter.name_patterns = argv;
|
||||
}
|
||||
|
||||
if (include_root_refs)
|
||||
flags |= FILTER_REFS_ROOT_REFS;
|
||||
|
||||
filter.match_as_path = 1;
|
||||
filter_and_format_refs(&filter, FILTER_REFS_REGULAR, sorting, &format);
|
||||
filter_and_format_refs(&filter, flags, sorting, &format);
|
||||
|
||||
ref_filter_clear(&filter);
|
||||
ref_sorting_release(sorting);
|
||||
|
||||
Reference in New Issue
Block a user