Merge branch 'tb/avoid-gcc-on-darwin-10-6'
[gitweb.git] / ref-filter.c
index d2946ea2a1d98653f748837a2d3c7a42896d5145..bc551a752c460cd4751034b3d69d7e9b5dfc775e 100644 (file)
@@ -43,6 +43,7 @@ static struct used_atom {
                        enum { C_BARE, C_BODY, C_BODY_DEP, C_LINES, C_SIG, C_SUB } option;
                        unsigned int nlines;
                } contents;
+               enum { O_FULL, O_SHORT } objectname;
        } u;
 } *used_atom;
 static int used_atom_cnt, need_tagged, need_symref;
@@ -73,14 +74,14 @@ static void remote_ref_atom_parser(struct used_atom *atom, const char *arg)
 static void body_atom_parser(struct used_atom *atom, const char *arg)
 {
        if (arg)
-               die("%%(body) does not take arguments");
+               die(_("%%(body) does not take arguments"));
        atom->u.contents.option = C_BODY_DEP;
 }
 
 static void subject_atom_parser(struct used_atom *atom, const char *arg)
 {
        if (arg)
-               die("%%(subject) does not take arguments");
+               die(_("%%(subject) does not take arguments"));
        atom->u.contents.option = C_SUB;
 }
 
@@ -102,6 +103,16 @@ static void contents_atom_parser(struct used_atom *atom, const char *arg)
                die(_("unrecognized %%(contents) argument: %s"), arg);
 }
 
+static void objectname_atom_parser(struct used_atom *atom, const char *arg)
+{
+       if (!arg)
+               atom->u.objectname = O_FULL;
+       else if (!strcmp(arg, "short"))
+               atom->u.objectname = O_SHORT;
+       else
+               die(_("unrecognized %%(objectname) argument: %s"), arg);
+}
+
 static align_type parse_align_position(const char *s)
 {
        if (!strcmp(s, "right"))
@@ -160,7 +171,7 @@ static struct {
        { "refname" },
        { "objecttype" },
        { "objectsize", FIELD_ULONG },
-       { "objectname" },
+       { "objectname", FIELD_STR, objectname_atom_parser },
        { "tree" },
        { "parent" },
        { "numparent", FIELD_ULONG },
@@ -230,7 +241,7 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
        if (*sp == '*' && sp < ep)
                sp++; /* deref */
        if (ep <= sp)
-               die("malformed field name: %.*s", (int)(ep-atom), atom);
+               die(_("malformed field name: %.*s"), (int)(ep-atom), atom);
 
        /* Do we have the atom already used elsewhere? */
        for (i = 0; i < used_atom_cnt; i++) {
@@ -256,7 +267,7 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
        }
 
        if (ARRAY_SIZE(valid_atom) <= i)
-               die("unknown field name: %.*s", (int)(ep-atom), atom);
+               die(_("unknown field name: %.*s"), (int)(ep-atom), atom);
 
        /* Add it in, including the deref prefix */
        at = used_atom_cnt;
@@ -410,7 +421,7 @@ int verify_ref_format(const char *format)
                int at;
 
                if (!ep)
-                       return error("malformed format string %s", sp);
+                       return error(_("malformed format string %s"), sp);
                /* sp points at "%(" and ep points at the closing ")" */
                at = parse_ref_filter_atom(sp + 2, ep);
                cp = ep + 1;
@@ -440,15 +451,17 @@ static void *get_obj(const unsigned char *sha1, struct object **obj, unsigned lo
 }
 
 static int grab_objectname(const char *name, const unsigned char *sha1,
-                           struct atom_value *v)
+                          struct atom_value *v, struct used_atom *atom)
 {
-       if (!strcmp(name, "objectname")) {
-               v->s = xstrdup(sha1_to_hex(sha1));
-               return 1;
-       }
-       if (!strcmp(name, "objectname:short")) {
-               v->s = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV));
-               return 1;
+       if (starts_with(name, "objectname")) {
+               if (atom->u.objectname == O_SHORT) {
+                       v->s = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV));
+                       return 1;
+               } else if (atom->u.objectname == O_FULL) {
+                       v->s = xstrdup(sha1_to_hex(sha1));
+                       return 1;
+               } else
+                       die("BUG: unknown %%(objectname) option");
        }
        return 0;
 }
