Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 969eba6

Browse files
peffgitster
authored andcommitted
commit: push commit_index update into alloc_commit_node
Whenever we create a commit object via lookup_commit, we give it a unique index to be used with the commit-slab API. The theory is that any "struct commit" we create would follow this code path, so any such struct would get an index. However, callers could use alloc_commit_node() directly (and get multiple commits with index 0). Let's push the indexing into alloc_commit_node so that it's hard for callers to get it wrong. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c335d74 commit 969eba6

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

alloc.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,18 @@ union any_object {
4747

4848
DEFINE_ALLOCATOR(blob, struct blob)
4949
DEFINE_ALLOCATOR(tree, struct tree)
50-
DEFINE_ALLOCATOR(commit, struct commit)
50+
DEFINE_ALLOCATOR(raw_commit, struct commit)
5151
DEFINE_ALLOCATOR(tag, struct tag)
5252
DEFINE_ALLOCATOR(object, union any_object)
5353

54+
void *alloc_commit_node(void)
55+
{
56+
static int commit_count;
57+
struct commit *c = alloc_raw_commit_node();
58+
c->index = commit_count++;
59+
return c;
60+
}
61+
5462
static void report(const char *name, unsigned int count, size_t size)
5563
{
5664
fprintf(stderr, "%10s: %8u (%"PRIuMAX" kB)\n",
@@ -64,7 +72,7 @@ void alloc_report(void)
6472
{
6573
REPORT(blob, struct blob);
6674
REPORT(tree, struct tree);
67-
REPORT(commit, struct commit);
75+
REPORT(raw_commit, struct commit);
6876
REPORT(tag, struct tag);
6977
REPORT(object, union any_object);
7078
}

commit.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ static struct commit_extra_header *read_commit_extra_header_lines(const char *bu
1717
int save_commit_buffer = 1;
1818

1919
const char *commit_type = "commit";
20-
static int commit_count;
2120

2221
static struct commit *check_commit(struct object *obj,
2322
const unsigned char *sha1,
@@ -64,7 +63,6 @@ struct commit *lookup_commit(const unsigned char *sha1)
6463
struct object *obj = lookup_object(sha1);
6564
if (!obj) {
6665
struct commit *c = alloc_commit_node();
67-
c->index = commit_count++;
6866
return create_object(sha1, OBJ_COMMIT, c);
6967
}
7068
if (!obj->type)

0 commit comments

Comments
 (0)