From: Junio C Hamano Date: Mon, 27 Feb 2017 21:57:13 +0000 (-0800) Subject: Merge branch 'kn/ref-filter-branch-list' X-Git-Tag: v2.13.0-rc0~174 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=93e8cd8b6ee766b35bfd3913f56ba86d63cb6253;p=git Merge branch 'kn/ref-filter-branch-list' The code to list branches in "git branch" has been consolidated with the more generic ref-filter API. * kn/ref-filter-branch-list: (21 commits) ref-filter: resurrect "strip" as a synonym to "lstrip" branch: implement '--format' option branch: use ref-filter printing APIs branch, tag: use porcelain output ref-filter: allow porcelain to translate messages in the output ref-filter: add an 'rstrip=' option to atoms which deal with refnames ref-filter: modify the 'lstrip=' option to work with negative '' ref-filter: Do not abruptly die when using the 'lstrip=' option ref-filter: rename the 'strip' option to 'lstrip' ref-filter: make remote_ref_atom_parser() use refname_atom_parser_internal() ref-filter: introduce refname_atom_parser() ref-filter: introduce refname_atom_parser_internal() ref-filter: make "%(symref)" atom work with the ':short' modifier ref-filter: add support for %(upstream:track,nobracket) ref-filter: make %(upstream:track) prints "[gone]" for invalid upstreams ref-filter: introduce format_ref_array_item() ref-filter: move get_head_description() from branch.c ref-filter: modify "%(objectname:short)" to take length ref-filter: implement %(if:equals=) and %(if:notequals=) ref-filter: include reference to 'used_atom' within 'atom_value' ... --- 93e8cd8b6ee766b35bfd3913f56ba86d63cb6253 diff --cc ref-filter.c index 3820b21cc7,2a94d6da98..1ec0fb8391 --- a/ref-filter.c +++ b/ref-filter.c @@@ -943,8 -1231,54 +1231,56 @@@ static void fill_remote_ref_details(str *s = ">"; else *s = "<>"; - } else /* RR_NORMAL */ - *s = refname; + } else + die("BUG: unhandled RR_* enum"); + } + + char *get_head_description(void) + { + struct strbuf desc = STRBUF_INIT; + struct wt_status_state state; + memset(&state, 0, sizeof(state)); + wt_status_get_state(&state, 1); + if (state.rebase_in_progress || + state.rebase_interactive_in_progress) + strbuf_addf(&desc, _("(no branch, rebasing %s)"), + state.branch); + else if (state.bisect_in_progress) + strbuf_addf(&desc, _("(no branch, bisect started on %s)"), + state.branch); + else if (state.detached_from) { - /* TRANSLATORS: make sure these match _("HEAD detached at ") - and _("HEAD detached from ") in wt-status.c */ + if (state.detached_at) ++ /* TRANSLATORS: make sure this matches ++ "HEAD detached at " in wt-status.c */ + strbuf_addf(&desc, _("(HEAD detached at %s)"), + state.detached_from); + else ++ /* TRANSLATORS: make sure this matches ++ "HEAD detached from " in wt-status.c */ + strbuf_addf(&desc, _("(HEAD detached from %s)"), + state.detached_from); + } + else + strbuf_addstr(&desc, _("(no branch)")); + free(state.branch); + free(state.onto); + free(state.detached_from); + return strbuf_detach(&desc, NULL); + } + + static const char *get_symref(struct used_atom *atom, struct ref_array_item *ref) + { + if (!ref->symref) + return ""; + else + return show_ref(&atom->u.refname, ref->symref); + } + + static const char *get_refname(struct used_atom *atom, struct ref_array_item *ref) + { + if (ref->kind & FILTER_REFS_DETACHED_HEAD) + return get_head_description(); + return show_ref(&atom->u.refname, ref->refname); } /* diff --cc ref-filter.h index 7b05592baf,44b36eded0..154e24c405 --- a/ref-filter.h +++ b/ref-filter.h @@@ -108,12 -111,9 +111,16 @@@ int parse_opt_ref_sorting(const struct struct ref_sorting *ref_default_sorting(void); /* Function to parse --merged and --no-merged options */ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset); + /* Get the current HEAD's description */ + char *get_head_description(void); + /* Set up translated strings in the output. */ + void setup_ref_filter_porcelain_msg(void); +/* + * Print a single ref, outside of any ref-filter. Note that the + * name must be a fully qualified refname. + */ +void pretty_print_ref(const char *name, const unsigned char *sha1, + const char *format); + #endif /* REF_FILTER_H */