docs: clarify what git-rebase's "-p" / "--preserve-merges" does
[gitweb.git] / object.c
index 472aa8d5befff0ebb80281fd6d69120d542d2baa..69fbbbf504d861fac42ee50bc04a49ede1f60028 100644 (file)
--- a/object.c
+++ b/object.c
@@ -158,6 +158,25 @@ void *create_object(const unsigned char *sha1, void *o)
        return obj;
 }
 
+void *object_as_type(struct object *obj, enum object_type type, int quiet)
+{
+       if (obj->type == type)
+               return obj;
+       else if (obj->type == OBJ_NONE) {
+               if (type == OBJ_COMMIT)
+                       ((struct commit *)obj)->index = alloc_commit_index();
+               obj->type = type;
+               return obj;
+       }
+       else {
+               if (!quiet)
+                       error("object %s is a %s, not a %s",
+                             sha1_to_hex(obj->sha1),
+                             typename(obj->type), typename(type));
+               return NULL;
+       }
+}
+
 struct object *lookup_unknown_object(const unsigned char *sha1)
 {
        struct object *obj = lookup_object(sha1);