]> git.ipfire.org Git - thirdparty/git.git/blobdiff - revision.c
Add several uses of get_object_hash.
[thirdparty/git.git] / revision.c
index af2a18ed7485ea83170409ce55f81473ee606221..897e9bd0a752f82a02c84f0e1162fc0c3218dae5 100644 (file)
@@ -38,7 +38,7 @@ char *path_name(const struct name_path *path, const char *name)
        }
        n = xmalloc(len);
        m = n + len - (nlen + 1);
-       strcpy(m, name);
+       memcpy(m, name, nlen + 1);
        for (p = path; p; p = p->up) {
                if (p->elem_len) {
                        m -= p->elem_len + 1;
@@ -153,10 +153,7 @@ void mark_parents_uninteresting(struct commit *commit)
                commit_list_insert(l->item, &parents);
 
        while (parents) {
-               struct commit *commit = parents->item;
-               l = parents;
-               parents = parents->next;
-               free(l);
+               struct commit *commit = pop_commit(&parents);
 
                while (commit) {
                        /*
@@ -285,7 +282,7 @@ static struct commit *handle_commit(struct rev_info *revs,
                        add_pending_object(revs, object, tag->tag);
                if (!tag->tagged)
                        die("bad tag");
-               object = parse_object(tag->tagged->sha1);
+               object = parse_object(get_object_hash(*tag->tagged));
                if (!object) {
                        if (flags & UNINTERESTING)
                                return NULL;
@@ -513,7 +510,7 @@ static int rev_compare_tree(struct rev_info *revs,
 
        tree_difference = REV_TREE_SAME;
        DIFF_OPT_CLR(&revs->pruning, HAS_CHANGES);
-       if (diff_tree_sha1(t1->object.sha1, t2->object.sha1, "",
+       if (diff_tree_sha1(get_object_hash(t1->object), get_object_hash(t2->object), "",
                           &revs->pruning) < 0)
                return REV_TREE_DIFFERENT;
        return tree_difference;
@@ -529,7 +526,7 @@ static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit)
 
        tree_difference = REV_TREE_SAME;
        DIFF_OPT_CLR(&revs->pruning, HAS_CHANGES);
-       retval = diff_tree_sha1(NULL, t1->object.sha1, "", &revs->pruning);
+       retval = diff_tree_sha1(NULL, get_object_hash(t1->object), "", &revs->pruning);
 
        return retval >= 0 && (tree_difference == REV_TREE_SAME);
 }
@@ -1102,14 +1099,10 @@ static int limit_list(struct rev_info *revs)
        }
 
        while (list) {
-               struct commit_list *entry = list;
-               struct commit *commit = list->item;
+               struct commit *commit = pop_commit(&list);
                struct object *obj = &commit->object;
                show_early_output_fn_t show;
 
-               list = list->next;
-               free(entry);
-
                if (commit == interesting_cache)
                        interesting_cache = NULL;
 
@@ -1385,7 +1378,7 @@ static int add_parents_only(struct rev_info *revs, const char *arg_, int flags)
                        break;
                if (!((struct tag*)it)->tagged)
                        return 0;
-               hashcpy(sha1, ((struct tag*)it)->tagged->sha1);
+               hashcpy(sha1, get_object_hash(*((struct tag*)it)->tagged));
        }
        if (it->type != OBJ_COMMIT)
                return 0;
@@ -1562,10 +1555,10 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
 
                                a = (a_obj->type == OBJ_COMMIT
                                     ? (struct commit *)a_obj
-                                    : lookup_commit_reference(a_obj->sha1));
+                                    : lookup_commit_reference(get_object_hash(*a_obj)));
                                b = (b_obj->type == OBJ_COMMIT
                                     ? (struct commit *)b_obj
-                                    : lookup_commit_reference(b_obj->sha1));
+                                    : lookup_commit_reference(get_object_hash(*b_obj)));
                                if (!a || !b)
                                        goto missing;
                                exclude = get_merge_bases(a, b);
@@ -2733,10 +2726,7 @@ static void simplify_merges(struct rev_info *revs)
                yet_to_do = NULL;
                tail = &yet_to_do;
                while (list) {
-                       commit = list->item;
-                       next = list->next;
-                       free(list);
-                       list = next;
+                       commit = pop_commit(&list);
                        tail = simplify_one(revs, commit, tail);
                }
        }
@@ -2748,10 +2738,7 @@ static void simplify_merges(struct rev_info *revs)
        while (list) {
                struct merge_simplify_state *st;
 
-               commit = list->item;
-               next = list->next;
-               free(list);
-               list = next;
+               commit = pop_commit(&list);
                st = locate_simplify_state(revs, commit);
                if (st->simplified == commit)
                        tail = &commit_list_insert(commit, tail)->next;
@@ -2951,7 +2938,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
        if (opt->show_notes) {
                if (!buf.len)
                        strbuf_addstr(&buf, message);
-               format_display_notes(commit->object.sha1, &buf, encoding, 1);
+               format_display_notes(get_object_hash(commit->object), &buf, encoding, 1);
        }
 
        /*
@@ -2981,7 +2968,7 @@ enum commit_action get_commit_action(struct rev_info *revs, struct commit *commi
 {
        if (commit->object.flags & SHOWN)
                return commit_ignore;
-       if (revs->unpacked && has_sha1_pack(commit->object.sha1))
+       if (revs->unpacked && has_sha1_pack(get_object_hash(commit->object)))
                return commit_ignore;
        if (revs->show_all)
                return commit_show;
@@ -3125,11 +3112,7 @@ static struct commit *get_revision_1(struct rev_info *revs)
                return NULL;
 
        do {
-               struct commit_list *entry = revs->commits;
-               struct commit *commit = entry->item;
-
-               revs->commits = entry->next;
-               free(entry);
+               struct commit *commit = pop_commit(&revs->commits);
 
                if (revs->reflog_info) {
                        save_parents(revs, commit);