Skip to content

Commit 34dfe19

Browse files
peffgitster
authored andcommitted
object_as_type: set commit index
The point of the "index" field of struct commit is that every allocated commit would have one. It is supposed to be an invariant that whenever object->type is set to OBJ_COMMIT, we have a unique index. Commit 969eba6 (commit: push commit_index update into alloc_commit_node, 2014-06-10) covered this case for newly-allocated commits. However, we may also allocate an "unknown" object via lookup_unknown_object, and only later convert it to a commit. We must make sure that we set the commit index when we switch the type field. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5de7f50 commit 34dfe19

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

object.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)
163163
if (obj->type == type)
164164
return obj;
165165
else if (obj->type == OBJ_NONE) {
166+
if (type == OBJ_COMMIT)
167+
((struct commit *)obj)->index = alloc_commit_index();
166168
obj->type = type;
167169
return obj;
168170
}

0 commit comments

Comments
 (0)