@@ -472,7 +485,7 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
                        v->s = xstrfmt("%lu", sz);
                }
                else if (deref)
-                       grab_objectname(name, obj->oid.hash, v);
+                       grab_objectname(name, obj->oid.hash, v, &used_atom[i]);
        }
 }
 
@@ -862,12 +875,12 @@ static const char *strip_ref_components(const char *refname, const char *nr_arg)
        const char *start = refname;
 
        if (nr < 1 || *end != '\0')
-               die(":strip= requires a positive integer argument");
+               die(_(":strip= requires a positive integer argument"));
 
        while (remaining) {
                switch (*start++) {
                case '\0':
-                       die("ref '%s' does not have %ld components to :strip",
+                       die(_("ref '%s' does not have %ld components to :strip"),
                            refname, nr);
                case '/':
                        remaining--;
@@ -996,7 +1009,7 @@ static void populate_value(struct ref_array_item *ref)
                                v->s = xstrdup(buf + 1);
                        }
                        continue;
-               } else if (!deref && grab_objectname(name, ref->objectname, v)) {
+               } else if (!deref && grab_objectname(name, ref->objectname, v, atom)) {
                        continue;
                } else if (!strcmp(name, "HEAD")) {
                        const char *head;
@@ -1030,7 +1043,7 @@ static void populate_value(struct ref_array_item *ref)
                        else if (skip_prefix(formatp, "strip=", &arg))
                                refname = strip_ref_components(refname, arg);
                        else
-                               die("unknown %.*s format %s",
+                               die(_("unknown %.*s format %s"),
                                    (int)(formatp - name), name, formatp);
                }
 
@@ -1050,10 +1063,10 @@ static void populate_value(struct ref_array_item *ref)
  need_obj:
        buf = get_obj(ref->objectname, &obj, &size, &eaten);
        if (!buf)
-               die("missing object %s for %s",
+               die(_("missing object %s for %s"),
                    sha1_to_hex(ref->objectname), ref->refname);
        if (!obj)
-               die("parse_object_buffer failed on %s for %s",
+               die(_("parse_object_buffer failed on %s for %s"),
                    sha1_to_hex(ref->objectname), ref->refname);
 
        grab_values(ref->value, 0, obj, buf, size);
@@ -1081,10 +1094,10 @@ static void populate_value(struct ref_array_item *ref)
         */
        buf = get_obj(tagged, &obj, &size, &eaten);
        if (!buf)
-               die("missing object %s for %s",
+               die(_("missing object %s for %s"),
                    sha1_to_hex(tagged), ref->refname);
        if (!obj)
-               die("parse_object_buffer failed on %s for %s",
+               die(_("parse_object_buffer failed on %s for %s"),
                    sha1_to_hex(tagged), ref->refname);
        grab_values(ref->value, 1, obj, buf, size);
        if (!eaten)
@@ -1308,10 +1321,8 @@ static struct ref_array_item *new_ref_array_item(const char *refname,
                                                 const unsigned char *objectname,
                                                 int flag)
 {
-       size_t len = strlen(refname);
-       struct ref_array_item *ref = xcalloc(1, sizeof(struct ref_array_item) + len + 1);
-       memcpy(ref->refname, refname, len);
-       ref->refname[len] = '\0';
+       struct ref_array_item *ref;
+       FLEX_ALLOC_STR(ref, refname, refname);
        hashcpy(ref->objectname, objectname);
        ref->flag = flag;
 
@@ -1359,12 +1370,12 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
        unsigned int kind;
 
        if (flag & REF_BAD_NAME) {
-               warning("ignoring ref with broken name %s", refname);
+               warning(_("ignoring ref with broken name %s"), refname);
                return 0;
        }
 
        if (flag & REF_ISBROKEN) {
-               warning("ignoring broken ref %s", refname);
+               warning(_("ignoring broken ref %s"), refname);
                return 0;
        }