From: Junio C Hamano Date: Fri, 19 Jul 2019 18:30:23 +0000 (-0700) Subject: Merge branch 'jl/status-reduce-vertical-blank' X-Git-Tag: v2.23.0-rc0~29 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/7b098429355bb3271f9ffdf73b97f2ef82794fea?hp=-c Merge branch 'jl/status-reduce-vertical-blank' Extra blank lines in "git status" output have been reduced. * jl/status-reduce-vertical-blank: status: remove the empty line after hints --- 7b098429355bb3271f9ffdf73b97f2ef82794fea diff --combined t/t7512-status-help.sh index 60eea88c41,bf0b2c8bdb..e01c285cbf --- a/t/t7512-status-help.sh +++ b/t/t7512-status-help.sh @@@ -33,7 -33,6 +33,6 @@@ You have unmerged paths Unmerged paths: (use "git add ..." to mark resolution) - both modified: main.txt no changes added to commit (use "git add" and/or "git commit -a") @@@ -54,7 -53,6 +53,6 @@@ All conflicts fixed but you are still m (use "git commit" to conclude merge) Changes to be committed: - modified: main.txt Untracked files not listed (use -u option to show untracked files) @@@ -87,7 -85,6 +85,6 @@@ You are currently rebasing branch '\''r Unmerged paths: (use "git restore --staged ..." to unstage) (use "git add ..." to mark resolution) - both modified: main.txt no changes added to commit (use "git add" and/or "git commit -a") @@@ -111,7 -108,6 +108,6 @@@ You are currently rebasing branch '\''r Changes to be committed: (use "git restore --staged ..." to unstage) - modified: main.txt Untracked files not listed (use -u option to show untracked files) @@@ -150,7 -146,6 +146,6 @@@ You are currently rebasing branch '\''r Unmerged paths: (use "git restore --staged ..." to unstage) (use "git add ..." to mark resolution) - both modified: main.txt no changes added to commit (use "git add" and/or "git commit -a") @@@ -177,7 -172,6 +172,6 @@@ You are currently rebasing branch '\''r Changes to be committed: (use "git restore --staged ..." to unstage) - modified: main.txt Untracked files not listed (use -u option to show untracked files) @@@ -247,7 -241,6 +241,6 @@@ You are currently splitting a commit wh Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) - modified: main.txt no changes added to commit (use "git add" and/or "git commit -a") @@@ -355,7 -348,6 +348,6 @@@ You are currently splitting a commit wh Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) - modified: main.txt no changes added to commit (use "git add" and/or "git commit -a") @@@ -454,7 -446,6 +446,6 @@@ You are currently splitting a commit wh Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) - modified: main.txt no changes added to commit (use "git add" and/or "git commit -a") @@@ -558,7 -549,6 +549,6 @@@ You are currently splitting a commit wh Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) - modified: main.txt no changes added to commit (use "git add" and/or "git commit -a") @@@ -747,7 -737,6 +737,6 @@@ You are currently cherry-picking commi Unmerged paths: (use "git add ..." to mark resolution) - both modified: main.txt no changes added to commit (use "git add" and/or "git commit -a") @@@ -771,7 -760,6 +760,6 @@@ You are currently cherry-picking commi (use "git cherry-pick --abort" to cancel the cherry-pick operation) Changes to be committed: - modified: main.txt Untracked files not listed (use -u option to show untracked files) @@@ -780,40 -768,6 +768,40 @@@ EO test_i18ncmp expected actual ' +test_expect_success 'status when cherry-picking after committing conflict resolution' ' + git reset --hard cherry_branch && + test_when_finished "git cherry-pick --abort" && + test_must_fail git cherry-pick cherry_branch_second one_cherry && + echo end >main.txt && + git commit -a && + cat >expected <actual && + test_i18ncmp expected actual +' + +test_expect_success 'status shows cherry-pick with invalid oid' ' + mkdir .git/sequencer && + test_write_lines "pick invalid-oid" >.git/sequencer/todo && + git status --untracked-files=no >actual 2>err && + git cherry-pick --quit && + test_must_be_empty err && + test_i18ncmp expected actual +' + +test_expect_success 'status does not show error if .git/sequencer is a file' ' + test_when_finished "rm .git/sequencer" && + test_write_lines hello >.git/sequencer && + git status --untracked-files=no 2>err && + test_must_be_empty err +' + test_expect_success 'status showing detached at and from a tag' ' test_commit atag tagging && git checkout atag && @@@ -852,7 -806,6 +840,6 @@@ You are currently reverting commit $TO_ Unmerged paths: (use "git restore --staged ..." to unstage) (use "git add ..." to mark resolution) - both modified: to-revert.txt no changes added to commit (use "git add" and/or "git commit -a") @@@ -872,7 -825,6 +859,6 @@@ You are currently reverting commit $TO_ Changes to be committed: (use "git restore --staged ..." to unstage) - modified: to-revert.txt Untracked files not listed (use -u option to show untracked files) @@@ -886,24 -838,6 +872,24 @@@ test_expect_success 'status after rever cat >expected <<\EOF && On branch master nothing to commit (use -u to show untracked files) +EOF + git status --untracked-files=no >actual && + test_i18ncmp expected actual +' + +test_expect_success 'status while reverting after committing conflict resolution' ' + test_when_finished "git revert --abort" && + git reset --hard new && + test_must_fail git revert old new && + echo reverted >to-revert.txt && + git commit -a && + cat >expected <actual && test_i18ncmp expected actual diff --combined wt-status.c index 7d776f8a97,ddab6b93be..9f6c65a580 --- a/wt-status.c +++ b/wt-status.c @@@ -17,9 -17,6 +17,9 @@@ #include "utf8.h" #include "worktree.h" #include "lockfile.h" +#include "sequencer.h" + +#define AB_DELAY_WARNING_IN_MS (2 * 1000) static const char cut_line[] = "------------------------ >8 ------------------------\n"; @@@ -202,7 -199,6 +202,6 @@@ static void wt_longstatus_print_unmerge } else { status_printf_ln(s, c, _(" (use \"git add/rm ...\" as appropriate to mark resolution)")); } - status_printf_ln(s, c, "%s", ""); } static void wt_longstatus_print_cached_header(struct wt_status *s) @@@ -224,7 -220,6 +223,6 @@@ s->reference); } else status_printf_ln(s, c, _(" (use \"git rm --cached ...\" to unstage)")); - status_printf_ln(s, c, "%s", ""); } static void wt_longstatus_print_dirty_header(struct wt_status *s, @@@ -243,7 -238,6 +241,6 @@@ status_printf_ln(s, c, _(" (use \"git restore ...\" to discard changes in working directory)")); if (has_dirty_submodules) status_printf_ln(s, c, _(" (commit or discard the untracked or modified content in submodules)")); - status_printf_ln(s, c, "%s", ""); } static void wt_longstatus_print_other_header(struct wt_status *s, @@@ -255,7 -249,6 +252,6 @@@ if (!s->hints) return; status_printf_ln(s, c, _(" (use \"git %s ...\" to include in what will be committed)"), how); - status_printf_ln(s, c, "%s", ""); } static void wt_longstatus_print_trailer(struct wt_status *s) @@@ -1021,19 -1014,13 +1017,19 @@@ size_t wt_status_locate_end(const char return len; } -void wt_status_add_cut_line(FILE *fp) +void wt_status_append_cut_line(struct strbuf *buf) { const char *explanation = _("Do not modify or remove the line above.\nEverything below it will be ignored."); + + strbuf_commented_addf(buf, "%s", cut_line); + strbuf_add_commented_lines(buf, explanation, strlen(explanation)); +} + +void wt_status_add_cut_line(FILE *fp) +{ struct strbuf buf = STRBUF_INIT; - fprintf(fp, "%c %s", comment_line_char, cut_line); - strbuf_add_commented_lines(&buf, explanation, strlen(explanation)); + wt_status_append_cut_line(&buf); fputs(buf.buf, fp); strbuf_release(&buf); } @@@ -1099,29 -1086,14 +1095,29 @@@ static void wt_longstatus_print_trackin struct branch *branch; char comment_line_string[3]; int i; + uint64_t t_begin = 0; assert(s->branch && !s->is_initial); if (!skip_prefix(s->branch, "refs/heads/", &branch_name)) return; branch = branch_get(branch_name); + + t_begin = getnanotime(); + if (!format_tracking_info(branch, &sb, s->ahead_behind_flags)) return; + if (advice_status_ahead_behind_warning && + s->ahead_behind_flags == AHEAD_BEHIND_FULL) { + uint64_t t_delta_in_ms = (getnanotime() - t_begin) / 1000000; + if (t_delta_in_ms > AB_DELAY_WARNING_IN_MS) { + strbuf_addf(&sb, _("\n" + "It took %.2f seconds to compute the branch ahead/behind values.\n" + "You can use '--no-ahead-behind' to avoid this.\n"), + t_delta_in_ms / 1000.0); + } + } + i = 0; if (s->display_comment_prefix) { comment_line_string[i++] = comment_line_char; @@@ -1244,9 -1216,7 +1240,9 @@@ static void abbrev_sha1_in_line(struct int i; if (starts_with(line->buf, "exec ") || - starts_with(line->buf, "x ")) + starts_with(line->buf, "x ") || + starts_with(line->buf, "label ") || + starts_with(line->buf, "l ")) return; split = strbuf_split_max(line, ' ', 3); @@@ -1418,22 -1388,12 +1414,22 @@@ static void show_rebase_in_progress(str 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(&s->state.cherry_pick_head_oid, DEFAULT_ABBREV)); + if (is_null_oid(&s->state.cherry_pick_head_oid)) + status_printf_ln(s, color, + _("Cherry-pick currently in progress.")); + else + status_printf_ln(s, color, + _("You are currently cherry-picking commit %s."), + find_unique_abbrev(&s->state.cherry_pick_head_oid, + DEFAULT_ABBREV)); + if (s->hints) { if (has_unmerged(s)) status_printf_ln(s, color, _(" (fix conflicts and run \"git cherry-pick --continue\")")); + else if (is_null_oid(&s->state.cherry_pick_head_oid)) + status_printf_ln(s, color, + _(" (run \"git cherry-pick --continue\" to continue)")); else status_printf_ln(s, color, _(" (all conflicts fixed: run \"git cherry-pick --continue\")")); @@@ -1446,21 -1406,12 +1442,21 @@@ 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(&s->state.revert_head_oid, DEFAULT_ABBREV)); + if (is_null_oid(&s->state.revert_head_oid)) + status_printf_ln(s, color, + _("Revert currently in progress.")); + else + status_printf_ln(s, color, + _("You are currently reverting commit %s."), + find_unique_abbrev(&s->state.revert_head_oid, + DEFAULT_ABBREV)); if (s->hints) { if (has_unmerged(s)) status_printf_ln(s, color, _(" (fix conflicts and run \"git revert --continue\")")); + else if (is_null_oid(&s->state.revert_head_oid)) + status_printf_ln(s, color, + _(" (run \"git revert --continue\" to continue)")); else status_printf_ln(s, color, _(" (all conflicts fixed: run \"git revert --continue\")")); @@@ -1631,7 -1582,6 +1627,7 @@@ void wt_status_get_state(struct reposit { struct stat st; struct object_id oid; + enum replay_action action; if (!stat(git_path_merge_head(r), &st)) { wt_status_check_rebase(NULL, state); @@@ -1649,15 -1599,7 +1645,15 @@@ state->revert_in_progress = 1; oidcpy(&state->revert_head_oid, &oid); } - + if (!sequencer_get_last_command(r, &action)) { + if (action == REPLAY_PICK) { + state->cherry_pick_in_progress = 1; + oidcpy(&state->cherry_pick_head_oid, &null_oid); + } else { + state->revert_in_progress = 1; + oidcpy(&state->revert_head_oid, &null_oid); + } + } if (get_detached_from) wt_status_get_detached_from(r, state); } @@@ -1705,9 -1647,9 +1701,9 @@@ static void wt_longstatus_print(struct } else if (s->state.detached_from) { branch_name = s->state.detached_from; if (s->state.detached_at) - on_what = _("HEAD detached at "); + on_what = HEAD_DETACHED_AT; else - on_what = _("HEAD detached from "); + on_what = HEAD_DETACHED_FROM; } else { branch_name = ""; on_what = _("Not currently on any branch."); @@@ -1917,7 -1859,7 +1913,7 @@@ static void wt_shortstatus_print_tracki color_fprintf(s->fp, branch_color_local, "%s", branch_name); sti = stat_tracking_info(branch, &num_ours, &num_theirs, &base, - s->ahead_behind_flags); + 0, s->ahead_behind_flags); if (sti < 0) { if (!base) goto conclude; @@@ -2056,7 -1998,7 +2052,7 @@@ static void wt_porcelain_v2_print_track branch = branch_get(branch_name); base = NULL; ab_info = stat_tracking_info(branch, &nr_ahead, &nr_behind, - &base, s->ahead_behind_flags); + &base, 0, s->ahead_behind_flags); if (base) { base = shorten_unambiguous_ref(base, 0); fprintf(s->fp, "# branch.upstream %s%c", base, eol); @@@ -2105,7 -2047,9 +2101,7 @@@ static void wt_porcelain_v2_submodule_s /* * Fix-up changed entries before we print them. */ -static void wt_porcelain_v2_fix_up_changed( - struct string_list_item *it, - struct wt_status *s) +static void wt_porcelain_v2_fix_up_changed(struct string_list_item *it) { struct wt_status_change_data *d = it->util; @@@ -2165,7 -2109,7 +2161,7 @@@ static void wt_porcelain_v2_print_chang char submodule_token[5]; char sep_char, eol_char; - wt_porcelain_v2_fix_up_changed(it, s); + wt_porcelain_v2_fix_up_changed(it); wt_porcelain_v2_submodule_state(d, submodule_token); key[0] = d->index_status ? d->index_status : '.';