show-branch: use skip_prefix to drop magic numbers
[gitweb.git] / wt-status.c
index b96be25966c32c0e7a5d1521955a5fdf89462288..7004a2d588769b76e95c07c8471569b2d6bf6c56 100644 (file)
@@ -263,7 +263,7 @@ static const char *wt_status_unmerged_status_string(int stagemask)
        case 7:
                return _("both modified:");
        default:
-               die(_("bug: unhandled unmerged status %x"), stagemask);
+               die("BUG: unhandled unmerged status %x", stagemask);
        }
 }
 
@@ -367,11 +367,11 @@ static void wt_status_print_change_data(struct wt_status *s,
                if (d->new_submodule_commits || d->dirty_submodule) {
                        strbuf_addstr(&extra, " (");
                        if (d->new_submodule_commits)
-                               strbuf_addf(&extra, _("new commits, "));
+                               strbuf_addstr(&extra, _("new commits, "));
                        if (d->dirty_submodule & DIRTY_SUBMODULE_MODIFIED)
-                               strbuf_addf(&extra, _("modified content, "));
+                               strbuf_addstr(&extra, _("modified content, "));
                        if (d->dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
-                               strbuf_addf(&extra, _("untracked content, "));
+                               strbuf_addstr(&extra, _("untracked content, "));
                        strbuf_setlen(&extra, extra.len - 2);
                        strbuf_addch(&extra, ')');
                }
@@ -388,7 +388,7 @@ static void wt_status_print_change_data(struct wt_status *s,
        status_printf(s, color(WT_STATUS_HEADER, s), "\t");
        what = wt_status_diff_status_string(status);
        if (!what)
-               die(_("bug: unhandled diff status %c"), status);
+               die("BUG: unhandled diff status %c", status);
        len = label_width - utf8_strwidth(what);
        assert(len >= 0);
        if (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED)
@@ -432,7 +432,8 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
                        d->worktree_status = p->status;
                d->dirty_submodule = p->two->dirty_submodule;
                if (S_ISGITLINK(p->two->mode))
-                       d->new_submodule_commits = !!hashcmp(p->one->sha1, p->two->sha1);
+                       d->new_submodule_commits = !!oidcmp(&p->one->oid,
+                                                           &p->two->oid);
        }
 }
 
@@ -1052,7 +1053,6 @@ static void abbrev_sha1_in_line(struct strbuf *line)
        split = strbuf_split_max(line, ' ', 3);
        if (split[0] && split[1]) {
                unsigned char sha1[20];
-               const char *abbrev;
 
                /*
                 * strbuf_split_max left a space. Trim it and re-add
@@ -1060,9 +1060,10 @@ static void abbrev_sha1_in_line(struct strbuf *line)
                 */
                strbuf_trim(split[1]);
                if (!get_sha1(split[1]->buf, sha1)) {
-                       abbrev = find_unique_abbrev(sha1, DEFAULT_ABBREV);
                        strbuf_reset(split[1]);
-                       strbuf_addf(split[1], "%s ", abbrev);
+                       strbuf_add_unique_abbrev(split[1], sha1,
+                                                DEFAULT_ABBREV);
+                       strbuf_addch(split[1], ' ');
                        strbuf_reset(line);
                        for (i = 0; split[i]; i++)
                                strbuf_addbuf(line, split[i]);
@@ -1285,10 +1286,8 @@ static char *get_branch(const struct worktree *wt, const char *path)
        else if (starts_with(sb.buf, "refs/"))
                ;
        else if (!get_sha1_hex(sb.buf, sha1)) {
-               const char *abbrev;
-               abbrev = find_unique_abbrev(sha1, DEFAULT_ABBREV);
                strbuf_reset(&sb);
-               strbuf_addstr(&sb, abbrev);
+               strbuf_add_unique_abbrev(&sb, sha1, DEFAULT_ABBREV);
        } else if (!strcmp(sb.buf, "detached HEAD")) /* rebase */
                goto got_nothing;
        else                    /* bisect */
@@ -1325,8 +1324,7 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
        if (!strcmp(cb->buf.buf, "HEAD")) {
                /* HEAD is relative. Resolve it to the right reflog entry. */
                strbuf_reset(&cb->buf);
-               strbuf_addstr(&cb->buf,
-                             find_unique_abbrev(nsha1, DEFAULT_ABBREV));
+               strbuf_add_unique_abbrev(&cb->buf, nsha1, DEFAULT_ABBREV);
        }
        return 1;
 }