Imported Upstream version 2.12.4
[platform/upstream/git.git] / object.c
index 23d6c96..e680d88 100644 (file)
--- a/object.c
+++ b/object.c
@@ -41,7 +41,8 @@ int type_from_string_gently(const char *str, ssize_t len, int gentle)
                len = strlen(str);
 
        for (i = 1; i < ARRAY_SIZE(object_type_strings); i++)
-               if (!strncmp(str, object_type_strings[i], len))
+               if (!strncmp(str, object_type_strings[i], len) &&
+                   object_type_strings[i][len] == '\0')
                        return i;
 
        if (gentle)
@@ -67,7 +68,7 @@ static unsigned int hash_obj(const unsigned char *sha1, unsigned int n)
  */
 static void insert_obj_hash(struct object *obj, struct object **hash, unsigned int size)
 {
-       unsigned int j = hash_obj(obj->sha1, size);
+       unsigned int j = hash_obj(obj->oid.hash, size);
 
        while (hash[j]) {
                j++;
@@ -91,7 +92,7 @@ struct object *lookup_object(const unsigned char *sha1)
 
        first = i = hash_obj(sha1, obj_hash_size);
        while ((obj = obj_hash[i]) != NULL) {
-               if (!hashcmp(sha1, obj->sha1))
+               if (!hashcmp(sha1, obj->oid.hash))
                        break;
                i++;
                if (i == obj_hash_size)
@@ -103,9 +104,7 @@ struct object *lookup_object(const unsigned char *sha1)
                 * that we do not need to walk the hash table the next
                 * time we look for it.
                 */
-               struct object *tmp = obj_hash[i];
-               obj_hash[i] = obj_hash[first];
-               obj_hash[first] = tmp;
+               SWAP(obj_hash[i], obj_hash[first]);
        }
        return obj;
 }
@@ -144,7 +143,7 @@ void *create_object(const unsigned char *sha1, void *o)
        obj->parsed = 0;
        obj->used = 0;
        obj->flags = 0;
-       hashcpy(obj->sha1, sha1);
+       hashcpy(obj->oid.hash, sha1);
 
        if (obj_hash_size - 1 <= nr_objs * 2)
                grow_object_hash();
@@ -167,7 +166,7 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)
        else {
                if (!quiet)
                        error("object %s is a %s, not a %s",
-                             sha1_to_hex(obj->sha1),
+                             oid_to_hex(&obj->oid),
                              typename(obj->type), typename(type));
                return NULL;
        }