OSDN Git Service

Merge branch 'kn/ref-filter-branch-list'
authorJunio C Hamano <gitster@pobox.com>
Mon, 27 Feb 2017 21:57:13 +0000 (13:57 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Feb 2017 21:57:13 +0000 (13:57 -0800)
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=<N>' option to atoms which deal with refnames
  ref-filter: modify the 'lstrip=<N>' option to work with negative '<N>'
  ref-filter: Do not abruptly die when using the 'lstrip=<N>' 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=<string>) and %(if:notequals=<string>)
  ref-filter: include reference to 'used_atom' within 'atom_value'
  ...

1  2 
Documentation/git-branch.txt
builtin/tag.c
ref-filter.c
ref-filter.h

Simple merge
diff --cc builtin/tag.c
Simple merge
diff --cc 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
@@@ -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  */