alloc: factor out commit index

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>

Jeff King committed Jul 13, 2014 at 02:42 UTC 94d5a22cf651174f91d40a140593628a04fdacf3
2 files changed +8 -2
alloc.c
+7 -2
@@ -82,12 +82,17 @@ void *alloc_object_node(void)
82
83 static struct alloc_state commit_state;
84
85 +unsigned int alloc_commit_index(void)
86 +{
87 + static unsigned int count;
88 + return count++;
89 +}
90 +
91 void *alloc_commit_node(void)
92 {
87 - static int commit_count;
93 struct commit *c = alloc_node(&commit_state, sizeof(struct commit));
94 c->object.type = OBJ_COMMIT;
90 - c->index = commit_count++;
95 + c->index = alloc_commit_index();
96 return c;
97 }
98
cache.h
+1
@@ -1376,6 +1376,7 @@ extern void *alloc_commit_node(void);
1376 extern void *alloc_tag_node(void);
1377 extern void *alloc_object_node(void);
1378 extern void alloc_report(void);
1379 +extern unsigned int alloc_commit_index(void);
1380
1381 /* trace.c */
1382 __attribute__((format (printf, 1, 2)))