Merge branch 'sg/object-as-type-commit-graph-fix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 5 Feb 2019 22:26:19 +0000 (14:26 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Feb 2019 22:26:19 +0000 (14:26 -0800)
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'

1  2 
object.c
diff --combined object.c
index 541934ecdd214535eed584598d4354d89fd6c6b0,675cb8902b0c7289397f3a51e71b1ca2ce3dd2b6..5dc5eec367354ae4817b813b181423e096179a8a
+++ b/object.c
@@@ -95,7 -95,7 +95,7 @@@ struct object *lookup_object(struct rep
  
        first = i = hash_obj(sha1, r->parsed_objects->obj_hash_size);
        while ((obj = r->parsed_objects->obj_hash[i]) != NULL) {
 -              if (!hashcmp(sha1, obj->oid.hash))
 +              if (hasheq(sha1, obj->oid.hash))
                        break;
                i++;
                if (i == r->parsed_objects->obj_hash_size)
@@@ -164,8 -164,9 +164,9 @@@ void *object_as_type(struct repository 
                return obj;
        else if (obj->type == OBJ_NONE) {
                if (type == OBJ_COMMIT)
-                       ((struct commit *)obj)->index = alloc_commit_index(r);
-               obj->type = type;
+                       init_commit_node(r, (struct commit *) obj);
+               else
+                       obj->type = type;
                return obj;
        }
        else {
@@@ -259,8 -260,8 +260,8 @@@ struct object *parse_object(struct repo
        if (obj && obj->parsed)
                return obj;
  
 -      if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) ||
 -          (!obj && has_object_file(oid) &&
 +      if ((obj && obj->type == OBJ_BLOB && repo_has_object_file(r, oid)) ||
 +          (!obj && repo_has_object_file(r, oid) &&
             oid_object_info(r, oid, NULL) == OBJ_BLOB)) {
                if (check_object_signature(repl, NULL, 0, NULL) < 0) {
                        error(_("sha1 mismatch %s"), oid_to_hex(oid));
                return lookup_object(r, oid->hash);
        }
  
 -      buffer = read_object_file(oid, &type, &size);
 +      buffer = repo_read_object_file(r, oid, &type, &size);
        if (buffer) {
                if (check_object_signature(repl, buffer, size, type_name(type)) < 0) {
                        free(buffer);
@@@ -482,26 -483,27 +483,26 @@@ struct raw_object_store *raw_object_sto
        return o;
  }
  
 -static void free_alt_odb(struct alternate_object_database *alt)
 +static void free_object_directory(struct object_directory *odb)
  {
 -      strbuf_release(&alt->scratch);
 -      oid_array_clear(&alt->loose_objects_cache);
 -      free(alt);
 +      free(odb->path);
 +      odb_clear_loose_cache(odb);
 +      free(odb);
  }
  
 -static void free_alt_odbs(struct raw_object_store *o)
 +static void free_object_directories(struct raw_object_store *o)
  {
 -      while (o->alt_odb_list) {
 -              struct alternate_object_database *next;
 +      while (o->odb) {
 +              struct object_directory *next;
  
 -              next = o->alt_odb_list->next;
 -              free_alt_odb(o->alt_odb_list);
 -              o->alt_odb_list = next;
 +              next = o->odb->next;
 +              free_object_directory(o->odb);
 +              o->odb = next;
        }
  }
  
  void raw_object_store_clear(struct raw_object_store *o)
  {
 -      FREE_AND_NULL(o->objectdir);
        FREE_AND_NULL(o->alternate_db);
  
        oidmap_free(o->replace_map, 1);
        o->commit_graph = NULL;
        o->commit_graph_attempted = 0;
  
 -      free_alt_odbs(o);
 -      o->alt_odb_tail = NULL;
 +      free_object_directories(o);
 +      o->odb_tail = NULL;
 +      o->loaded_alternates = 0;
  
        INIT_LIST_HEAD(&o->packed_git_mru);
        close_all_packs(o);
@@@ -540,7 -541,7 +541,7 @@@ void parsed_object_pool_clear(struct pa
                if (obj->type == OBJ_TREE)
                        free_tree_buffer((struct tree*)obj);
                else if (obj->type == OBJ_COMMIT)
 -                      release_commit_memory((struct commit*)obj);
 +                      release_commit_memory(o, (struct commit*)obj);
                else if (obj->type == OBJ_TAG)
                        release_tag_memory((struct tag*)obj);
        }