fast-import: don't fail on omitted committer name
[gitweb.git] / alloc.c
diff --git a/alloc.c b/alloc.c
index 460db192d5a7de4073eb89972871720dd1c8fe1e..aeae55c976802264d714282218e58a858a9c68b5 100644 (file)
--- a/alloc.c
+++ b/alloc.c
 
 #define BLOCKING 1024
 
-#define DEFINE_ALLOCATOR(name)                                 \
+#define DEFINE_ALLOCATOR(name, type)                           \
 static unsigned int name##_allocs;                             \
-struct name *alloc_##name##_node(void)                         \
+void *alloc_##name##_node(void)                                        \
 {                                                              \
        static int nr;                                          \
-       static struct name *block;                              \
+       static type *block;                                     \
+       void *ret;                                              \
                                                                \
        if (!nr) {                                              \
                nr = BLOCKING;                                  \
-               block = xcalloc(BLOCKING, sizeof(struct name)); \
+               block = xmalloc(BLOCKING * sizeof(type));       \
        }                                                       \
        nr--;                                                   \
        name##_allocs++;                                        \
-       return block++;                                         \
+       ret = block++;                                          \
+       memset(ret, 0, sizeof(type));                           \
+       return ret;                                             \
 }
 
-DEFINE_ALLOCATOR(blob)
-DEFINE_ALLOCATOR(tree)
-DEFINE_ALLOCATOR(commit)
-DEFINE_ALLOCATOR(tag)
+union any_object {
+       struct object object;
+       struct blob blob;
+       struct tree tree;
+       struct commit commit;
+       struct tag tag;
+};
 
-#ifdef NO_C99_FORMAT
-#define SZ_FMT "%u"
-#else
-#define SZ_FMT "%zu"
-#endif
+DEFINE_ALLOCATOR(blob, struct blob)
+DEFINE_ALLOCATOR(tree, struct tree)
+DEFINE_ALLOCATOR(commit, struct commit)
+DEFINE_ALLOCATOR(tag, struct tag)
+DEFINE_ALLOCATOR(object, union any_object)
 
-static void report(const charname, unsigned int count, size_t size)
+static void report(const char *name, unsigned int count, size_t size)
 {
-    fprintf(stderr, "%10s: %8u (" SZ_FMT " kB)\n", name, count, size);
+       fprintf(stderr, "%10s: %8u (%"PRIuMAX" kB)\n",
+                       name, count, (uintmax_t) size);
 }
 
-#undef SZ_FMT
-
 #define REPORT(name)   \
     report(#name, name##_allocs, name##_allocs*sizeof(struct name) >> 10)