Makefile: stop pretending to support rpmbuild
[gitweb.git] / revision.c
index f6caef067220e9ecae7cc1b21b7b01380544c066..8b2dfe3160784f9780cf541a674fe89100d38a93 100644 (file)
@@ -25,69 +25,13 @@ 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;
-       char *n, *m;
-       int nlen = strlen(name);
-       int len = nlen + 1;
-
-       for (p = path; p; p = p->up) {
-               if (p->elem_len)
-                       len += p->elem_len + 1;
-       }
-       n = xmalloc(len);
-       m = n + len - (nlen + 1);
-       strcpy(m, name);
-       for (p = path; p; p = p->up) {
-               if (p->elem_len) {
-                       m -= p->elem_len + 1;
-                       memcpy(m, p->elem, p->elem_len);
-                       m[p->elem_len] = '/';
-               }
-       }
-       return n;
-}
-
-static int show_path_component_truncated(FILE *out, const char *name, int len)
+void show_object_with_name(FILE *out, struct object *obj, const char *name)
 {
-       int cnt;
-       for (cnt = 0; cnt < len; cnt++) {
-               int ch = name[cnt];
-               if (!ch || ch == '\n')
-                       return -1;
-               fputc(ch, out);
-       }
-       return len;
-}
+       const char *p;
 
-static int show_path_truncated(FILE *out, const struct name_path *path)
-{
-       int emitted, ours;
-
-       if (!path)
-               return 0;
-       emitted = show_path_truncated(out, path->up);
-       if (emitted < 0)
-               return emitted;
-       if (emitted)
-               fputc('/', out);
-       ours = show_path_component_truncated(out, path->elem, path->elem_len);
-       if (ours < 0)
-               return ours;
-       return ours || emitted;
-}
-
-void show_object_with_name(FILE *out, struct object *obj,
-                          const struct name_path *path, const char *component)
-{
-       struct name_path leaf;
-       leaf.up = (struct name_path *)path;
-       leaf.elem = component;
-       leaf.elem_len = strlen(component);
-
-       fprintf(out, "%s ", sha1_to_hex(obj->sha1));
-       show_path_truncated(out, &leaf);
+       fprintf(out, "%s ", oid_to_hex(&obj->oid));
+       for (p = name; *p && *p != '\n'; p++)
+               fputc(*p, out);
        fputc('\n', out);
 }
 
@@ -106,10 +50,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)) {
@@ -166,7 +110,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)
@@ -284,19 +228,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;
        }
@@ -512,7 +455,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;
@@ -528,7 +471,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);
 }
@@ -541,7 +484,7 @@ struct treesame_state {
 static struct treesame_state *initialise_treesame(struct rev_info *revs, struct commit *commit)
 {
        unsigned n = commit_list_count(commit->parents);
-       struct treesame_state *st = xcalloc(1, sizeof(*st) + n);
+       struct treesame_state *st = xcalloc(1, st_add(sizeof(*st), n));
        st->nparents = n;
        add_decoration(&revs->treesame, &commit->object, st);
        return st;
@@ -612,7 +555,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) {
@@ -710,8 +653,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)) {
@@ -743,8 +686,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 */
@@ -756,7 +699,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));
        }
 
        /*
@@ -1191,7 +1134,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;
        }
@@ -1380,7 +1323,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;
@@ -1437,7 +1380,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;
        }
 }
@@ -1557,10 +1500,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);
@@ -1636,10 +1579,7 @@ static void append_prune_data(struct cmdline_pathspec *prune, const char **av)
 static void read_pathspec_from_stdin(struct rev_info *revs, struct strbuf *sb,
                                     struct cmdline_pathspec *prune)
 {
-       while (strbuf_getwholeline(sb, stdin, '\n') != EOF) {
-               int len = sb->len;
-               if (len && sb->buf[len - 1] == '\n')
-                       sb->buf[--len] = '\0';
+       while (strbuf_getline(sb, stdin) != EOF) {
                ALLOC_GROW(prune->path, prune->nr + 1, prune->alloc);
                prune->path[prune->nr++] = xstrdup(sb->buf);
        }
@@ -1656,10 +1596,8 @@ static void read_revisions_from_stdin(struct rev_info *revs,
        warn_on_object_refname_ambiguity = 0;
 
        strbuf_init(&sb, 1000);
-       while (strbuf_getwholeline(&sb, stdin, '\n') != EOF) {
+       while (strbuf_getline(&sb, stdin) != EOF) {
                int len = sb.len;
-               if (len && sb.buf[len - 1] == '\n')
-                       sb.buf[--len] = '\0';
                if (!len)
                        break;
                if (sb.buf[0] == '-') {
@@ -2050,7 +1988,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
        } else if (!strcmp(arg, "--ignore-missing")) {
                revs->ignore_missing = 1;
        } else {
-               int opts = diff_opt_parse(&revs->diffopt, argv, argc);
+               int opts = diff_opt_parse(&revs->diffopt, argv, argc, revs->prefix);
                if (!opts)
                        unkv[(*unkc)++] = arg;
                return opts;
@@ -2940,7 +2878,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);
        }
 
        /*
@@ -2970,7 +2908,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;
@@ -3096,7 +3034,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;
        }
@@ -3134,7 +3072,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));
                        }
                }
 
@@ -3143,7 +3081,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);