static void fill_tracking_info(struct strbuf *stat, const char *branch_name, int show_upstream_ref) { int ours, theirs; struct branch *branch = branch_get(branch_name); if (!stat_tracking_info(branch, &ours, &theirs)) { if (branch && branch->merge && branch->merge[0]->dst && show_upstream_ref) strbuf_addf(stat, "[%s] ", shorten_unambiguous_ref(branch->merge[0]->dst, 0)); return; } strbuf_addch(stat, '['); if (show_upstream_ref) strbuf_addf(stat, "%s: ", shorten_unambiguous_ref(branch->merge[0]->dst, 0)); if (!ours) strbuf_addf(stat, "behind %d] ", theirs); else if (!theirs) strbuf_addf(stat, "ahead %d] ", ours); else strbuf_addf(stat, "ahead %d, behind %d] ", ours, theirs); }
/* * Return true when there is anything to report, otherwise false. */ int format_tracking_info(struct branch *branch, struct strbuf *sb) { int num_ours, num_theirs; const char *base; if (!stat_tracking_info(branch, &num_ours, &num_theirs)) return 0; base = branch->merge[0]->dst; if (!prefixcmp(base, "refs/remotes/")) { base += strlen("refs/remotes/"); } if (!num_theirs) strbuf_addf(sb, "Your branch is ahead of '%s' " "by %d commit%s.\n", base, num_ours, (num_ours == 1) ? "" : "s"); else if (!num_ours) strbuf_addf(sb, "Your branch is behind '%s' " "by %d commit%s, " "and can be fast-forwarded.\n", base, num_theirs, (num_theirs == 1) ? "" : "s"); else strbuf_addf(sb, "Your branch and '%s' have diverged,\n" "and have %d and %d different commit(s) each, " "respectively.\n", base, num_ours, num_theirs); return 1; }
static void wt_shortstatus_print_tracking(struct wt_status *s) { struct branch *branch; const char *header_color = color(WT_STATUS_HEADER, s); const char *branch_color_local = color(WT_STATUS_LOCAL_BRANCH, s); const char *branch_color_remote = color(WT_STATUS_REMOTE_BRANCH, s); const char *base; const char *branch_name; int num_ours, num_theirs; color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "## "); if (!s->branch) return; branch_name = s->branch; if (!prefixcmp(branch_name, "refs/heads/")) branch_name += 11; else if (!strcmp(branch_name, "HEAD")) { branch_name = _("HEAD (no branch)"); branch_color_local = color(WT_STATUS_NOBRANCH, s); } branch = branch_get(s->branch + 11); if (s->is_initial) color_fprintf(s->fp, header_color, _("Initial commit on ")); if (!stat_tracking_info(branch, &num_ours, &num_theirs)) { color_fprintf(s->fp, branch_color_local, "%s", branch_name); fputc(s->null_termination ? '\0' : '\n', s->fp); return; } base = branch->merge[0]->dst; base = shorten_unambiguous_ref(base, 0); color_fprintf(s->fp, branch_color_local, "%s", branch_name); color_fprintf(s->fp, header_color, "..."); color_fprintf(s->fp, branch_color_remote, "%s", base); color_fprintf(s->fp, header_color, " ["); if (!num_ours) { color_fprintf(s->fp, header_color, _("behind ")); color_fprintf(s->fp, branch_color_remote, "%d", num_theirs); } else if (!num_theirs) { color_fprintf(s->fp, header_color, _("ahead ")); color_fprintf(s->fp, branch_color_local, "%d", num_ours); } else { color_fprintf(s->fp, header_color, _("ahead ")); color_fprintf(s->fp, branch_color_local, "%d", num_ours); color_fprintf(s->fp, header_color, _(", behind ")); color_fprintf(s->fp, branch_color_remote, "%d", num_theirs); } color_fprintf(s->fp, header_color, "]"); fputc(s->null_termination ? '\0' : '\n', s->fp); }
static void fill_tracking_info(struct strbuf *stat, const char *branch_name) { int ours, theirs; struct branch *branch = branch_get(branch_name); if (!stat_tracking_info(branch, &ours, &theirs) || (!ours && !theirs)) return; if (!ours) strbuf_addf(stat, "[behind %d] ", theirs); else if (!theirs) strbuf_addf(stat, "[ahead %d] ", ours); else strbuf_addf(stat, "[ahead %d, behind %d] ", ours, theirs); }
static void fill_tracking_info(struct strbuf *stat, const char *branch_name, int show_upstream_ref) { int ours, theirs; char *ref = NULL; struct branch *branch = branch_get(branch_name); if (!stat_tracking_info(branch, &ours, &theirs)) { if (branch && branch->merge && branch->merge[0]->dst && show_upstream_ref) strbuf_addf(stat, "[%s] ", shorten_unambiguous_ref(branch->merge[0]->dst, 0)); return; } if (show_upstream_ref) ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0); if (!ours) { if (ref) strbuf_addf(stat, _("[%s: behind %d]"), ref, theirs); else strbuf_addf(stat, _("[behind %d]"), theirs); } else if (!theirs) { if (ref) strbuf_addf(stat, _("[%s: ahead %d]"), ref, ours); else strbuf_addf(stat, _("[ahead %d]"), ours); } else { if (ref) strbuf_addf(stat, _("[%s: ahead %d, behind %d]"), ref, ours, theirs); else strbuf_addf(stat, _("[ahead %d, behind %d]"), ours, theirs); } strbuf_addch(stat, ' '); free(ref); }
static void fill_tracking_info(struct strbuf *stat, const char *branch_name, int show_upstream_ref) { int ours, theirs; char *ref = NULL; struct branch *branch = branch_get(branch_name); struct strbuf fancy = STRBUF_INIT; int upstream_is_gone = 0; int added_decoration = 1; switch (stat_tracking_info(branch, &ours, &theirs)) { case 0: /* no base */ return; case -1: /* with "gone" base */ upstream_is_gone = 1; break; default: /* with base */ break; } if (show_upstream_ref) { ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0); if (want_color(branch_use_color)) strbuf_addf(&fancy, "%s%s%s", branch_get_color(BRANCH_COLOR_UPSTREAM), ref, branch_get_color(BRANCH_COLOR_RESET)); else strbuf_addstr(&fancy, ref); } if (upstream_is_gone) { if (show_upstream_ref) strbuf_addf(stat, _("[%s: gone]"), fancy.buf); else added_decoration = 0; } else if (!ours && !theirs) { if (show_upstream_ref) strbuf_addf(stat, _("[%s]"), fancy.buf); else added_decoration = 0; } else if (!ours) { if (show_upstream_ref) strbuf_addf(stat, _("[%s: behind %d]"), fancy.buf, theirs); else strbuf_addf(stat, _("[behind %d]"), theirs); } else if (!theirs) { if (show_upstream_ref) strbuf_addf(stat, _("[%s: ahead %d]"), fancy.buf, ours); else strbuf_addf(stat, _("[ahead %d]"), ours); } else { if (show_upstream_ref) strbuf_addf(stat, _("[%s: ahead %d, behind %d]"), fancy.buf, ours, theirs); else strbuf_addf(stat, _("[ahead %d, behind %d]"), ours, theirs); } strbuf_release(&fancy); if (added_decoration) strbuf_addch(stat, ' '); free(ref); }
static void wt_shortstatus_print_tracking(struct wt_status *s) { struct branch *branch; const char *header_color = color(WT_STATUS_HEADER, s); const char *branch_color_local = color(WT_STATUS_LOCAL_BRANCH, s); const char *branch_color_remote = color(WT_STATUS_REMOTE_BRANCH, s); const char *base; const char *branch_name; int num_ours, num_theirs; int upstream_is_gone = 0; color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "## "); if (!s->branch) return; branch_name = s->branch; if (starts_with(branch_name, "refs/heads/")) branch_name += 11; else if (!strcmp(branch_name, "HEAD")) { branch_name = _("HEAD (no branch)"); branch_color_local = color(WT_STATUS_NOBRANCH, s); } branch = branch_get(s->branch + 11); if (s->is_initial) color_fprintf(s->fp, header_color, _("Initial commit on ")); color_fprintf(s->fp, branch_color_local, "%s", branch_name); if (stat_tracking_info(branch, &num_ours, &num_theirs, &base) < 0) { if (!base) { fputc(s->null_termination ? '\0' : '\n', s->fp); return; } upstream_is_gone = 1; } base = shorten_unambiguous_ref(base, 0); color_fprintf(s->fp, header_color, "..."); color_fprintf(s->fp, branch_color_remote, "%s", base); free((char *)base); if (!upstream_is_gone && !num_ours && !num_theirs) { fputc(s->null_termination ? '\0' : '\n', s->fp); return; } #define LABEL(string) (s->no_gettext ? (string) : _(string)) color_fprintf(s->fp, header_color, " ["); if (upstream_is_gone) { color_fprintf(s->fp, header_color, LABEL(N_("gone"))); } else if (!num_ours) { color_fprintf(s->fp, header_color, LABEL(N_("behind "))); color_fprintf(s->fp, branch_color_remote, "%d", num_theirs); } else if (!num_theirs) { color_fprintf(s->fp, header_color, LABEL(N_(("ahead ")))); color_fprintf(s->fp, branch_color_local, "%d", num_ours); } else { color_fprintf(s->fp, header_color, LABEL(N_(("ahead ")))); color_fprintf(s->fp, branch_color_local, "%d", num_ours); color_fprintf(s->fp, header_color, ", %s", LABEL(N_("behind "))); color_fprintf(s->fp, branch_color_remote, "%d", num_theirs); } color_fprintf(s->fp, header_color, "]"); fputc(s->null_termination ? '\0' : '\n', s->fp); }