object: drop parsed_object_pool->commit_count
14ba97f8 (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 <abhishekkumar8222@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Abhishek Kumar committed
Jun 17, 2020 at 14:44 UTC
6da43d937ca96d277556fa92c5a664fb1cbcc8ac
12 files changed
+24
-19
alloc.c
+11
-5
@@ -99,15 +99,21 @@ void *alloc_object_node(struct repository *r)
99
return obj;
100
}
101
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)
108
{
104
- return r->parsed_objects->commit_count++;
109
+ static unsigned int parsed_commits_count;
110
+ return parsed_commits_count++;
111
}
112
107
-void init_commit_node(struct repository *r, struct commit *c)
113
+void init_commit_node(struct commit *c)
114
{
115
c->object.type = OBJ_COMMIT;
110
- c->index = alloc_commit_index(r);
116
+ c->index = alloc_commit_index();
117
c->graph_pos = COMMIT_NOT_FROM_GRAPH;
118
c->generation = GENERATION_NUMBER_INFINITY;
119
}
@@ -115,7 +121,7 @@ void init_commit_node(struct repository *r, struct commit *c)
121
void *alloc_commit_node(struct repository *r)
122
{
123
struct commit *c = alloc_node(r->parsed_objects->commit_state, sizeof(struct commit));
118
- init_commit_node(r, c);
124
+ init_commit_node(c);
125
return c;
126
}
127
alloc.h
+1
-1
@@ -9,7 +9,7 @@ struct repository;
9
10
void *alloc_blob_node(struct repository *r);
11
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);
13
void *alloc_commit_node(struct repository *r);
14
void *alloc_tag_node(struct repository *r);
15
void *alloc_object_node(struct repository *r);
blob.c
+1
-1
@@ -10,7 +10,7 @@ struct blob *lookup_blob(struct repository *r, const struct object_id *oid)
10
struct object *obj = lookup_object(r, oid);
11
if (!obj)
12
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);
14
}
15
16
int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size)
builtin/commit-graph.c
+1
-1
@@ -154,7 +154,7 @@ static int read_one_commit(struct oidset *commits, struct progress *progress,
154
NULL, 0);
155
if (!result)
156
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))
158
oidset_insert(commits, &result->oid);
159
160
display_progress(progress, oidset_size(commits));
builtin/fsck.c
+1
-1
@@ -241,7 +241,7 @@ static void mark_unreachable_referents(const struct object_id *oid)
241
enum object_type type = oid_object_info(the_repository,
242
&obj->oid, NULL);
243
if (type > 0)
244
- object_as_type(the_repository, obj, type, 0);
244
+ object_as_type(obj, type, 0);
245
}
246
247
options.walk = mark_used;
commit.c
+2
-2
@@ -37,7 +37,7 @@ struct commit *lookup_commit_reference_gently(struct repository *r,
37
38
if (!obj)
39
return NULL;
40
- return object_as_type(r, obj, OBJ_COMMIT, quiet);
40
+ return object_as_type(obj, OBJ_COMMIT, quiet);
41
}
42
43
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)
62
struct object *obj = lookup_object(r, oid);
63
if (!obj)
64
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);
66
}
67
68
struct commit *lookup_commit_reference_by_name(const char *name)
object.c
+2
-2
@@ -157,13 +157,13 @@ void *create_object(struct repository *r, const struct object_id *oid, void *o)
157
return obj;
158
}
159
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)
161
{
162
if (obj->type == type)
163
return obj;
164
else if (obj->type == OBJ_NONE) {
165
if (type == OBJ_COMMIT)
166
- init_commit_node(r, (struct commit *) obj);
166
+ init_commit_node((struct commit *) obj);
167
else
168
obj->type = type;
169
return obj;
object.h
+1
-2
@@ -15,7 +15,6 @@ struct parsed_object_pool {
15
struct alloc_state *commit_state;
16
struct alloc_state *tag_state;
17
struct alloc_state *object_state;
18
- unsigned commit_count;
18
19
/* parent substitutions from .git/info/grafts and .git/shallow */
20
struct commit_graft **grafts;
@@ -121,7 +120,7 @@ struct object *lookup_object(struct repository *r, const struct object_id *oid);
120
121
void *create_object(struct repository *r, const struct object_id *oid, void *obj);
122
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);
124
125
/*
126
* Returns the object, having parsed it to find out what it is.
refs.c
+1
-1
@@ -339,7 +339,7 @@ enum peel_status peel_object(const struct object_id *name, struct object_id *oid
339
340
if (o->type == OBJ_NONE) {
341
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))
343
return PEEL_INVALID;
344
}
345
t/helper/test-reach.c
+1
-1
@@ -67,7 +67,7 @@ int cmd__reach(int ac, const char **av)
67
die("failed to load commit for input %s resulting in oid %s\n",
68
buf.buf, oid_to_hex(&oid));
69
70
- c = object_as_type(r, peeled, OBJ_COMMIT, 0);
70
+ c = object_as_type(peeled, OBJ_COMMIT, 0);
71
72
if (!c)
73
die("failed to load commit for input %s resulting in oid %s\n",
tag.c
+1
-1
@@ -103,7 +103,7 @@ struct tag *lookup_tag(struct repository *r, const struct object_id *oid)
103
struct object *obj = lookup_object(r, oid);
104
if (!obj)
105
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);
107
}
108
109
static timestamp_t parse_tag_date(const char *buf, const char *tail)
tree.c
+1
-1
@@ -200,7 +200,7 @@ struct tree *lookup_tree(struct repository *r, const struct object_id *oid)
200
struct object *obj = lookup_object(r, oid);
201
if (!obj)
202
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);
204
}
205
206
int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size)