Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Mon, 30 Dec 2013 20:27:01 +0000 (12:27 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 30 Dec 2013 20:27:01 +0000 (12:27 -0800)
* maint:
for-each-ref: remove unused variable

1  2 
builtin/for-each-ref.c
diff --combined builtin/for-each-ref.c
index 6551e7b39b6039032852d6ec0d0dd8da0d7031dc,7557aa239eeaf94b5cd609cfd8f44ee547c04190..51798b48b54266fccd2f7b4687646d152ab70588
@@@ -9,7 -9,6 +9,7 @@@
  #include "quote.h"
  #include "parse-options.h"
  #include "remote.h"
 +#include "color.h"
  
  /* Quoting styles */
  #define QUOTE_NONE 0
@@@ -76,8 -75,6 +76,8 @@@ static struct 
        { "upstream" },
        { "symref" },
        { "flag" },
 +      { "HEAD" },
 +      { "color" },
  };
  
  /*
@@@ -92,8 -89,7 +92,8 @@@
   */
  static const char **used_atom;
  static cmp_type *used_atom_type;
- static int used_atom_cnt, sort_atom_limit, need_tagged, need_symref;
+ static int used_atom_cnt, need_tagged, need_symref;
 +static int need_color_reset_at_eol;
  
  /*
   * Used to parse format string and sort specifiers
@@@ -180,21 -176,13 +180,21 @@@ static const char *find_next(const cha
  static int verify_format(const char *format)
  {
        const char *cp, *sp;
 +      static const char color_reset[] = "color:reset";
 +
 +      need_color_reset_at_eol = 0;
        for (cp = format; *cp && (sp = find_next(cp)); ) {
                const char *ep = strchr(sp, ')');
 +              int at;
 +
                if (!ep)
                        return error("malformed format string %s", sp);
                /* sp points at "%(" and ep points at the closing ")" */
 -              parse_atom(sp + 2, ep);
 +              at = parse_atom(sp + 2, ep);
                cp = ep + 1;
 +
 +              if (!memcmp(used_atom[at], "color:", 6))
 +                      need_color_reset_at_eol = !!strcmp(used_atom[at], color_reset);
        }
        return 0;
  }
@@@ -453,7 -441,7 +453,7 @@@ static void grab_person(const char *who
                if (name[wholen] != 0 &&
                    strcmp(name + wholen, "name") &&
                    strcmp(name + wholen, "email") &&
 -                  prefixcmp(name + wholen, "date"))
 +                  !starts_with(name + wholen, "date"))
                        continue;
                if (!wholine)
                        wholine = find_wholine(who, wholen, buf, sz);
                        v->s = copy_name(wholine);
                else if (!strcmp(name + wholen, "email"))
                        v->s = copy_email(wholine);
 -              else if (!prefixcmp(name + wholen, "date"))
 +              else if (starts_with(name + wholen, "date"))
                        grab_date(wholine, v, name);
        }
  
                if (deref)
                        name++;
  
 -              if (!prefixcmp(name, "creatordate"))
 +              if (starts_with(name, "creatordate"))
                        grab_date(wholine, v, name);
                else if (!strcmp(name, "creator"))
                        v->s = copy_line(wholine);
