]> git.ipfire.org Git - thirdparty/git.git/blobdiff - wt-status.c
Replace all die("BUG: ...") calls by BUG() ones
[thirdparty/git.git] / wt-status.c
index f5debcd2b4f05c50d5e70efc95d10d95ca6372cd..26d037610eea90652dda57de971807280dce94ee 100644 (file)
@@ -136,6 +136,7 @@ void wt_status_prepare(struct wt_status *s)
        s->ignored.strdup_strings = 1;
        s->show_branch = -1;  /* unspecified */
        s->show_stash = 0;
+       s->ahead_behind_flags = AHEAD_BEHIND_UNSPECIFIED;
        s->display_comment_prefix = 0;
 }
 
@@ -263,7 +264,7 @@ static const char *wt_status_unmerged_status_string(int stagemask)
        case 7:
                return _("both modified:");
        default:
-               die("BUG: unhandled unmerged status %x", stagemask);
+               BUG("unhandled unmerged status %x", stagemask);
        }
 }
 
@@ -376,7 +377,7 @@ static void wt_longstatus_print_change_data(struct wt_status *s,
                status = d->worktree_status;
                break;
        default:
-               die("BUG: unhandled change_type %d in wt_longstatus_print_change_data",
+               BUG("unhandled change_type %d in wt_longstatus_print_change_data",
                    change_type);
        }
 
@@ -394,7 +395,7 @@ static void wt_longstatus_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);
+               BUG("unhandled diff status %c", status);
        len = label_width - utf8_strwidth(what);
        assert(len >= 0);
        if (one_name != two_name)
@@ -469,7 +470,7 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
                case DIFF_STATUS_COPIED:
                case DIFF_STATUS_RENAMED:
                        if (d->rename_status)
-                               die("BUG: multiple renames on the same target? how?");
+                               BUG("multiple renames on the same target? how?");
                        d->rename_source = xstrdup(p->one->path);
                        d->rename_score = p->score * 100 / MAX_SCORE;
                        d->rename_status = p->status;
@@ -483,7 +484,7 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
                        break;
 
                default:
-                       die("BUG: unhandled diff-files status '%c'", p->status);
+                       BUG("unhandled diff-files status '%c'", p->status);
                        break;
                }
 
@@ -546,7 +547,7 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
                case DIFF_STATUS_COPIED:
                case DIFF_STATUS_RENAMED:
                        if (d->rename_status)
-                               die("BUG: multiple renames on the same target? how?");
+                               BUG("multiple renames on the same target? how?");
                        d->rename_source = xstrdup(p->one->path);
                        d->rename_score = p->score * 100 / MAX_SCORE;
                        d->rename_status = p->status;
@@ -568,7 +569,7 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
                        break;
 
                default:
-                       die("BUG: unhandled diff-index status '%c'", p->status);
+                       BUG("unhandled diff-index status '%c'", p->status);
                        break;
                }
        }
@@ -1032,7 +1033,7 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
        if (!skip_prefix(s->branch, "refs/heads/", &branch_name))
                return;
        branch = branch_get(branch_name);
-       if (!format_tracking_info(branch, &sb))
+       if (!format_tracking_info(branch, &sb, s->ahead_behind_flags))
                return;
 
        i = 0;
