Git 2.7.6
[gitweb.git] / builtin / pack-objects.c
index 1c63f8f28c7d925ee5647f190d236e64fc6e05a2..a27de5b323f3fc7852a48fdc6de99414e8005c10 100644 (file)
@@ -624,7 +624,7 @@ static struct object_entry **compute_write_order(void)
 {
        unsigned int i, wo_end, last_untagged;
 
-       struct object_entry **wo = xmalloc(to_pack.nr_objects * sizeof(*wo));
+       struct object_entry **wo;
        struct object_entry *objects = to_pack.objects;
 
        for (i = 0; i < to_pack.nr_objects; i++) {
@@ -657,6 +657,7 @@ static struct object_entry **compute_write_order(void)
         * Give the objects in the original recency order until
         * we see a tagged tip.
         */
+       ALLOC_ARRAY(wo, to_pack.nr_objects);
        for (i = wo_end = 0; i < to_pack.nr_objects; i++) {
                if (objects[i].tagged)
                        break;
@@ -769,7 +770,7 @@ static void write_pack_file(void)
 
        if (progress > pack_to_stdout)
                progress_state = start_progress(_("Writing objects"), nr_result);
-       written_list = xmalloc(to_pack.nr_objects * sizeof(*written_list));
+       ALLOC_ARRAY(written_list, to_pack.nr_objects);
        write_order = compute_write_order();
 
        do {
@@ -2129,7 +2130,7 @@ static void prepare_pack(int window, int depth)
        if (!to_pack.nr_objects || !window || !depth)
                return;
 
-       delta_list = xmalloc(to_pack.nr_objects * sizeof(*delta_list));
+       ALLOC_ARRAY(delta_list, to_pack.nr_objects);
        nr_deltas = n = 0;
 
        for (i = 0; i < to_pack.nr_objects; i++) {
@@ -2277,33 +2278,23 @@ static void read_object_list_from_stdin(void)
 
 static void show_commit(struct commit *commit, void *data)
 {
-       add_object_entry(commit->object.sha1, OBJ_COMMIT, NULL, 0);
+       add_object_entry(commit->object.oid.hash, OBJ_COMMIT, NULL, 0);
        commit->object.flags |= OBJECT_ADDED;
 
        if (write_bitmap_index)
                index_commit_for_bitmap(commit);
 }
 
-static void show_object(struct object *obj,
-                       const struct name_path *path, const char *last,
-                       void *data)
+static void show_object(struct object *obj, const char *name, void *data)
 {
-       char *name = path_name(path, last);
-
        add_preferred_base_object(name);
-       add_object_entry(obj->sha1, obj->type, name, 0);
+       add_object_entry(obj->oid.hash, obj->type, name, 0);
        obj->flags |= OBJECT_ADDED;
-
-       /*
-        * We will have generated the hash from the name,
-        * but not saved a pointer to it - we can free it
-        */
-       free((char *)name);
 }
 
 static void show_edge(struct commit *commit)
 {
-       add_preferred_base(commit->object.sha1);
+       add_preferred_base(commit->object.oid.hash);
 }
 
 struct in_pack_object {
@@ -2319,7 +2310,7 @@ struct in_pack {
 
 static void mark_in_pack_object(struct object *object, struct packed_git *p, struct in_pack *in_pack)
 {
-       in_pack->array[in_pack->nr].offset = find_pack_entry_one(object->sha1, p);
+       in_pack->array[in_pack->nr].offset = find_pack_entry_one(object->oid.hash, p);
        in_pack->array[in_pack->nr].object = object;
        in_pack->nr++;
 }
@@ -2338,7 +2329,7 @@ static int ofscmp(const void *a_, const void *b_)
        else if (a->offset > b->offset)
                return 1;
        else
-               return hashcmp(a->object->sha1, b->object->sha1);
+               return oidcmp(&a->object->oid, &b->object->oid);
 }
 
 static void add_objects_in_unpacked_packs(struct rev_info *revs)
@@ -2376,7 +2367,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
                      ofscmp);
                for (i = 0; i < in_pack.nr; i++) {
                        struct object *o = in_pack.array[i].object;
-                       add_object_entry(o->sha1, o->type, "", 0);
+                       add_object_entry(o->oid.hash, o->type, "", 0);
                }
        }
        free(in_pack.array);
@@ -2480,16 +2471,15 @@ static int get_object_list_from_bitmap(struct rev_info *revs)
 }
 
 static void record_recent_object(struct object *obj,
-                                const struct name_path *path,
-                                const char *last,
+                                const char *name,
                                 void *data)
 {
-       sha1_array_append(&recent_objects, obj->sha1);
+       sha1_array_append(&recent_objects, obj->oid.hash);
 }
 
 static void record_recent_commit(struct commit *commit, void *data)
 {
-       sha1_array_append(&recent_objects, commit->object.sha1);
+       sha1_array_append(&recent_objects, commit->object.oid.hash);
 }
 
 static void get_object_list(int ac, const char **av)