Skip to content

Commit 2ed3de4

Browse files
committed
Merge branch 'sg/object-as-type-commit-graph-fix'
The commit-graph facility did not work when in-core objects that are promoted from unknown type to commit (e.g. a commit that is accessed via a tag that refers to it) were involved, which has been corrected. * sg/object-as-type-commit-graph-fix: object_as_type: initialize commit-graph-related fields of 'struct commit'
2 parents d6cc136 + 4468d44 commit 2ed3de4

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

alloc.c

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

102-
unsigned int alloc_commit_index(struct repository *r)
102+
static unsigned int alloc_commit_index(struct repository *r)
103103
{
104104
return r->parsed_objects->commit_count++;
105105
}
106106

107-
void *alloc_commit_node(struct repository *r)
107+
void init_commit_node(struct repository *r, struct commit *c)
108108
{
109-
struct commit *c = alloc_node(r->parsed_objects->commit_state, sizeof(struct commit));
110109
c->object.type = OBJ_COMMIT;
111110
c->index = alloc_commit_index(r);
112111
c->graph_pos = COMMIT_NOT_FROM_GRAPH;
113112
c->generation = GENERATION_NUMBER_INFINITY;
113+
}
114+
115+
void *alloc_commit_node(struct repository *r)
116+
{
117+
struct commit *c = alloc_node(r->parsed_objects->commit_state, sizeof(struct commit));
118+
init_commit_node(r, c);
114119
return c;
115120
}
116121

alloc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ 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);
1213
void *alloc_commit_node(struct repository *r);
1314
void *alloc_tag_node(struct repository *r);
1415
void *alloc_object_node(struct repository *r);
1516
void alloc_report(struct repository *r);
16-
unsigned int alloc_commit_index(struct repository *r);
1717

1818
struct alloc_state *allocate_alloc_state(void);
1919
void clear_alloc_state(struct alloc_state *s);

object.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ void *object_as_type(struct repository *r, struct object *obj, enum object_type
164164
return obj;
165165
else if (obj->type == OBJ_NONE) {
166166
if (type == OBJ_COMMIT)
167-
((struct commit *)obj)->index = alloc_commit_index(r);
168-
obj->type = type;
167+
init_commit_node(r, (struct commit *) obj);
168+
else
169+
obj->type = type;
169170
return obj;
170171
}
171172
else {

0 commit comments

Comments
 (0)