summaryrefslogtreecommitdiff
path: root/alloc.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-07-13 06:42:08 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-07-14 01:59:05 (GMT)
commit94d5a22cf651174f91d40a140593628a04fdacf3 (patch)
treee07d447848193680f33a628cad544c0b5cdfe540 /alloc.c
parent8ff226a9d5ee065fe52752e6032f63cb6e4beccb (diff)
downloadgit-94d5a22cf651174f91d40a140593628a04fdacf3.zip
git-94d5a22cf651174f91d40a140593628a04fdacf3.tar.gz
git-94d5a22cf651174f91d40a140593628a04fdacf3.tar.bz2
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>
Diffstat (limited to 'alloc.c')
-rw-r--r--alloc.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/alloc.c b/alloc.c
index fd2e32d..12afadf 100644
--- 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;
}