path: implement common_dir handling in git_pathdup_submodule()
[gitweb.git] / ref-filter.c
index 7b39303810c0e059b8d740ce208f65820a960f82..f38dee4f605df344315e0202487aeebc623f6582 100644 (file)
@@ -362,7 +362,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
        char *zone;
        unsigned long timestamp;
        long tz;
-       enum date_mode date_mode = DATE_NORMAL;
+       struct date_mode date_mode = { DATE_NORMAL };
        const char *formatp;
 
        /*
@@ -374,7 +374,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
        formatp = strchr(atomname, ':');
        if (formatp != NULL) {
                formatp++;
-               date_mode = parse_date_format(formatp);
+               parse_date_format(formatp, &date_mode);
        }
 
        if (!eoemail)
@@ -385,7 +385,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam
        tz = strtol(zone, NULL, 10);
        if ((tz == LONG_MIN || tz == LONG_MAX) && errno == ERANGE)
                goto bad;
-       v->s = xstrdup(show_date(timestamp, tz, date_mode));
+       v->s = xstrdup(show_date(timestamp, tz, &date_mode));
        v->ul = timestamp;
        return;
  bad:
@@ -847,8 +847,10 @@ static struct ref_array_item *new_ref_array_item(const char *refname,
                                                 const unsigned char *objectname,
                                                 int flag)
 {
-       struct ref_array_item *ref = xcalloc(1, sizeof(struct ref_array_item));
-       ref->refname = xstrdup(refname);
+       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';
        hashcpy(ref->objectname, objectname);
        ref->flag = flag;
 
@@ -870,6 +872,11 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
                return 0;
        }
 
+       if (flag & REF_ISBROKEN) {
+               warning("ignoring broken ref %s", refname);
+               return 0;
+       }
+
        if (*filter->name_patterns && !match_name_as_path(filter->name_patterns, refname))
                return 0;
 
@@ -889,7 +896,6 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
 static void free_array_item(struct ref_array_item *item)
 {
        free((char *)item->symref);
-       free(item->refname);
        free(item);
 }