name-hash: properly fold directory names in adjust_dirname_case()
[gitweb.git] / ref-filter.c
index bc551a752c460cd4751034b3d69d7e9b5dfc775e..9a8f55e45a160717caed50f1ea86ff108c42d6d5 100644 (file)
@@ -235,7 +235,7 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
 {
        const char *sp;
        const char *arg;
-       int i, at;
+       int i, at, atom_len;
 
        sp = atom;
        if (*sp == '*' && sp < ep)
@@ -250,19 +250,19 @@ int parse_ref_filter_atom(const char *atom, const char *ep)
                        return i;
        }
 
+       /*
+        * If the atom name has a colon, strip it and everything after
+        * it off - it specifies the format for this entry, and
+        * shouldn't be used for checking against the valid_atom
+        * table.
+        */
+       arg = memchr(sp, ':', ep - sp);
+       atom_len = (arg ? arg : ep) - sp;
+
        /* Is the atom a valid one? */
        for (i = 0; i < ARRAY_SIZE(valid_atom); i++) {
                int len = strlen(valid_atom[i].name);
-
-               /*
-                * If the atom name has a colon, strip it and everything after
-                * it off - it specifies the format for this entry, and
-                * shouldn't be used for checking against the valid_atom
-                * table.
-                */
-               arg = memchr(sp, ':', ep - sp);
-               if (len == (arg ? arg : ep) - sp &&
-                   !memcmp(valid_atom[i].name, sp, len))
+               if (len == atom_len && !memcmp(valid_atom[i].name, sp, len))
                        break;
        }
 
@@ -1576,24 +1576,6 @@ void ref_array_sort(struct ref_sorting *sorting, struct ref_array *array)
        qsort(array->items, array->nr, sizeof(struct ref_array_item *), compare_refs);
 }
 
-static int hex1(char ch)
-{
-       if ('0' <= ch && ch <= '9')
-               return ch - '0';
-       else if ('a' <= ch && ch <= 'f')
-               return ch - 'a' + 10;
-       else if ('A' <= ch && ch <= 'F')
-               return ch - 'A' + 10;
-       return -1;
-}
-static int hex2(const char *cp)
-{
-       if (cp[0] && cp[1])
-               return (hex1(cp[0]) << 4) | hex1(cp[1]);
-       else
-               return -1;
-}
-
 static void append_literal(const char *cp, const char *ep, struct ref_formatting_state *state)
 {
        struct strbuf *s = &state->stack->output;
@@ -1603,7 +1585,7 @@ static void append_literal(const char *cp, const char *ep, struct ref_formatting
                        if (cp[1] == '%')
                                cp++;
                        else {
-                               int ch = hex2(cp + 1);
+                               int ch = hex2chr(cp + 1);
                                if (0 <= ch) {
                                        strbuf_addch(s, ch);
                                        cp += 3;