clean up name allocation in prepare_revision_walk
[gitweb.git] / revision.c
index 615535c98453336323a437530132f27824b51ac2..01cc276fa2bdf58eded0cc8a7210042e75600c5a 100644 (file)
@@ -300,7 +300,7 @@ static struct commit *handle_commit(struct rev_info *revs,
                        revs->limited = 1;
                }
                if (revs->show_source && !commit->util)
-                       commit->util = (void *) name;
+                       commit->util = xstrdup(name);
                return commit;
        }
 
@@ -473,7 +473,7 @@ static int rev_compare_tree(struct rev_info *revs,
                 * If we are simplifying by decoration, then the commit
                 * is worth showing if it has a tag pointing at it.
                 */
-               if (lookup_decoration(&name_decoration, &commit->object))
+               if (get_name_decoration(&commit->object))
                        return REV_TREE_DIFFERENT;
                /*
                 * A commit that is not pointed by a tag is uninteresting
@@ -1397,7 +1397,7 @@ static void prepare_show_merge(struct rev_info *revs)
                        continue;
                if (ce_path_match(ce, &revs->prune_data, NULL)) {
                        prune_num++;
-                       prune = xrealloc(prune, sizeof(*prune) * prune_num);
+                       REALLOC_ARRAY(prune, prune_num);
                        prune[prune_num-2] = ce->name;
                        prune[prune_num-1] = NULL;
                }
@@ -2656,15 +2656,16 @@ void reset_revision_walk(void)
 
 int prepare_revision_walk(struct rev_info *revs)
 {
-       int nr = revs->pending.nr;
-       struct object_array_entry *e, *list;
+       int i;
+       struct object_array old_pending;
        struct commit_list **next = &revs->commits;
 
-       e = list = revs->pending.objects;
+       memcpy(&old_pending, &revs->pending, sizeof(old_pending));
        revs->pending.nr = 0;
        revs->pending.alloc = 0;
        revs->pending.objects = NULL;
-       while (--nr >= 0) {
+       for (i = 0; i < old_pending.nr; i++) {
+               struct object_array_entry *e = old_pending.objects + i;
                struct commit *commit = handle_commit(revs, e->item, e->name);
                if (commit) {
                        if (!(commit->object.flags & SEEN)) {
@@ -2672,10 +2673,9 @@ int prepare_revision_walk(struct rev_info *revs)
                                next = commit_list_append(commit, next);
                        }
                }
-               e++;
        }
        if (!revs->leak_pending)
-               free(list);
+               object_array_clear(&old_pending);
 
        /* Signal whether we need per-parent treesame decoration */
        if (revs->simplify_merges ||