Skip to content

Commit 5de7f50

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c4ad00f commit 5de7f50

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

alloc.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,17 @@ void *alloc_object_node(void)
8282

8383
static struct alloc_state commit_state;
8484

85+
unsigned int alloc_commit_index(void)
86+
{
87+
static unsigned int count;
88+
return count++;
89+
}
90+
8591
void *alloc_commit_node(void)
8692
{
87-
static int commit_count;
8893
struct commit *c = alloc_node(&commit_state, sizeof(struct commit));
8994
c->object.type = OBJ_COMMIT;
90-
c->index = commit_count++;
95+
c->index = alloc_commit_index();
9196
return c;
9297
}
9398

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,7 @@ extern void *alloc_commit_node(void);
13541354
extern void *alloc_tag_node(void);
13551355
extern void *alloc_object_node(void);
13561356
extern void alloc_report(void);
1357+
extern unsigned int alloc_commit_index(void);
13571358

13581359
/* trace.c */
13591360
__attribute__((format (printf, 1, 2)))

0 commit comments

Comments
 (0)