describe --contains: default to HEAD when no commit-ish is given
[gitweb.git] / builtin / index-pack.c
index de35960d99bb6c92c0f57c588aa6f43e3c227d2c..9ca0203922ba41139ad8daa9672acd22602bc1b5 100644 (file)
@@ -207,8 +207,13 @@ static unsigned check_object(struct object *obj)
        if (!(obj->flags & FLAG_CHECKED)) {
                unsigned long size;
                int type = sha1_object_info(obj->sha1, &size);
-               if (type != obj->type || type <= 0)
-                       die(_("object of unexpected type"));
+               if (type <= 0)
+                       die(_("did not receive expected object %s"),
+                             sha1_to_hex(obj->sha1));
+               if (type != obj->type)
+                       die(_("object %s: expected type %s, found %s"),
+                           sha1_to_hex(obj->sha1),
+                           typename(obj->type), typename(type));
                obj->flags |= FLAG_CHECKED;
                return 1;
        }
@@ -357,8 +362,7 @@ static void set_thread_data(struct thread_local *data)
 
 static struct base_data *alloc_base_data(void)
 {
-       struct base_data *base = xmalloc(sizeof(struct base_data));
-       memset(base, 0, sizeof(*base));
+       struct base_data *base = xcalloc(1, sizeof(struct base_data));
        base->ref_last = -1;
        base->ofs_last = -1;
        return base;
@@ -549,7 +553,7 @@ static void *unpack_data(struct object_entry *obj,
 
        do {
                ssize_t n = (len < 64*1024) ? len : 64*1024;
-               n = pread(get_thread_data()->pack_fd, inbuf, n, from);
+               n = xpread(get_thread_data()->pack_fd, inbuf, n, from);
                if (n < 0)
                        die_errno(_("cannot pread pack file"));
                if (!n)
@@ -781,7 +785,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
                        }
                        if (obj->type == OBJ_COMMIT) {
                                struct commit *commit = (struct commit *) obj;
-                               commit->buffer = NULL;
+                               if (detach_commit_buffer(commit, NULL) != data)
+                                       die("BUG: parse_object_buffer transmogrified our buffer");
                        }
                        obj->flags |= FLAG_CHECKED;
                }