diff options
Diffstat (limited to 'wt-status.c')
-rw-r--r-- | wt-status.c | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/wt-status.c b/wt-status.c index f5debcd2b4..50815e5faf 100644 --- a/wt-status.c +++ b/wt-status.c @@ -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; } @@ -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); + } } } |