@@ -1187,7 +1188,7 @@ static void abbrev_sha1_in_line(struct strbuf *line)
                strbuf_trim(split[1]);
                if (!get_oid(split[1]->buf, &oid)) {
                        strbuf_reset(split[1]);
-                       strbuf_add_unique_abbrev(split[1], oid.hash,
+                       strbuf_add_unique_abbrev(split[1], &oid,
                                                 DEFAULT_ABBREV);
                        strbuf_addch(split[1], ' ');
                        strbuf_reset(line);
@@ -1349,7 +1350,7 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
                                        const char *color)
 {
        status_printf_ln(s, color, _("You are currently cherry-picking commit %s."),
-                       find_unique_abbrev(state->cherry_pick_head_sha1, DEFAULT_ABBREV));
+                       find_unique_abbrev(&state->cherry_pick_head_oid, DEFAULT_ABBREV));
        if (s->hints) {
                if (has_unmerged(s))
                        status_printf_ln(s, color,
@@ -1368,7 +1369,7 @@ static void show_revert_in_progress(struct wt_status *s,
                                        const char *color)
 {
        status_printf_ln(s, color, _("You are currently reverting commit %s."),
-                        find_unique_abbrev(state->revert_head_sha1, DEFAULT_ABBREV));
+                        find_unique_abbrev(&state->revert_head_oid, DEFAULT_ABBREV));
        if (s->hints) {
                if (has_unmerged(s))
                        status_printf_ln(s, color,
@@ -1421,7 +1422,7 @@ static char *get_branch(const struct worktree *wt, const char *path)
                ;
        else if (!get_oid_hex(sb.buf, &oid)) {
                strbuf_reset(&sb);
-               strbuf_add_unique_abbrev(&sb, oid.hash, DEFAULT_ABBREV);
+               strbuf_add_unique_abbrev(&sb, &oid, DEFAULT_ABBREV);
        } else if (!strcmp(sb.buf, "detached HEAD")) /* rebase */
                goto got_nothing;
        else                    /* bisect */
@@ -1458,7 +1459,7 @@ static int grab_1st_switch(struct object_id *ooid, struct object_id *noid,
        if (!strcmp(cb->buf.buf, "HEAD")) {
                /* HEAD is relative. Resolve it to the right reflog entry. */
                strbuf_reset(&cb->buf);
-               strbuf_add_unique_abbrev(&cb->buf, noid->hash, DEFAULT_ABBREV);
+               strbuf_add_unique_abbrev(&cb->buf, noid, DEFAULT_ABBREV);
        }
        return 1;
 }
@@ -1488,10 +1489,10 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
                state->detached_from = xstrdup(from);
        } else
                state->detached_from =
-                       xstrdup(find_unique_abbrev(cb.noid.hash, DEFAULT_ABBREV));
-       hashcpy(state->detached_sha1, cb.noid.hash);
+                       xstrdup(find_unique_abbrev(&cb.noid, DEFAULT_ABBREV));
+       oidcpy(&state->detached_oid, &cb.noid);
        state->detached_at = !get_oid("HEAD", &oid) &&
-                            !hashcmp(oid.hash, state->detached_sha1);
+                            !oidcmp(&oid, &state->detached_oid);
 
        free(ref);
        strbuf_release(&cb.buf);
@@ -1550,13 +1551,13 @@ void wt_status_get_state(struct wt_status_state *state,
        } else if (!stat(git_path_cherry_pick_head(), &st) &&
                        !get_oid("CHERRY_PICK_HEAD", &oid)) {
                state->cherry_pick_in_progress = 1;
-               hashcpy(state->cherry_pick_head_sha1, oid.hash);
+               oidcpy(&state->cherry_pick_head_oid, &oid);
        }
        wt_status_check_bisect(NULL, state);
        if (!stat(git_path_revert_head(), &st) &&
            !get_oid("REVERT_HEAD", &oid)) {
                state->revert_in_progress = 1;
-               hashcpy(state->revert_head_sha1, oid.hash);
+               oidcpy(&state->revert_head_oid, &oid);
        }
 
        if (get_detached_from)
@@ -1793,7 +1794,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
        const char *base;
        char *short_base;
        const char *branch_name;
-       int num_ours, num_theirs;
+       int num_ours, num_theirs, sti;
        int upstream_is_gone = 0;
 
        color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "## ");
@@ -1819,7 +1820,9 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
 
        color_fprintf(s->fp, branch_color_local, "%s", branch_name);
 
-       if (stat_tracking_info(branch, &num_ours, &num_theirs, &base) < 0) {
+       sti = stat_tracking_info(branch, &num_ours, &num_theirs, &base,
+                                s->ahead_behind_flags);
+       if (sti < 0) {
                if (!base)
                        goto conclude;
 
@@ -1831,12 +1834,14 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
        color_fprintf(s->fp, branch_color_remote, "%s", short_base);
        free(short_base);
 
-       if (!upstream_is_gone && !num_ours && !num_theirs)
+       if (!upstream_is_gone && !sti)
                goto conclude;
 
        color_fprintf(s->fp, header_color, " [");
        if (upstream_is_gone) {
                color_fprintf(s->fp, header_color, LABEL(N_("gone")));
+       } else if (s->ahead_behind_flags == AHEAD_BEHIND_QUICK) {
+               color_fprintf(s->fp, header_color, LABEL(N_("different")));
        } else if (!num_ours) {
                color_fprintf(s->fp, header_color, LABEL(N_("behind ")));
                color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
@@ -1905,18 +1910,19 @@ static void wt_porcelain_print(struct wt_status *s)
  *
  *    <upstream> ::= the upstream branch name, when set.
  *
- *       <ahead> ::= integer ahead value, when upstream set
- *                   and the commit is present (not gone).
- *
- *      <behind> ::= integer behind value, when upstream set
- *                   and commit is present.
+ *       <ahead> ::= integer ahead value or '?'.
  *
+ *      <behind> ::= integer behind value or '?'.
  *
  * The end-of-line is defined by the -z flag.
  *
  *                 <eol> ::= NUL when -z,
  *                           LF when NOT -z.
  *
+ * When an upstream is set and present, the 'branch.ab' line will
+ * be printed with the ahead/behind counts for the branch and the
+ * upstream.  When AHEAD_BEHIND_QUICK is requested and the branches
+ * are different, '?' will be substituted for the actual count.
  */
 static void wt_porcelain_v2_print_tracking(struct wt_status *s)
 {
@@ -1956,14 +1962,25 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)
                /* Lookup stats on the upstream tracking branch, if set. */
                branch = branch_get(branch_name);
                base = NULL;
-               ab_info = (stat_tracking_info(branch, &nr_ahead, &nr_behind, &base) == 0);
+               ab_info = stat_tracking_info(branch, &nr_ahead, &nr_behind,
+                                            &base, s->ahead_behind_flags);
                if (base) {
                        base = shorten_unambiguous_ref(base, 0);
                        fprintf(s->fp, "# branch.upstream %s%c", base, eol);
                        free((char *)base);
 
-                       if (ab_info)
-                               fprintf(s->fp, "# branch.ab +%d -%d%c", nr_ahead, nr_behind, eol);
+                       if (ab_info > 0) {
+                               /* different */
+                               if (nr_ahead || nr_behind)
+                                       fprintf(s->fp, "# branch.ab +%d -%d%c",
+                                               nr_ahead, nr_behind, eol);
+                               else
+                                       fprintf(s->fp, "# branch.ab +? -?%c",
+                                               eol);
+                       } else if (!ab_info) {
+                               /* same */
+                               fprintf(s->fp, "# branch.ab +0 -0%c", eol);
+                       }
                }
        }
 
@@ -2141,7 +2158,7 @@ static void wt_porcelain_v2_print_unmerged_entry(
        case 6: key = "AA"; break; /* both added */
        case 7: key = "UU"; break; /* both modified */
        default:
-               die("BUG: unhandled unmerged status %x", d->stagemask);
+               BUG("unhandled unmerged status %x", d->stagemask);
        }
 
        /*
@@ -2168,7 +2185,7 @@ static void wt_porcelain_v2_print_unmerged_entry(
                sum |= (1 << (stage - 1));
        }
        if (sum != d->stagemask)
-               die("BUG: observed stagemask 0x%x != expected stagemask 0x%x", sum, d->stagemask);
+               BUG("observed stagemask 0x%x != expected stagemask 0x%x", sum, d->stagemask);
 
        if (s->null_termination)
                path_index = it->string;
@@ -2272,7 +2289,7 @@ void wt_status_print(struct wt_status *s)
                wt_porcelain_v2_print(s);
                break;
        case STATUS_FORMAT_UNSPECIFIED:
-               die("BUG: finalize_deferred_config() should have been called");
+               BUG("finalize_deferred_config() should have been called");
                break;
        case STATUS_FORMAT_NONE:
        case STATUS_FORMAT_LONG: