Merge branch 'sh/p4-multi-depot'
[gitweb.git] / revision.c
index 3f65614963e515ed9971cae10b0bc33382cf7186..0a282f533b3e225a996221d614de8bdc960092a3 100644 (file)
 #include "commit-slab.h"
 #include "dir.h"
 #include "cache-tree.h"
+#include "bisect.h"
 
 volatile show_early_output_fn_t show_early_output;
 
+static const char *term_bad;
+static const char *term_good;
+
 char *path_name(const struct name_path *path, const char *name)
 {
        const struct name_path *p;
@@ -34,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;
@@ -82,7 +86,7 @@ void show_object_with_name(FILE *out, struct object *obj,
        leaf.elem = component;
        leaf.elem_len = strlen(component);
 
-       fprintf(out, "%s ", sha1_to_hex(obj->sha1));
+       fprintf(out, "%s ", oid_to_hex(&obj->oid));
        show_path_truncated(out, &leaf);
        fputc('\n', out);
 }
@@ -102,10 +106,10 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
        struct name_entry entry;
        struct object *obj = &tree->object;
 
-       if (!has_sha1_file(obj->sha1))
+       if (!has_object_file(&obj->oid))
                return;
        if (parse_tree(tree) < 0)
-               die("bad tree %s", sha1_to_hex(obj->sha1));
+               die("bad tree %s", oid_to_hex(&obj->oid));
 
        init_tree_desc(&desc, tree->buffer, tree->size);
        while (tree_entry(&desc, &entry)) {
@@ -131,10 +135,12 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
 
 void mark_tree_uninteresting(struct tree *tree)
 {
-       struct object *obj = &tree->object;
+       struct object *obj;
 
        if (!tree)
                return;
+
+       obj = &tree->object;
        if (obj->flags & UNINTERESTING)
                return;
        obj->flags |= UNINTERESTING;
@@ -160,7 +166,7 @@ void mark_parents_uninteresting(struct commit *commit)
                         * it is popped next time around, we won't be trying
                         * to parse it and get an error.
                         */
-                       if (!has_sha1_file(commit->object.sha1))
+                       if (!has_object_file(&commit->object.oid))
                                commit->object.parsed = 1;
 
                        if (commit->object.flags & UNINTERESTING)
@@ -278,19 +284,18 @@ 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(tag->tagged->oid.hash);
                if (!object) {
                        if (flags & UNINTERESTING)
                                return NULL;
-                       die("bad object %s", sha1_to_hex(tag->tagged->sha1));
+                       die("bad object %s", oid_to_hex(&tag->tagged->oid));
                }
                object->flags |= flags;
                /*
                 * We'll handle the tagged object by looping or dropping
                 * through to the non-tag handlers below. Do not
-                * propagate data from the tag's pending entry.
+                * propagate path data from the tag's pending entry.
                 */
-               name = "";
                path = NULL;
                mode = 0;
        }
@@ -506,7 +511,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(t1->object.oid.hash, t2->object.oid.hash, "",
                           &revs->pruning) < 0)
                return REV_TREE_DIFFERENT;
        return tree_difference;
@@ -522,7 +527,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, t1->object.oid.hash, "", &revs->pruning);
 
        return retval >= 0 && (tree_difference == REV_TREE_SAME);
 }
@@ -606,7 +611,7 @@ static unsigned update_treesame(struct rev_info *revs, struct commit *commit)
 
                st = lookup_decoration(&revs->treesame, &commit->object);
                if (!st)
-                       die("update_treesame %s", sha1_to_hex(commit->object.sha1));
+                       die("update_treesame %s", oid_to_hex(&commit->object.oid));
                relevant_parents = 0;
                relevant_change = irrelevant_change = 0;
                for (p = commit->parents, n = 0; p; n++, p = p->next) {
@@ -704,8 +709,8 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
                }
                if (parse_commit(p) < 0)
                        die("cannot simplify commit %s (because of %s)",
-                           sha1_to_hex(commit->object.sha1),
-                           sha1_to_hex(p->object.sha1));
+                           oid_to_hex(&commit->object.oid),
+                           oid_to_hex(&p->object.oid));
                switch (rev_compare_tree(revs, p, commit)) {
                case REV_TREE_SAME:
                        if (!revs->simplify_history || !relevant_commit(p)) {
@@ -737,8 +742,8 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
                                 */
                                if (parse_commit(p) < 0)
                                        die("cannot simplify commit %s (invalid %s)",
-                                           sha1_to_hex(commit->object.sha1),
-                                           sha1_to_hex(p->object.sha1));
+                                           oid_to_hex(&commit->object.oid),
+                                           oid_to_hex(&p->object.oid));
                                p->parents = NULL;
                        }
                /* fallthrough */
@@ -750,7 +755,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
                                irrelevant_change = 1;
                        continue;
                }
