replace: add --graft option
[gitweb.git] / alloc.c
diff --git a/alloc.c b/alloc.c
index 53eba373dbb923e27998ccac5e655047772d41fe..eb22a45c9d0acf08a6024094bd0a2090a7307945 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -20,7 +20,7 @@
 
 #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 type *block;                                     \
@@ -47,30 +47,32 @@ union any_object {
 
 DEFINE_ALLOCATOR(blob, struct blob)
 DEFINE_ALLOCATOR(tree, struct tree)
-DEFINE_ALLOCATOR(commit, struct commit)
+DEFINE_ALLOCATOR(raw_commit, struct commit)
 DEFINE_ALLOCATOR(tag, struct tag)
 DEFINE_ALLOCATOR(object, union any_object)
 
-#ifdef NO_C99_FORMAT
-#define SZ_FMT "%u"
-#else
-#define SZ_FMT "%zu"
-#endif
-
-static void report(const char* name, unsigned int count, size_t size)
+void *alloc_commit_node(void)
 {
-    fprintf(stderr, "%10s: %8u (" SZ_FMT " kB)\n", name, count, size);
+       static int commit_count;
+       struct commit *c = alloc_raw_commit_node();
+       c->index = commit_count++;
+       return c;
 }
 
-#undef SZ_FMT
+static void report(const char *name, unsigned int count, size_t size)
+{
+       fprintf(stderr, "%10s: %8u (%"PRIuMAX" kB)\n",
+                       name, count, (uintmax_t) size);
+}
 
-#define REPORT(name)   \
-    report(#name, name##_allocs, name##_allocs*sizeof(struct name) >> 10)
+#define REPORT(name, type)     \
+    report(#name, name##_allocs, name##_allocs * sizeof(type) >> 10)
 
 void alloc_report(void)
 {
-       REPORT(blob);
-       REPORT(tree);
-       REPORT(commit);
-       REPORT(tag);
+       REPORT(blob, struct blob);
+       REPORT(tree, struct tree);
+       REPORT(raw_commit, struct commit);
+       REPORT(tag, struct tag);
+       REPORT(object, union any_object);
 }