From 80f537f79c16efeb7b92b3409ede434a230b5679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 25 Apr 2019 16:45:58 +0700 Subject: doc: promote "git restore" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new command "git restore" (together with "git switch") are added to avoid the confusion of one-command-do-all "git checkout" for new users. They are also helpful to avoid ambiguous context. For these reasons, promote it everywhere possible. This includes documentation, suggestions/advice from other commands. One nice thing about git-restore is the ability to restore "everything", so it can be used in "git status" advice instead of both "git checkout" and "git reset". The three commands suggested by "git status" are add, rm and restore. "git checkout" is also removed from "git help" (i.e. it's no longer considered a commonly used command) Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- wt-status.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 445a36204a..19fd1add75 100644 --- a/wt-status.c +++ b/wt-status.c @@ -178,9 +178,15 @@ static void wt_longstatus_print_unmerged_header(struct wt_status *s) return; if (s->whence != FROM_COMMIT) ; - else if (!s->is_initial) - status_printf_ln(s, c, _(" (use \"git reset %s ...\" to unstage)"), s->reference); - else + else if (!s->is_initial) { + if (!strcmp(s->reference, "HEAD")) + status_printf_ln(s, c, + _(" (use \"git restore --staged ...\" to unstage)")); + else + status_printf_ln(s, c, + _(" (use \"git restore --source=%s --staged ...\" to unstage)"), + s->reference); + } else status_printf_ln(s, c, _(" (use \"git rm --cached ...\" to unstage)")); if (!both_deleted) { @@ -205,9 +211,15 @@ static void wt_longstatus_print_cached_header(struct wt_status *s) return; if (s->whence != FROM_COMMIT) ; /* NEEDSWORK: use "git reset --unresolve"??? */ - else if (!s->is_initial) - status_printf_ln(s, c, _(" (use \"git reset %s ...\" to unstage)"), s->reference); - else + else if (!s->is_initial) { + if (!strcmp(s->reference, "HEAD")) + status_printf_ln(s, c + , _(" (use \"git restore --staged ...\" to unstage)")); + else + status_printf_ln(s, c, + _(" (use \"git restore --source=%s --staged ...\" to unstage)"), + s->reference); + } else status_printf_ln(s, c, _(" (use \"git rm --cached ...\" to unstage)")); status_printf_ln(s, c, "%s", ""); } @@ -225,7 +237,7 @@ static void wt_longstatus_print_dirty_header(struct wt_status *s, status_printf_ln(s, c, _(" (use \"git add ...\" to update what will be committed)")); else status_printf_ln(s, c, _(" (use \"git add/rm ...\" to update what will be committed)")); - status_printf_ln(s, c, _(" (use \"git checkout -- ...\" to discard changes in working directory)")); + 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", ""); -- cgit v1.2.3 From 13a178129ffe91b4d2443c7950a399a634488225 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 9 May 2019 17:30:19 -0400 Subject: wt-status: drop unused status parameter The v2_fix_up_changed() function doesn't actually need to see the wt_status struct. It's possible that could change in the future, but this is a static-local function with one caller. It would be easy to read-add it back then. Let's drop the unused parameter. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- wt-status.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index f4fa982638..4c365ca6fd 100644 --- a/wt-status.c +++ b/wt-status.c @@ -2045,9 +2045,7 @@ static void wt_porcelain_v2_submodule_state( /* * 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; @@ -2107,7 +2105,7 @@ static void wt_porcelain_v2_print_changed_entry( 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 : '.'; -- cgit v1.2.3 From 28438e84e046984afc76dc891a49bd0862d555f7 Mon Sep 17 00:00:00 2001 From: Matthew DeVore Date: Tue, 18 Jun 2019 15:29:15 -0700 Subject: ref-filter: sort detached HEAD lines firstly Before this patch, "git branch" would put "(HEAD detached...)" and "(no branch, rebasing...)" lines before all the other branches *in most cases* except for when using Chinese-language messages. zh_CN generally uses a full-width "(" symbol (codepoint FF08) to match the full-width proportions of Chinese characters, and the translated strings we had did use them. This meant that the detached HEAD line would appear after all local refs and even after the remote refs if there were any. AFAIK, it is sometimes not jarring to see the half-width parenthesis in "full-width" text as in the CJK languages, for instance when there are no characters preceding or following the parenthesized text fragment. By removing the parenthesis from the localizable text, we can share strings with wt-status.c and remove a cautionary comment to translators. Remove the ( from the localizable portion of messages so the sorting happens properly regardless of locale. Helped-by: Johannes Schindelin Helped-by: Jonathan Nieder Signed-off-by: Matthew DeVore Signed-off-by: Junio C Hamano --- wt-status.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 1f564b12d2..9e24855b82 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1628,9 +1628,9 @@ static void wt_longstatus_print(struct wt_status *s) } 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."); -- cgit v1.2.3 From b2f5171ecc2feb4192acd80f5a6b05c06e099e97 Mon Sep 17 00:00:00 2001 From: John Lin Date: Tue, 4 Jun 2019 07:02:21 -0700 Subject: status: remove the empty line after hints Before this patch, there is inconsistency between the status messages with hints and the ones without hints: there is an empty line between the title and the file list if hints are presented, but there isn't one if there are no hints. This patch remove the inconsistency by removing the empty lines even if hints are presented. Signed-off-by: John Lin Signed-off-by: Junio C Hamano --- wt-status.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 19fd1add75..ddab6b93be 100644 --- a/wt-status.c +++ b/wt-status.c @@ -199,7 +199,6 @@ static void wt_longstatus_print_unmerged_header(struct wt_status *s) } 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) @@ -221,7 +220,6 @@ static void wt_longstatus_print_cached_header(struct wt_status *s) 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, @@ -240,7 +238,6 @@ static void wt_longstatus_print_dirty_header(struct wt_status *s, 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, @@ -252,7 +249,6 @@ static void wt_longstatus_print_other_header(struct wt_status *s, 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) -- cgit v1.2.3 From 0a53561a6221f989b210797e62e83fb7260fa42c Mon Sep 17 00:00:00 2001 From: Jeff Hostetler Date: Tue, 18 Jun 2019 13:21:27 -0700 Subject: status: warn when a/b calculation takes too long The ahead/behind calculation in 'git status' can be slow in some cases. Users may not realize that there are ways to avoid this computation, especially if they are not using the information. Add a warning that appears if this calculation takes more than two seconds. The warning can be disabled through the new config setting advice.statusAheadBehind. Signed-off-by: Jeff Hostetler Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- wt-status.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'wt-status.c') diff --git a/wt-status.c b/wt-status.c index 0bccef542f..d4e45f9e6a 100644 --- a/wt-status.c +++ b/wt-status.c @@ -19,6 +19,8 @@ #include "lockfile.h" #include "sequencer.h" +#define AB_DELAY_WARNING_IN_MS (2 * 1000) + static const char cut_line[] = "------------------------ >8 ------------------------\n"; @@ -1085,14 +1087,29 @@ static void wt_longstatus_print_tracking(struct wt_status *s) 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; -- cgit v1.2.3