alloc: factor out commit index
authorJeff King <peff@peff.net>
Sun, 13 Jul 2014 06:42:08 +0000 (02:42 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 14 Jul 2014 01:59:05 +0000 (18:59 -0700)
We keep a static counter to set the commit index on newly
allocated objects. However, since we also need to set the
index on any_objects which are converted to commits, let's
make the counter available as a public function.

While we're moving it, let's make sure the counter is
allocated as an unsigned integer to match the index field in
"struct commit".

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
alloc.c
cache.h
diff --git a/alloc.c b/alloc.c
index fd2e32df8c472d36043e0a389f5022b990600f77..12afadfacdd6094912a6e18a217a9aa6318b47b2 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -82,12 +82,17 @@ void *alloc_object_node(void)
 
 static struct alloc_state commit_state;
 
+unsigned int alloc_commit_index(void)
+{
+       static unsigned int count;
+       return count++;
+}
+
 void *alloc_commit_node(void)
 {
-       static int commit_count;
        struct commit *c = alloc_node(&commit_state, sizeof(struct commit));
        c->object.type = OBJ_COMMIT;
-       c->index = commit_count++;
+       c->index = alloc_commit_index();
        return c;
 }
 
diff --git a/cache.h b/cache.h
index df65231ac3db7ae08b5d9cfd37c505c4573c1675..42a5e865b588d39836a04b8a022e53ae8ce76d5d 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1376,6 +1376,7 @@ extern void *alloc_commit_node(void);
 extern void *alloc_tag_node(void);
 extern void *alloc_object_node(void);
 extern void alloc_report(void);
+extern unsigned int alloc_commit_index(void);
 
 /* trace.c */
 __attribute__((format (printf, 1, 2)))