-               die("bad tree compare for commit %s", sha1_to_hex(commit->object.sha1));
+               die("bad tree compare for commit %s", oid_to_hex(&commit->object.oid));
        }
 
        /*
@@ -1185,7 +1190,7 @@ static void add_rev_cmdline_list(struct rev_info *revs,
 {
        while (commit_list) {
                struct object *object = &commit_list->item->object;
-               add_rev_cmdline(revs, object, sha1_to_hex(object->sha1),
+               add_rev_cmdline(revs, object, oid_to_hex(&object->oid),
                                whence, flags);
                commit_list = commit_list->next;
        }
@@ -1374,7 +1379,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, ((struct tag*)it)->tagged->oid.hash);
        }
        if (it->type != OBJ_COMMIT)
                return 0;
@@ -1431,7 +1436,7 @@ static void add_pending_commit_list(struct rev_info *revs,
        while (commit_list) {
                struct object *object = &commit_list->item->object;
                object->flags |= flags;
-               add_pending_object(revs, object, sha1_to_hex(object->sha1));
+               add_pending_object(revs, object, oid_to_hex(&object->oid));
                commit_list = commit_list->next;
        }
 }
@@ -1551,10 +1556,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(a_obj->oid.hash));
                                b = (b_obj->type == OBJ_COMMIT
                                     ? (struct commit *)b_obj
-                                    : lookup_commit_reference(b_obj->sha1));
+                                    : lookup_commit_reference(b_obj->oid.hash));
                                if (!a || !b)
                                        goto missing;
                                exclude = get_merge_bases(a, b);
@@ -1989,10 +1994,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
        } else if (!strcmp(arg, "--full-history")) {
                revs->simplify_history = 0;
        } else if (!strcmp(arg, "--relative-date")) {
-               revs->date_mode = DATE_RELATIVE;
+               revs->date_mode.type = DATE_RELATIVE;
                revs->date_mode_explicit = 1;
        } else if ((argcount = parse_long_opt("date", argv, &optarg))) {
-               revs->date_mode = parse_date_format(optarg);
+               parse_date_format(optarg, &revs->date_mode);
                revs->date_mode_explicit = 1;
                return argcount;
        } else if (!strcmp(arg, "--log-size")) {
@@ -2069,14 +2074,23 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
        ctx->argc -= n;
 }
 
+static int for_each_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data, const char *term) {
+       struct strbuf bisect_refs = STRBUF_INIT;
+       int status;
+       strbuf_addf(&bisect_refs, "refs/bisect/%s", term);
+       status = for_each_ref_in_submodule(submodule, bisect_refs.buf, fn, cb_data);
+       strbuf_release(&bisect_refs);
+       return status;
+}
+
 static int for_each_bad_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)
 {
-       return for_each_ref_in_submodule(submodule, "refs/bisect/bad", fn, cb_data);
+       return for_each_bisect_ref(submodule, fn, cb_data, term_bad);
 }
 
 static int for_each_good_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)
 {
-       return for_each_ref_in_submodule(submodule, "refs/bisect/good", fn, cb_data);
+       return for_each_bisect_ref(submodule, fn, cb_data, term_good);
 }
 
 static int handle_revision_pseudo_opt(const char *submodule,
@@ -2105,6 +2119,7 @@ static int handle_revision_pseudo_opt(const char *submodule,
                handle_refs(submodule, revs, *flags, for_each_branch_ref_submodule);
                clear_ref_exclusion(&revs->ref_excludes);
        } else if (!strcmp(arg, "--bisect")) {
+               read_bisect_terms(&term_bad, &term_good);
                handle_refs(submodule, revs, *flags, for_each_bad_bisect_ref);
                handle_refs(submodule, revs, *flags ^ (UNINTERESTING | BOTTOM), for_each_good_bisect_ref);
                revs->bisect = 1;
@@ -2924,7 +2939,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(commit->object.oid.hash, &buf, encoding, 1);
        }
 
        /*
@@ -2954,7 +2969,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(commit->object.oid.hash))
                return commit_ignore;
        if (revs->show_all)
                return commit_show;
@@ -3080,7 +3095,7 @@ static void track_linear(struct rev_info *revs, struct commit *commit)
                struct commit_list *p;
                for (p = revs->previous_parents; p; p = p->next)
                        if (p->item == NULL || /* first commit */
-                           !hashcmp(p->item->object.sha1, commit->object.sha1))
+                           !oidcmp(&p->item->object.oid, &commit->object.oid))
                                break;
                revs->linear = p != NULL;
        }
@@ -3118,7 +3133,7 @@ static struct commit *get_revision_1(struct rev_info *revs)
                        if (add_parents_to_list(revs, commit, &revs->commits, NULL) < 0) {
                                if (!revs->ignore_missing_links)
                                        die("Failed to traverse parents of commit %s",
-                                               sha1_to_hex(commit->object.sha1));
+                                               oid_to_hex(&commit->object.oid));
                        }
                }
 
@@ -3127,7 +3142,7 @@ static struct commit *get_revision_1(struct rev_info *revs)
                        continue;
                case commit_error:
                        die("Failed to simplify parents of commit %s",
-                           sha1_to_hex(commit->object.sha1));
+                           oid_to_hex(&commit->object.oid));
                default:
                        if (revs->track_linear)
                                track_linear(revs, commit);