Skip to content

Commit 6da43d9

Browse files
abhishekkumar2718gitster
authored andcommitted
object: drop parsed_object_pool->commit_count
14ba97f (alloc: allow arbitrary repositories for alloc functions, 2018-05-15) introduced parsed_object_pool->commit_count to keep count of commits per repository and was used to assign commit->index. However, commit-slab code requires commit->index values to be unique and a global count would be correct, rather than a per-repo count. Let's introduce a static counter variable, `parsed_commits_count` to keep track of parsed commits so far. As commit_count has no use anymore, let's also drop it from the struct. Signed-off-by: Abhishek Kumar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eebb51b commit 6da43d9

File tree

12 files changed

+24
-19
lines changed

12 files changed

+24
-19
lines changed

alloc.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,29 @@ void *alloc_object_node(struct repository *r)
9999
return obj;
100100
}
101101

102-
static unsigned int alloc_commit_index(struct repository *r)
102+
/*
103+
* The returned count is to be used as an index into commit slabs,
104+
* that are *NOT* maintained per repository, and that is why a single
105+
* global counter is used.
106+
*/
107+
static unsigned int alloc_commit_index(void)
103108
{
104-
return r->parsed_objects->commit_count++;
109+
static unsigned int parsed_commits_count;
110+
return parsed_commits_count++;
105111
}
106112

107-
void init_commit_node(struct repository *r, struct commit *c)
113+
void init_commit_node(struct commit *c)
108114
{
109115
c->object.type = OBJ_COMMIT;
110-
c->index = alloc_commit_index(r);
116+
c->index = alloc_commit_index();
111117
c->graph_pos = COMMIT_NOT_FROM_GRAPH;
112118
c->generation = GENERATION_NUMBER_INFINITY;
113119
}
114120

115121
void *alloc_commit_node(struct repository *r)
116122
{
117123
struct commit *c = alloc_node(r->parsed_objects->commit_state, sizeof(struct commit));
118-
init_commit_node(r, c);
124+
init_commit_node(c);
119125
return c;
120126
}
121127

alloc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct repository;
99

1010
void *alloc_blob_node(struct repository *r);
1111
void *alloc_tree_node(struct repository *r);
12-
void init_commit_node(struct repository *r, struct commit *c);
12+
void init_commit_node(struct commit *c);
1313
void *alloc_commit_node(struct repository *r);
1414
void *alloc_tag_node(struct repository *r);
1515
void *alloc_object_node(struct repository *r);

blob.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct blob *lookup_blob(struct repository *r, const struct object_id *oid)
1010
struct object *obj = lookup_object(r, oid);
1111
if (!obj)
1212
return create_object(r, oid, alloc_blob_node(r));
13-
return object_as_type(r, obj, OBJ_BLOB, 0);
13+
return object_as_type(obj, OBJ_BLOB, 0);
1414
}
1515

1616
int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)

builtin/commit-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static int read_one_commit(struct oidset *commits, struct progress *progress,
154154
NULL, 0);
155155
if (!result)
156156
return error(_("invalid object: %s"), hash);
157-
else if (object_as_type(the_repository, result, OBJ_COMMIT, 1))
157+
else if (object_as_type(result, OBJ_COMMIT, 1))
158158
oidset_insert(commits, &result->oid);
159159

160160
display_progress(progress, oidset_size(commits));

builtin/fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static void mark_unreachable_referents(const struct object_id *oid)
241241
enum object_type type = oid_object_info(the_repository,
242242
&obj->oid, NULL);
243243
if (type > 0)
244-
object_as_type(the_repository, obj, type, 0);
244+
object_as_type(obj, type, 0);
245245
}
246246

247247
options.walk = mark_used;

commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct commit *lookup_commit_reference_gently(struct repository *r,
3737

3838
if (!obj)
3939
return NULL;
40-
return object_as_type(r, obj, OBJ_COMMIT, quiet);
40+
return object_as_type(obj, OBJ_COMMIT, quiet);
4141
}
4242

4343
struct commit *lookup_commit_reference(struct repository *r, const struct object_id *oid)
@@ -62,7 +62,7 @@ struct commit *lookup_commit(struct repository *r, const struct object_id *oid)
6262
struct object *obj = lookup_object(r, oid);
6363
if (!obj)
6464
return create_object(r, oid, alloc_commit_node(r));
65-
return object_as_type(r, obj, OBJ_COMMIT, 0);
65+
return object_as_type(obj, OBJ_COMMIT, 0);
6666
}
6767

6868
struct commit *lookup_commit_reference_by_name(const char *name)

object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ void *create_object(struct repository *r, const struct object_id *oid, void *o)
157157
return obj;
158158
}
159159

160-
void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet)
160+
void *object_as_type(struct object *obj, enum object_type type, int quiet)
161161
{
162162
if (obj->type == type)
163163
return obj;
164164
else if (obj->type == OBJ_NONE) {
165165
if (type == OBJ_COMMIT)
166-
init_commit_node(r, (struct commit *) obj);
166+
init_commit_node((struct commit *) obj);
167167
else
168168
obj->type = type;
169169
return obj;

object.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ struct parsed_object_pool {
1515
struct alloc_state *commit_state;
1616
struct alloc_state *tag_state;
1717
struct alloc_state *object_state;
18-
unsigned commit_count;
1918

2019
/* parent substitutions from .git/info/grafts and .git/shallow */
2120
struct commit_graft **grafts;
@@ -121,7 +120,7 @@ struct object *lookup_object(struct repository *r, const struct object_id *oid);
121120

122121
void *create_object(struct repository *r, const struct object_id *oid, void *obj);
123122

124-
void *object_as_type(struct repository *r, struct object *obj, enum object_type type, int quiet);
123+
void *object_as_type(struct object *obj, enum object_type type, int quiet);
125124

126125
/*
127126
* Returns the object, having parsed it to find out what it is.

refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ enum peel_status peel_object(const struct object_id *name, struct object_id *oid
339339

340340
if (o->type == OBJ_NONE) {
341341
int type = oid_object_info(the_repository, name, NULL);
342-
if (type < 0 || !object_as_type(the_repository, o, type, 0))
342+
if (type < 0 || !object_as_type(o, type, 0))
343343
return PEEL_INVALID;
344344
}
345345

t/helper/test-reach.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int cmd__reach(int ac, const char **av)
6767
die("failed to load commit for input %s resulting in oid %s\n",
6868
buf.buf, oid_to_hex(&oid));
6969

70-
c = object_as_type(r, peeled, OBJ_COMMIT, 0);
70+
c = object_as_type(peeled, OBJ_COMMIT, 0);
7171

7272
if (!c)
7373
die("failed to load commit for input %s resulting in oid %s\n",

tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct tag *lookup_tag(struct repository *r, const struct object_id *oid)
103103
struct object *obj = lookup_object(r, oid);
104104
if (!obj)
105105
return create_object(r, oid, alloc_tag_node(r));
106-
return object_as_type(r, obj, OBJ_TAG, 0);
106+
return object_as_type(obj, OBJ_TAG, 0);
107107
}
108108

109109
static timestamp_t parse_tag_date(const char *buf, const char *tail)

tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ struct tree *lookup_tree(struct repository *r, const struct object_id *oid)
200200
struct object *obj = lookup_object(r, oid);
201201
if (!obj)
202202
return create_object(r, oid, alloc_tree_node(r));
203-
return object_as_type(r, obj, OBJ_TREE, 0);
203+
return object_as_type(obj, OBJ_TREE, 0);
204204
}
205205

206206
int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)

0 commit comments

Comments
 (0)