From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthieu Moy Subject: [PATCH v5 3/4] status: give more information during rebase -i Date: Wed, 1 Jul 2015 10:30:32 +0200 Message-ID: <1435739433-18853-3-git-send-email-Matthieu.Moy@imag.fr> References: <1435739433-18853-1-git-send-email-Matthieu.Moy@imag.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: git@vger.kernel.org, remi.lespinet@ensimag.grenoble-inp.fr, guillaume.pages@ensimag.grenoble-inp.fr, louis--alexandre.stuber@ensimag.grenoble-inp.fr, antoine.delaite@ensimag.grenoble-inp.fr, Matthieu Moy To: gitster@pobox.com X-From: git-owner@vger.kernel.org Wed Jul 01 10:31:08 2015 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZADQA-0000Up-IF for gcvg-git-2@plane.gmane.org; Wed, 01 Jul 2015 10:31:07 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753025AbbGAIbA convert rfc822-to-quoted-printable (ORCPT ); Wed, 1 Jul 2015 04:31:00 -0400 Received: from mx1.imag.fr ([129.88.30.5]:34716 "EHLO shiva.imag.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753439AbbGAIau (ORCPT ); Wed, 1 Jul 2015 04:30:50 -0400 Received: from clopinette.imag.fr (clopinette.imag.fr [129.88.34.215]) by shiva.imag.fr (8.13.8/8.13.8) with ESMTP id t618UipZ004616 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 1 Jul 2015 10:30:44 +0200 Received: from anie.imag.fr (anie.imag.fr [129.88.7.32]) by clopinette.imag.fr (8.13.8/8.13.8) with ESMTP id t618Ui9p009955; Wed, 1 Jul 2015 10:30:44 +0200 Received: from moy by anie.imag.fr with local (Exim 4.80) (envelope-from ) id 1ZADPo-0005ce-P1; Wed, 01 Jul 2015 10:30:44 +0200 X-Mailer: git-send-email 2.5.0.rc0.7.ge1edd74 In-Reply-To: <1435739433-18853-1-git-send-email-Matthieu.Moy@imag.fr> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0.1 (shiva.imag.fr [129.88.30.5]); Wed, 01 Jul 2015 10:30:44 +0200 (CEST) X-IMAG-MailScanner-Information: Please contact MI2S MIM for more information X-MailScanner-ID: t618UipZ004616 X-IMAG-MailScanner: Found to be clean X-IMAG-MailScanner-SpamCheck: X-IMAG-MailScanner-From: moy@imag.fr MailScanner-NULL-Check: 1436344245.30519@NJTnZ4Tdoht7aYDeXLlcXw Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: =46rom: Guillaume Pag=C3=A8s git status gives more information during rebase -i, about the list of command that are done during the rebase. It displays the two last commands executed and the two next lines to be executed. It also gives hints to find the whole files in .git directory. Signed-off-by: Guillaume Pag=C3=A8s Signed-off-by: Junio C Hamano Signed-off-by: Matthieu Moy --- Added sha1-shortening code. t/t7512-status-help.sh | 111 +++++++++++++++++++++++++++++++++++++++++= ++++++++ wt-status.c | 109 +++++++++++++++++++++++++++++++++++++++++= +++++++ 2 files changed, 220 insertions(+) diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh index 190656d..9be0235 100755 --- a/t/t7512-status-help.sh +++ b/t/t7512-status-help.sh @@ -134,9 +134,13 @@ test_expect_success 'prepare for rebase_i_conflict= s' ' test_expect_success 'status during rebase -i when conflicts unresolved= ' ' test_when_finished "git rebase --abort" && ONTO=3D$(git rev-parse --short rebase_i_conflicts) && + LAST_COMMIT=3D$(git rev-parse --short rebase_i_conflicts_second) && test_must_fail git rebase -i rebase_i_conflicts && cat >expected <expected <expected <expected <expected <expected <expected <expected <expected <expected <expected <expected <expected <expected <buf, "exec ") || + starts_with(line->buf, "x ")) + return; + + split =3D strbuf_split_max(line, ' ', 3); + if (split[0] && split[1]) { + unsigned char sha1[20]; + const char *abbrev; + + /* + * strbuf_split_max left a space. Trim it and re-add + * it after abbreviation. + */ + strbuf_trim(split[1]); + if (!get_sha1(split[1]->buf, sha1)) { + abbrev =3D find_unique_abbrev(sha1, DEFAULT_ABBREV); + strbuf_reset(split[1]); + strbuf_addf(split[1], "%s ", abbrev); + } + strbuf_reset(line); + for (i =3D 0; split[i]; i++) + strbuf_addstr(line, split[i]->buf); + } + for (i =3D 0; split[i]; i++) + strbuf_release(split[i]); + +} + +static void read_rebase_todolist(const char *fname, struct string_list= *lines) +{ + struct strbuf line =3D STRBUF_INIT; + FILE *f =3D fopen(git_path(fname), "r"); + + if (!f) + die_errno("Could not open file %s for reading", git_path(fname)); + while (!strbuf_getline(&line, f, '\n')) { + stripspace(&line, 1); + /* Remove trailing \n */ + strbuf_rtrim(&line); + abbrev_sha1_in_line(&line); + string_list_append(lines, line.buf); + } + string_list_remove_empty_items(lines, 1); +} + +static void show_rebase_information(struct wt_status *s, + struct wt_status_state *state, + const char *color) +{ + if (state->rebase_interactive_in_progress) { + int i; + int nr_lines_to_show =3D 2; + + struct string_list have_done =3D STRING_LIST_INIT_DUP; + struct string_list yet_to_do =3D STRING_LIST_INIT_DUP; + + read_rebase_todolist("rebase-merge/done", &have_done); + read_rebase_todolist("rebase-merge/git-rebase-todo", &yet_to_do); + + if (have_done.nr =3D=3D 0) + status_printf_ln(s, color, _("No commands done.")); + else { + status_printf_ln(s, color, + Q_("Last command done (%d command done):", + "Last commands done (%d commands done):", + have_done.nr), + have_done.nr); + for (i =3D (have_done.nr > nr_lines_to_show) + ? have_done.nr - nr_lines_to_show : 0; + i < have_done.nr; + i++) + status_printf_ln(s, color, " %s", have_done.items[i].string); + if (have_done.nr > nr_lines_to_show && s->hints) + status_printf_ln(s, color, + _(" (see more in file %s)"), git_path("rebase-merge/done")); + } + + if (yet_to_do.nr =3D=3D 0) + status_printf_ln(s, color, + _("No commands remaining.")); + else { + status_printf_ln(s, color, + Q_("Next command to do (%d remaining command):", + "Next commands to do (%d remaining commands):", + yet_to_do.nr), + yet_to_do.nr); + for (i =3D 0; i < nr_lines_to_show && i < yet_to_do.nr; i++) + status_printf_ln(s, color, " %s", yet_to_do.items[i].string); + if (s->hints) + status_printf_ln(s, color, + _(" (use \"git rebase --edit-todo\" to view and edit)")); + } + string_list_clear(&yet_to_do, 0); + string_list_clear(&have_done, 0); + } +} + static void print_rebase_state(struct wt_status *s, struct wt_status_state *state, const char *color) @@ -1047,6 +1155,7 @@ static void show_rebase_in_progress(struct wt_sta= tus *s, { struct stat st; =20 + show_rebase_information(s, state, color); if (has_unmerged(s)) { print_rebase_state(s, state, color); if (s->hints) { --=20 2.5.0.rc0.7.ge1edd74