@@@ -661,20 -649,20 +661,20 @@@ static void populate_value(struct refin
                int deref = 0;
                const char *refname;
                const char *formatp;
 +              struct branch *branch = NULL;
  
                if (*name == '*') {
                        deref = 1;
                        name++;
                }
  
 -              if (!prefixcmp(name, "refname"))
 +              if (starts_with(name, "refname"))
                        refname = ref->refname;
 -              else if (!prefixcmp(name, "symref"))
 +              else if (starts_with(name, "symref"))
                        refname = ref->symref ? ref->symref : "";
 -              else if (!prefixcmp(name, "upstream")) {
 -                      struct branch *branch;
 +              else if (starts_with(name, "upstream")) {
                        /* only local branches may have an upstream */
 -                      if (prefixcmp(ref->refname, "refs/heads/"))
 +                      if (!starts_with(ref->refname, "refs/heads/"))
                                continue;
                        branch = branch_get(ref->refname + 11);
  
                            !branch->merge[0]->dst)
                                continue;
                        refname = branch->merge[0]->dst;
 -              }
 -              else if (!strcmp(name, "flag")) {
 +              } else if (starts_with(name, "color:")) {
 +                      char color[COLOR_MAXLEN] = "";
 +
 +                      color_parse(name + 6, "--format", color);
 +                      v->s = xstrdup(color);
 +                      continue;
 +              } else if (!strcmp(name, "flag")) {
                        char buf[256], *cp = buf;
                        if (ref->flag & REF_ISSYMREF)
                                cp = copy_advance(cp, ",symref");
                                v->s = xstrdup(buf + 1);
                        }
                        continue;
 -              }
 -              else if (!deref && grab_objectname(name, ref->objectname, v))
 +              } else if (!deref && grab_objectname(name, ref->objectname, v)) {
                        continue;
 -              else
 +              } else if (!strcmp(name, "HEAD")) {
 +                      const char *head;
 +                      unsigned char sha1[20];
 +
 +                      head = resolve_ref_unsafe("HEAD", sha1, 1, NULL);
 +                      if (!strcmp(ref->refname, head))
 +                              v->s = "*";
 +                      else
 +                              v->s = " ";
 +                      continue;
 +              } else
                        continue;
  
                formatp = strchr(name, ':');
 -              /* look for "short" refname format */
                if (formatp) {
 +                      int num_ours, num_theirs;
 +
                        formatp++;
                        if (!strcmp(formatp, "short"))
                                refname = shorten_unambiguous_ref(refname,
                                                      warn_ambiguous_refs);
 -                      else
 +                      else if (!strcmp(formatp, "track") &&
 +                               starts_with(name, "upstream")) {
 +                              char buf[40];
 +
 +                              stat_tracking_info(branch, &num_ours, &num_theirs);
 +                              if (!num_ours && !num_theirs)
 +                                      v->s = "";
 +                              else if (!num_ours) {
 +                                      sprintf(buf, "[behind %d]", num_theirs);
 +                                      v->s = xstrdup(buf);
 +                              } else if (!num_theirs) {
 +                                      sprintf(buf, "[ahead %d]", num_ours);
 +                                      v->s = xstrdup(buf);
 +                              } else {
 +                                      sprintf(buf, "[ahead %d, behind %d]",
 +                                              num_ours, num_theirs);
 +                                      v->s = xstrdup(buf);
 +                              }
 +                              continue;
 +                      } else if (!strcmp(formatp, "trackshort") &&
 +                                 starts_with(name, "upstream")) {
 +                              assert(branch);
 +                              stat_tracking_info(branch, &num_ours, &num_theirs);
 +                              if (!num_ours && !num_theirs)
 +                                      v->s = "=";
 +                              else if (!num_ours)
 +                                      v->s = "<";
 +                              else if (!num_theirs)
 +                                      v->s = ">";
 +                              else
 +                                      v->s = "<>";
 +                              continue;
 +                      } else
                                die("unknown %.*s format %s",
                                    (int)(formatp - name), name, formatp);
                }
@@@ -934,9 -875,11 +934,9 @@@ static void sort_refs(struct ref_sort *
        qsort(refs, num_refs, sizeof(struct refinfo *), compare_refs);
  }
  
 -static void print_value(struct refinfo *ref, int atom, int quote_style)
 +static void print_value(struct atom_value *v, int quote_style)
  {
 -      struct atom_value *v;
        struct strbuf sb = STRBUF_INIT;
 -      get_value(ref, atom, &v);
        switch (quote_style) {
        case QUOTE_NONE:
                fputs(v->s, stdout);
@@@ -1003,26 -946,15 +1003,26 @@@ static void show_ref(struct refinfo *in
        const char *cp, *sp, *ep;
  
        for (cp = format; *cp && (sp = find_next(cp)); cp = ep + 1) {
 +              struct atom_value *atomv;
 +
                ep = strchr(sp, ')');
                if (cp < sp)
                        emit(cp, sp);
 -              print_value(info, parse_atom(sp + 2, ep), quote_style);
 +              get_value(info, parse_atom(sp + 2, ep), &atomv);
 +              print_value(atomv, quote_style);
        }
        if (*cp) {
                sp = cp + strlen(cp);
                emit(cp, sp);
        }
 +      if (need_color_reset_at_eol) {
 +              struct atom_value resetv;
 +              char color[COLOR_MAXLEN] = "";
 +
 +              color_parse("reset", "--format", color);
 +              resetv.s = color;
 +              print_value(&resetv, quote_style);
 +      }
        putchar('\n');
  }
  
@@@ -1105,7 -1037,6 +1105,6 @@@ int cmd_for_each_ref(int argc, const ch
  
        if (!sort)
                sort = default_sort();
-       sort_atom_limit = used_atom_cnt;
  
        /* for warn_ambiguous_refs */
        git_config(git_default_config, NULL);