git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/4] status: give more information during rebase -i
  2015-06-03 22:00 [PATCH 1/4] status: factor two rebase-related messages together Guillaume Pagès
@ 2015-06-03 22:00 ` Guillaume Pagès
  2015-06-04  8:06   ` Matthieu Moy
  0 siblings, 1 reply; 11+ messages in thread
From: Guillaume Pagès @ 2015-06-03 22:00 UTC (permalink / raw)
  To: git
  Cc: Remi Galan, Remi Lespinet, Guillaume Pages,
	Louis-Alexandre Stuber, Antoine Delaite, Matthieu Moy

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.
---
 t/t7512-status-help.sh | 111 +++++++++++++++++++++++++++++++++++++++++++++++++
 wt-status.c            |  90 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 201 insertions(+)

diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh
index 190656d..4dd201a 100755
--- a/t/t7512-status-help.sh
+++ b/t/t7512-status-help.sh
@@ -134,9 +134,13 @@ test_expect_success 'prepare for rebase_i_conflicts' '
 test_expect_success 'status during rebase -i when conflicts unresolved' '
 	test_when_finished "git rebase --abort" &&
 	ONTO=$(git rev-parse --short rebase_i_conflicts) &&
+	LAST_COMMIT=$(git rev-parse rebase_i_conflicts_second) &&
 	test_must_fail git rebase -i rebase_i_conflicts &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command(s) done (1 command(s) done):
+   pick $LAST_COMMIT one_second
+No command remaining.
 You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
   (fix conflicts and then run "git rebase --continue")
   (use "git rebase --skip" to skip this patch)
@@ -159,10 +163,14 @@ test_expect_success 'status during rebase -i after resolving conflicts' '
 	git reset --hard rebase_i_conflicts_second &&
 	test_when_finished "git rebase --abort" &&
 	ONTO=$(git rev-parse --short rebase_i_conflicts) &&
+	LAST_COMMIT=$(git rev-parse rebase_i_conflicts_second) &&
 	test_must_fail git rebase -i rebase_i_conflicts &&
 	git add main.txt &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command(s) done (1 command(s) done):
+   pick $LAST_COMMIT one_second
+No command remaining.
 You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
   (all conflicts fixed: run "git rebase --continue")
 
@@ -183,7 +191,9 @@ test_expect_success 'status when rebasing -i in edit mode' '
 	git checkout -b rebase_i_edit &&
 	test_commit one_rebase_i main.txt one &&
 	test_commit two_rebase_i main.txt two &&
+	COMMIT2=$(git rev-parse rebase_i_edit) &&
 	test_commit three_rebase_i main.txt three &&
+	COMMIT3=$(git rev-parse rebase_i_edit) &&
 	FAKE_LINES="1 edit 2" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
@@ -191,6 +201,10 @@ test_expect_success 'status when rebasing -i in edit mode' '
 	git rebase -i HEAD~2 &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command(s) done (2 command(s) done):
+   pick $COMMIT2 two_rebase_i
+   edit $COMMIT3 three_rebase_i
+No command remaining.
 You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -207,8 +221,11 @@ test_expect_success 'status when splitting a commit' '
 	git checkout -b split_commit &&
 	test_commit one_split main.txt one &&
 	test_commit two_split main.txt two &&
+	COMMIT2=$(git rev-parse split_commit) &&
 	test_commit three_split main.txt three &&
+	COMMIT3=$(git rev-parse split_commit) &&
 	test_commit four_split main.txt four &&
+	COMMIT4=$(git rev-parse split_commit) &&
 	FAKE_LINES="1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
@@ -217,6 +234,12 @@ test_expect_success 'status when splitting a commit' '
 	git reset HEAD^ &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command(s) done (2 command(s) done):
+   pick $COMMIT2 two_split
+   edit $COMMIT3 three_split
+Next command(s) to do (1 remaining command(s)):
+   pick $COMMIT4 four_split
+  (use git rebase --edit-todo to view and edit)
 You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
   (Once your working directory is clean, run "git rebase --continue")
 
@@ -239,7 +262,9 @@ test_expect_success 'status after editing the last commit with --amend during a
 	test_commit one_amend main.txt one &&
 	test_commit two_amend main.txt two &&
 	test_commit three_amend main.txt three &&
+	COMMIT3=$(git rev-parse amend_last) &&
 	test_commit four_amend main.txt four &&
+	COMMIT4=$(git rev-parse amend_last) &&
 	FAKE_LINES="1 2 edit 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
@@ -248,6 +273,11 @@ test_expect_success 'status after editing the last commit with --amend during a
 	git commit --amend -m "foo" &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command(s) done (3 command(s) done):
+   pick $COMMIT3 three_amend
+   edit $COMMIT4 four_amend
+  (see more at .git/rebase-merge/done)
+No command remaining.
 You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -273,11 +303,20 @@ test_expect_success 'status: (continue first edit) second edit' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git rebase --continue &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command(s) done (2 command(s) done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command(s) to do (1 remaining command(s)):
+   pick $COMMIT4 four_edits
+  (use git rebase --edit-todo to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -294,12 +333,21 @@ test_expect_success 'status: (continue first edit) second edit and split' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git rebase --continue &&
 	git reset HEAD^ &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command(s) done (2 command(s) done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command(s) to do (1 remaining command(s)):
+   pick $COMMIT4 four_edits
+  (use git rebase --edit-todo to view and edit)
 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (Once your working directory is clean, run "git rebase --continue")
 
@@ -321,12 +369,21 @@ test_expect_success 'status: (continue first edit) second edit and amend' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git rebase --continue &&
 	git commit --amend -m "foo" &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command(s) done (2 command(s) done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command(s) to do (1 remaining command(s)):
+   pick $COMMIT4 four_edits
+  (use git rebase --edit-todo to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -343,12 +400,21 @@ test_expect_success 'status: (amend first edit) second edit' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git commit --amend -m "a" &&
 	git rebase --continue &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command(s) done (2 command(s) done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command(s) to do (1 remaining command(s)):
+   pick $COMMIT4 four_edits
+  (use git rebase --edit-todo to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -366,12 +432,21 @@ test_expect_success 'status: (amend first edit) second edit and split' '
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	git rebase -i HEAD~3 &&
 	git commit --amend -m "b" &&
 	git rebase --continue &&
 	git reset HEAD^ &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command(s) done (2 command(s) done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command(s) to do (1 remaining command(s)):
+   pick $COMMIT4 four_edits
+  (use git rebase --edit-todo to view and edit)
 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (Once your working directory is clean, run "git rebase --continue")
 
@@ -393,6 +468,9 @@ test_expect_success 'status: (amend first edit) second edit and amend' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git commit --amend -m "c" &&
@@ -400,6 +478,12 @@ test_expect_success 'status: (amend first edit) second edit and amend' '
 	git commit --amend -m "d" &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command(s) done (2 command(s) done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command(s) to do (1 remaining command(s)):
+   pick $COMMIT4 four_edits
+  (use git rebase --edit-todo to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -416,6 +500,9 @@ test_expect_success 'status: (split first edit) second edit' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git reset HEAD^ &&
@@ -424,6 +511,12 @@ test_expect_success 'status: (split first edit) second edit' '
 	git rebase --continue &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command(s) done (2 command(s) done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command(s) to do (1 remaining command(s)):
+   pick $COMMIT4 four_edits
+  (use git rebase --edit-todo to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -440,6 +533,9 @@ test_expect_success 'status: (split first edit) second edit and split' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git reset HEAD^ &&
@@ -449,6 +545,12 @@ test_expect_success 'status: (split first edit) second edit and split' '
 	git reset HEAD^ &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command(s) done (2 command(s) done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command(s) to do (1 remaining command(s)):
+   pick $COMMIT4 four_edits
+  (use git rebase --edit-todo to view and edit)
 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (Once your working directory is clean, run "git rebase --continue")
 
@@ -470,6 +572,9 @@ test_expect_success 'status: (split first edit) second edit and amend' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git reset HEAD^ &&
@@ -479,6 +584,12 @@ test_expect_success 'status: (split first edit) second edit and amend' '
 	git commit --amend -m "h" &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command(s) done (2 command(s) done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command(s) to do (1 remaining command(s)):
+   pick $COMMIT4 four_edits
+  (use git rebase --edit-todo to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
diff --git a/wt-status.c b/wt-status.c
index c83eca5..35ca55e 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1026,12 +1026,102 @@ static int split_commit_in_progress(struct wt_status *s)
 	return split_in_progress;
 }
 
+void get_two_last_lines(char *filename, int *numlines, char **lines)
+{
+	struct strbuf buf = STRBUF_INIT;
+	FILE *fp;
+
+	*numlines = 0;
+	fp = fopen(git_path("%s", filename), "r");
+	if (!fp) {
+		strbuf_release(&buf);
+		return;
+	}
+	while (strbuf_getline(&buf, fp, '\n') != EOF) {
+		(*numlines)++;
+		lines[0] = lines[1];
+		lines[1] = strbuf_detach(&buf, NULL);
+	}
+	fclose(fp);
+}
+
+void get_two_first_lines(char *filename, int *numlines, char **lines)
+{
+	struct strbuf buf = STRBUF_INIT;;
+	char *line;
+	FILE *fp;
+
+
+	*numlines = 0;
+	fp = fopen(git_path("%s", filename), "r");
+	if (!fp) {
+		strbuf_release(&buf);
+		return;
+	}
+	while (strbuf_getline(&buf, fp, '\n') != EOF) {
+		stripspace(&buf, 1);
+		line = strbuf_detach(&buf, NULL);
+		if (strcmp(line, "") == 0)
+			continue;
+		if (*numlines < 2)
+			lines[*numlines] = line;
+		(*numlines)++;
+	}
+	fclose(fp);
+}
+
+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, begin;
+		int numlines = 0;
+		char *lines[2];
+		get_two_last_lines("rebase-merge/done", &numlines, lines);
+		if (numlines == 0)
+			status_printf_ln(s,color,_("No command done."));
+		else{
+			status_printf_ln(s,color,
+				_("Last command(s) done (%d command(s) done):"),
+				numlines);
+			begin = numlines > 1? 0 : 1;
+			for (i = begin; i < 2; i++) {
+				status_printf_ln(s,color,"   %s",lines[i]);
+			}
+			if (numlines > 2 && s->hints)
+			   status_printf_ln(s,color,
+				_("  (see more at .git/rebase-merge/done)"));
+		}
+		numlines = 0;
+		get_two_first_lines("rebase-merge/git-rebase-todo",
+					 &numlines, lines);
+		if (numlines == 0)
+			status_printf_ln(s, color,
+					 _("No command remaining."));
+		else{
+
+			status_printf_ln(s, color,
+				_("Next command(s) to do (%d remaining command(s)):"),
+				numlines);
+			begin = numlines > 1? 0 : 1;
+			for (i = 0; (i < 2 && i < numlines); i++) {
+				status_printf(s, color, "   %s", lines[i]);
+			}
+			if (s->hints)
+			   status_printf_ln(s, color,
+				_("  (use git rebase --edit-todo to view and edit)"));
+		}
+	}
+}
+
 static void show_rebase_in_progress(struct wt_status *s,
 				struct wt_status_state *state,
 				const char *color)
 {
 	struct stat st;
 
+	show_rebase_information(s, state, color);
 	if (has_unmerged(s) || state->rebase_in_progress || !stat(git_path("MERGE_MSG"), &st)) {
 		if (state->branch)
 			status_printf_ln(s, color,
-- 
2.4.2.342.g3cebd9b

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/4] status: give more information during rebase -i
  2015-06-03 22:00 ` [PATCH 3/4] status: give more information during rebase -i Guillaume Pagès
@ 2015-06-04  8:06   ` Matthieu Moy
  2015-06-04 17:19     ` Junio C Hamano
  0 siblings, 1 reply; 11+ messages in thread
From: Matthieu Moy @ 2015-06-04  8:06 UTC (permalink / raw)
  To: Guillaume Pagès
  Cc: git, Remi Galan, Remi Lespinet, Louis-Alexandre Stuber,
	Antoine Delaite

Guillaume Pagès <guillaume.pages@ensimag.grenoble-inp.fr> writes:

> +  (use git rebase --edit-todo to view and edit)

You're still missing double-quotes around "git rebase --edit-todo".

Guillaume Pagès <guillaume.pages@ensimag.grenoble-inp.fr> writes:

> +Last command(s) done (1 command(s) done):

Can't we just have "1 command"/"2 commands" instead of this (s). It's
particularly bad since it is already within parenthesis.

See the doc for Q_() in po/README and
http://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/Plural-forms.html
for more details.

> +void get_two_last_lines(char *filename, int *numlines, char **lines)
> +{
> +	struct strbuf buf = STRBUF_INIT;
> +	FILE *fp;
> +
> +	*numlines = 0;
> +	fp = fopen(git_path("%s", filename), "r");
> +	if (!fp) {
> +		strbuf_release(&buf);
> +		return;
> +	}
> +	while (strbuf_getline(&buf, fp, '\n') != EOF) {
> +		(*numlines)++;
> +		lines[0] = lines[1];
> +		lines[1] = strbuf_detach(&buf, NULL);
> +	}
> +	fclose(fp);
> +}
> +
> +void get_two_first_lines(char *filename, int *numlines, char **lines)
> +{
> +	struct strbuf buf = STRBUF_INIT;;
> +	char *line;
> +	FILE *fp;
> +
> +
> +	*numlines = 0;
> +	fp = fopen(git_path("%s", filename), "r");
> +	if (!fp) {
> +		strbuf_release(&buf);
> +		return;
> +	}
> +	while (strbuf_getline(&buf, fp, '\n') != EOF) {
> +		stripspace(&buf, 1);
> +		line = strbuf_detach(&buf, NULL);
> +		if (strcmp(line, "") == 0)
> +			continue;
> +		if (*numlines < 2)
> +			lines[*numlines] = line;
> +		(*numlines)++;
> +	}
> +	fclose(fp);
> +}
> +
> +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, begin;
> +		int numlines = 0;
> +		char *lines[2];
> +		get_two_last_lines("rebase-merge/done", &numlines, lines);
> +		if (numlines == 0)
> +			status_printf_ln(s,color,_("No command done."));

space after comma.

You may want to play with clang-format/clang-format-diff to have a tool
tell you this instead of asking a human.

I think english people would make this plural (No commands done).

> +		else{
> +			status_printf_ln(s,color,
> +				_("Last command(s) done (%d command(s) done):"),
> +				numlines);

Q_() ?

> +			begin = numlines > 1? 0 : 1;
> +			for (i = begin; i < 2; i++) {
> +				status_printf_ln(s,color,"   %s",lines[i]);
> +			}
> +			if (numlines > 2 && s->hints)
> +			   status_printf_ln(s,color,
> +				_("  (see more at .git/rebase-merge/done)"));

I'd write explicitly 'in file ...' instead of 'at'.

You need to use git_path here, it may not be ".git" in some contexts.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/4] status: give more information during rebase -i
  2015-06-04  8:06   ` Matthieu Moy
@ 2015-06-04 17:19     ` Junio C Hamano
  2015-06-05 16:35       ` Guillaume Pages
  0 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2015-06-04 17:19 UTC (permalink / raw)
  To: Matthieu Moy
  Cc: Guillaume Pagès, git, Remi Galan, Remi Lespinet,
	Louis-Alexandre Stuber, Antoine Delaite

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:

>> +void get_two_last_lines(char *filename, int *numlines, char **lines)
>> +{
>> +...
>> +}
>> +
>> +void get_two_first_lines(char *filename, int *numlines, char **lines)
>> +{
>> +...
>> +}

I had a handful of comments on these:

 - Do we need two separate and overly specific functions like these,
   i.e. "two" and "first/last"?

 - Wouldn't people want to be able to configure the number of lines?

 - Do we really want get_two_{first,last}_LINES() functions?

   I am wondering if insn sheets these functions read include
   comments, in which case get_n_{first,last}_commands() may be a
   more correct name.

 - Wouldn't it be necessary for these functions to report the total
   number of commands, instead of giving "void" back?  Otherwise how
   would the caller produce summary like this:

       An interactive rebase of 14 commits in progress.  You have
       replayed 4 commits so far, the last few of which were:

          da66b27 remote.c: provide per-branch pushremote name
          f052154 remote.c: hoist branch.*.remote lookup out of

       and 10 more commits to go, the next few of which are:

          a9f9f8c remote.c: introduce branch_get_upstream helper
          8770e6f remote.c: hoist read_config into remote_get_1
       
   Note that I am not suggesting the phrasing or presentation.  The
   information content is what I am interested in.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/4] status: give more information during rebase -i
  2015-06-04 17:19     ` Junio C Hamano
@ 2015-06-05 16:35       ` Guillaume Pages
  2015-06-05 17:11         ` Junio C Hamano
  0 siblings, 1 reply; 11+ messages in thread
From: Guillaume Pages @ 2015-06-05 16:35 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Matthieu Moy, git, Remi Galan, Remi Lespinet,
	Louis-Alexandre Stuber, Antoine Delaite

Junio C Hamano <gitster@pobox.com> writes

>Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes: 

>>> +void get_two_last_lines(char *filename, int *numlines, char **lines) 
>>> +{ 
>>> +... 
>>> +} 
>>> + 
>>> +void get_two_first_lines(char *filename, int *numlines, char **lines) 
>>> +{ 
>>> +... 
>>> +} 

>I had a handful of comments on these: 

>- Do we need two separate and overly specific functions like these, 
>i.e. "two" and "first/last"? 

>- Wouldn't people want to be able to configure the number of lines? 

>- Do we really want get_two_{first,last}_LINES() functions? 

>I am wondering if insn sheets these functions read include 
>comments, in which case get_n_{first,last}_commands() may be a 
>more correct name. 

>- Wouldn't it be necessary for these functions to report the total 
>number of commands, instead of giving "void" back? Otherwise how 
>would the caller produce summary like this: 

I felt that was not the right way to do so. What do you think of a
function like that:

/*
 * Puts nb_commands commands from filename in lines,
 * returns the total number of commands in the file
 * ignores comments and empty lines
 * lines needs to be at least of size nb_commands
 * part: 0 get last commands
 * 	 1 get first commands
 */

int get_commands(char *filename, int nb_commands, char **lines, int part)

Maybe part is not the best word to choose to take the beginning or the end
of the file. I also hesitate about adding a parameter to ignore or not the 
comments.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/4] status: give more information during rebase -i
  2015-06-05 16:35       ` Guillaume Pages
@ 2015-06-05 17:11         ` Junio C Hamano
  0 siblings, 0 replies; 11+ messages in thread
From: Junio C Hamano @ 2015-06-05 17:11 UTC (permalink / raw)
  To: Guillaume Pages
  Cc: Matthieu Moy, git, Remi Galan, Remi Lespinet,
	Louis-Alexandre Stuber, Antoine Delaite

Guillaume Pages <guillaume.pages@ensimag.grenoble-inp.fr> writes:

> I felt that was not the right way to do so. What do you think of a
> function like that:
>
> /*
>  * Puts nb_commands commands from filename in lines,
>  * returns the total number of commands in the file
>  * ignores comments and empty lines
>  * lines needs to be at least of size nb_commands
>  * part: 0 get last commands
>  * 	 1 get first commands
>  */
>
> int get_commands(char *filename, int nb_commands, char **lines, int part)
>
> Maybe part is not the best word to choose to take the beginning or the end
> of the file. I also hesitate about adding a parameter to ignore or not the 
> comments.

If I were doing the caller of these two functions, then instead of
adding these specialized helpers, I'd probably structure that caller
this way:

	struct strbuf buf = STRBUF_INIT;
	struct string_list have_done = STRING_LIST_INIT_DUP;
	struct string_list yet_to_do = STRING_LIST_INIT_DUP;
	int have_done_nr, yet_to_do_nr;

	strbuf_read_file(&buf, ".../done", 0);
	stripspace(&buf, 1);
        have_done_nr = string_list_split(&have_done, buf.buf, '\n', -1);
	strbuf_release(&buf);

	strbuf_read_file(&buf, ".../todo", 0);
	stripspace(&buf, 1);
        yet_to_do_nr = string_list_split(&yet_to_do, buf.buf, '\n', -1);
	strbuf_release(&buf);

Then have_done.items[have_done_nr - 1].string would be the last one
that we have replayed, and yet_to_do.items[0].string would be the
next one we are going to replay.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 3/4] status: give more information during rebase -i
@ 2015-06-08 14:55 Guillaume Pagès
  2015-06-08 14:55 ` [PATCH 4/4] status: add new tests for status " Guillaume Pagès
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Guillaume Pagès @ 2015-06-08 14:55 UTC (permalink / raw)
  To: git
  Cc: Remi Galan, Remi Lespinet, Guillaume Pages,
	Louis-Alexandre Stuber, Antoine Delaite, Matthieu Moy,
	Junio Hamano

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.
---

I've applied your remarks, the way to read into file has been changed
and the " has been added. I haven't been able to configure clang-format
so I checked many times the coding style, and hope there is no more mistakes.

 t/t7512-status-help.sh | 111 +++++++++++++++++++++++++++++++++++++++++++++++++
 wt-status.c            |  61 +++++++++++++++++++++++++++
 2 files changed, 172 insertions(+)

diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh
index 190656d..0c889fa 100755
--- a/t/t7512-status-help.sh
+++ b/t/t7512-status-help.sh
@@ -134,9 +134,13 @@ test_expect_success 'prepare for rebase_i_conflicts' '
 test_expect_success 'status during rebase -i when conflicts unresolved' '
 	test_when_finished "git rebase --abort" &&
 	ONTO=$(git rev-parse --short rebase_i_conflicts) &&
+	LAST_COMMIT=$(git rev-parse rebase_i_conflicts_second) &&
 	test_must_fail git rebase -i rebase_i_conflicts &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command done (1 command done):
+   pick $LAST_COMMIT one_second
+No commands remaining.
 You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
   (fix conflicts and then run "git rebase --continue")
   (use "git rebase --skip" to skip this patch)
@@ -159,10 +163,14 @@ test_expect_success 'status during rebase -i after resolving conflicts' '
 	git reset --hard rebase_i_conflicts_second &&
 	test_when_finished "git rebase --abort" &&
 	ONTO=$(git rev-parse --short rebase_i_conflicts) &&
+	LAST_COMMIT=$(git rev-parse rebase_i_conflicts_second) &&
 	test_must_fail git rebase -i rebase_i_conflicts &&
 	git add main.txt &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command done (1 command done):
+   pick $LAST_COMMIT one_second
+No commands remaining.
 You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
   (all conflicts fixed: run "git rebase --continue")
 
@@ -183,7 +191,9 @@ test_expect_success 'status when rebasing -i in edit mode' '
 	git checkout -b rebase_i_edit &&
 	test_commit one_rebase_i main.txt one &&
 	test_commit two_rebase_i main.txt two &&
+	COMMIT2=$(git rev-parse rebase_i_edit) &&
 	test_commit three_rebase_i main.txt three &&
+	COMMIT3=$(git rev-parse rebase_i_edit) &&
 	FAKE_LINES="1 edit 2" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
@@ -191,6 +201,10 @@ test_expect_success 'status when rebasing -i in edit mode' '
 	git rebase -i HEAD~2 &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   pick $COMMIT2 two_rebase_i
+   edit $COMMIT3 three_rebase_i
+No commands remaining.
 You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -207,8 +221,11 @@ test_expect_success 'status when splitting a commit' '
 	git checkout -b split_commit &&
 	test_commit one_split main.txt one &&
 	test_commit two_split main.txt two &&
+	COMMIT2=$(git rev-parse split_commit) &&
 	test_commit three_split main.txt three &&
+	COMMIT3=$(git rev-parse split_commit) &&
 	test_commit four_split main.txt four &&
+	COMMIT4=$(git rev-parse split_commit) &&
 	FAKE_LINES="1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
@@ -217,6 +234,12 @@ test_expect_success 'status when splitting a commit' '
 	git reset HEAD^ &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   pick $COMMIT2 two_split
+   edit $COMMIT3 three_split
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_split
+  (use "git rebase --edit-todo" to view and edit)
 You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
   (Once your working directory is clean, run "git rebase --continue")
 
@@ -239,7 +262,9 @@ test_expect_success 'status after editing the last commit with --amend during a
 	test_commit one_amend main.txt one &&
 	test_commit two_amend main.txt two &&
 	test_commit three_amend main.txt three &&
+	COMMIT3=$(git rev-parse amend_last) &&
 	test_commit four_amend main.txt four &&
+	COMMIT4=$(git rev-parse amend_last) &&
 	FAKE_LINES="1 2 edit 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
@@ -248,6 +273,11 @@ test_expect_success 'status after editing the last commit with --amend during a
 	git commit --amend -m "foo" &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (3 commands done):
+   pick $COMMIT3 three_amend
+   edit $COMMIT4 four_amend
+  (see more in file .git/rebase-merge/done)
+No commands remaining.
 You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -273,11 +303,20 @@ test_expect_success 'status: (continue first edit) second edit' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git rebase --continue &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -294,12 +333,21 @@ test_expect_success 'status: (continue first edit) second edit and split' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git rebase --continue &&
 	git reset HEAD^ &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (Once your working directory is clean, run "git rebase --continue")
 
@@ -321,12 +369,21 @@ test_expect_success 'status: (continue first edit) second edit and amend' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git rebase --continue &&
 	git commit --amend -m "foo" &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -343,12 +400,21 @@ test_expect_success 'status: (amend first edit) second edit' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git commit --amend -m "a" &&
 	git rebase --continue &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -366,12 +432,21 @@ test_expect_success 'status: (amend first edit) second edit and split' '
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	git rebase -i HEAD~3 &&
 	git commit --amend -m "b" &&
 	git rebase --continue &&
 	git reset HEAD^ &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (Once your working directory is clean, run "git rebase --continue")
 
@@ -393,6 +468,9 @@ test_expect_success 'status: (amend first edit) second edit and amend' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git commit --amend -m "c" &&
@@ -400,6 +478,12 @@ test_expect_success 'status: (amend first edit) second edit and amend' '
 	git commit --amend -m "d" &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -416,6 +500,9 @@ test_expect_success 'status: (split first edit) second edit' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git reset HEAD^ &&
@@ -424,6 +511,12 @@ test_expect_success 'status: (split first edit) second edit' '
 	git rebase --continue &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -440,6 +533,9 @@ test_expect_success 'status: (split first edit) second edit and split' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git reset HEAD^ &&
@@ -449,6 +545,12 @@ test_expect_success 'status: (split first edit) second edit and split' '
 	git reset HEAD^ &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (Once your working directory is clean, run "git rebase --continue")
 
@@ -470,6 +572,9 @@ test_expect_success 'status: (split first edit) second edit and amend' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git reset HEAD^ &&
@@ -479,6 +584,12 @@ test_expect_success 'status: (split first edit) second edit and amend' '
 	git commit --amend -m "h" &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
diff --git a/wt-status.c b/wt-status.c
index c83eca5..7f88470 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1026,12 +1026,73 @@ static int split_commit_in_progress(struct wt_status *s)
 	return split_in_progress;
 }
 
+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, begin;
+		int lines_to_show_nr = 2;
+
+		struct strbuf buf = STRBUF_INIT;
+		struct string_list have_done = STRING_LIST_INIT_DUP;
+		struct string_list yet_to_do = STRING_LIST_INIT_DUP;
+
+		strbuf_read_file(&buf, git_path("rebase-merge/done"), 0);
+		stripspace(&buf, 1);
+		have_done.nr = string_list_split(&have_done, buf.buf, '\n', -1);
+		string_list_remove_empty_items(&have_done, 1);
+		strbuf_release(&buf);
+
+		strbuf_read_file(&buf, git_path("rebase-merge/git-rebase-todo"), 0);
+		stripspace(&buf, 1);
+		string_list_split(&yet_to_do, buf.buf, '\n', -1);
+		string_list_remove_empty_items(&yet_to_do, 1);
+		strbuf_release(&buf);
+
+		if (have_done.nr == 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);
+			begin = (have_done.nr > lines_to_show_nr) ? have_done.nr-lines_to_show_nr : 0;
+			for (i = begin; i < have_done.nr; i++) {
+				status_printf_ln(s, color, "   %s", have_done.items[i].string);
+			}
+			if (have_done.nr > lines_to_show_nr && s->hints)
+			   status_printf_ln(s, color,
+				_("  (see more in file %s)"), git_path("rebase-merge/done"));
+		}
+		if (yet_to_do.nr == 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 = 0; i < lines_to_show_nr && 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)"));
+		}
+	}
+}
+
 static void show_rebase_in_progress(struct wt_status *s,
 				struct wt_status_state *state,
 				const char *color)
 {
 	struct stat st;
 
+	show_rebase_information(s, state, color);
 	if (has_unmerged(s) || state->rebase_in_progress || !stat(git_path("MERGE_MSG"), &st)) {
 		if (state->branch)
 			status_printf_ln(s, color,
-- 
2.4.2.342.gc0899ef

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/4] status: add new tests for status during rebase -i
  2015-06-08 14:55 [PATCH 3/4] status: give more information during rebase -i Guillaume Pagès
@ 2015-06-08 14:55 ` Guillaume Pagès
  2015-06-08 16:17 ` [PATCH 3/4] status: give more information " Matthieu Moy
  2015-06-08 22:11 ` Junio C Hamano
  2 siblings, 0 replies; 11+ messages in thread
From: Guillaume Pagès @ 2015-06-08 14:55 UTC (permalink / raw)
  To: git
  Cc: Remi Galan, Remi Lespinet, Guillaume Pages,
	Louis-Alexandre Stuber, Antoine Delaite, Matthieu Moy,
	Junio Hamano

Expand test coverage with one or more than two commands done
and with zero, one or more than two commands remaining
---
 t/t7512-status-help.sh | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh
index 0c889fa..844ba15 100755
--- a/t/t7512-status-help.sh
+++ b/t/t7512-status-help.sh
@@ -856,4 +856,92 @@ EOF
 	test_i18ncmp expected actual
 '
 
+test_expect_success 'prepare for different number of commits rebased' '
+	git reset --hard master &&
+	git checkout -b several_commits &&
+	test_commit one_commit main.txt one &&
+	test_commit two_commit main.txt two &&
+	test_commit three_commit main.txt three &&
+	test_commit four_commit main.txt four
+'
+
+
+test_expect_success 'status: one command done nothing remaining' '
+	FAKE_LINES=" exec_exit_15" &&
+	export FAKE_LINES &&
+	test_when_finished "git rebase --abort" &&
+	ONTO=$(git rev-parse --short HEAD~3) &&
+	(git rebase -i HEAD~3 || true) &&
+       cat >expected <<EOF &&
+interactive rebase in progress; onto $ONTO
+Last command done (1 command done):
+   exec exit 15
+No commands remaining.
+You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
+  (use "git commit --amend" to amend the current commit)
+  (use "git rebase --continue" once you are satisfied with your changes)
+
+nothing to commit (use -u to show untracked files)
+EOF
+	git status --untracked-files=no >actual &&
+	test_i18ncmp expected actual
+'
+
+test_expect_success 'status: two commands done with some white lines in done file' '
+	FAKE_LINES="1 > exec_exit_15  2 3" &&
+	export FAKE_LINES &&
+	test_when_finished "git rebase --abort" &&
+	ONTO=$(git rev-parse --short HEAD~3) &&
+	COMMIT4=$(git rev-parse HEAD) &&
+	COMMIT3=$(git rev-parse HEAD^) &&
+	COMMIT2=$(git rev-parse HEAD^^) &&
+	(git rebase -i HEAD~3 || true) &&
+       cat >expected <<EOF &&
+interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   pick $COMMIT2 two_commit
+   exec exit 15
+Next commands to do (2 remaining commands):
+   pick $COMMIT3 three_commit
+   pick $COMMIT4 four_commit
+  (use "git rebase --edit-todo" to view and edit)
+You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
+  (use "git commit --amend" to amend the current commit)
+  (use "git rebase --continue" once you are satisfied with your changes)
+
+nothing to commit (use -u to show untracked files)
+EOF
+	git status --untracked-files=no >actual &&
+	test_i18ncmp expected actual
+'
+
+test_expect_success 'status: two remaining commands with some white lines in todo file' '
+	FAKE_LINES="1 2 exec_exit_15 3 > 4" &&
+	export FAKE_LINES &&
+	test_when_finished "git rebase --abort" &&
+	ONTO=$(git rev-parse --short HEAD~4) &&
+	COMMIT4=$(git rev-parse HEAD) &&
+	COMMIT3=$(git rev-parse HEAD^) &&
+	COMMIT2=$(git rev-parse HEAD^^) &&
+	(git rebase -i HEAD~4 || true) &&
+	cat >expected <<EOF &&
+interactive rebase in progress; onto $ONTO
+Last commands done (3 commands done):
+   pick $COMMIT2 two_commit
+   exec exit 15
+  (see more in file .git/rebase-merge/done)
+Next commands to do (2 remaining commands):
+   pick $COMMIT3 three_commit
+   pick $COMMIT4 four_commit
+  (use "git rebase --edit-todo" to view and edit)
+You are currently editing a commit while rebasing branch '\''several_commits'\'' on '\''$ONTO'\''.
+  (use "git commit --amend" to amend the current commit)
+  (use "git rebase --continue" once you are satisfied with your changes)
+
+nothing to commit (use -u to show untracked files)
+EOF
+	git status --untracked-files=no >actual &&
+	test_i18ncmp expected actual
+'
+
 test_done
-- 
2.4.2.342.gc0899ef

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/4] status: give more information during rebase -i
  2015-06-08 14:55 [PATCH 3/4] status: give more information during rebase -i Guillaume Pagès
  2015-06-08 14:55 ` [PATCH 4/4] status: add new tests for status " Guillaume Pagès
@ 2015-06-08 16:17 ` Matthieu Moy
  2015-06-08 22:11 ` Junio C Hamano
  2 siblings, 0 replies; 11+ messages in thread
From: Matthieu Moy @ 2015-06-08 16:17 UTC (permalink / raw)
  To: Guillaume Pagès
  Cc: git, Remi Galan, Remi Lespinet, Louis-Alexandre Stuber,
	Antoine Delaite, Junio Hamano

Please, include a version number in the subject. git send-email -v2 does
this for you.

Guillaume Pagès <guillaume.pages@ensimag.grenoble-inp.fr> writes:

> +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, begin;
> +		int lines_to_show_nr = 2;
> +
> +		struct strbuf buf = STRBUF_INIT;
> +		struct string_list have_done = STRING_LIST_INIT_DUP;
> +		struct string_list yet_to_do = STRING_LIST_INIT_DUP;
> +
> +		strbuf_read_file(&buf, git_path("rebase-merge/done"), 0);
> +		stripspace(&buf, 1);
> +		have_done.nr = string_list_split(&have_done, buf.buf, '\n', -1);
> +		string_list_remove_empty_items(&have_done, 1);
> +		strbuf_release(&buf);

I'd release buf one line earlier (meaning "I'm done with buf, now let's
talk about something else"), but it's OK like this too

> +		strbuf_read_file(&buf, git_path("rebase-merge/git-rebase-todo"), 0);
> +		stripspace(&buf, 1);
> +		string_list_split(&yet_to_do, buf.buf, '\n', -1);
> +		string_list_remove_empty_items(&yet_to_do, 1);
> +		strbuf_release(&buf);

Nice. Much simpler than the previous iteration.

> +		if (have_done.nr == 0)
> +			status_printf_ln(s, color, _("No commands done."));
> +		else{

Missing space before {

> +			status_printf_ln(s, color,
> +				Q_("Last command done (%d command done):",
> +					"Last commands done (%d commands done):",
> +					have_done.nr),
> +				have_done.nr);
> +			begin = (have_done.nr > lines_to_show_nr) ? have_done.nr-lines_to_show_nr : 0;

Missing space around '-'

> +			for (i = begin; i < have_done.nr; i++) {
> +				status_printf_ln(s, color, "   %s", have_done.items[i].string);
> +			}

Useless braces.

> +			if (have_done.nr > lines_to_show_nr && s->hints)
> +			   status_printf_ln(s, color,

Indentation with space (open in Emacs, M-x whitespace-mode RET to see
this kind of things).

> +				_("  (see more in file %s)"), git_path("rebase-merge/done"));
> +		}
> +		if (yet_to_do.nr == 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 = 0; i < lines_to_show_nr && i < yet_to_do.nr; i++) {
> +				status_printf_ln(s, color, "   %s", yet_to_do.items[i].string);
> +			}

Useless braces.

> +			if (s->hints)
> +			   status_printf_ln(s, color,

Indentation with space again.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/4] status: give more information during rebase -i
  2015-06-08 14:55 [PATCH 3/4] status: give more information during rebase -i Guillaume Pagès
  2015-06-08 14:55 ` [PATCH 4/4] status: add new tests for status " Guillaume Pagès
  2015-06-08 16:17 ` [PATCH 3/4] status: give more information " Matthieu Moy
@ 2015-06-08 22:11 ` Junio C Hamano
  2015-06-09  8:57   ` Guillaume Pages
  2 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2015-06-08 22:11 UTC (permalink / raw)
  To: Guillaume Pagès
  Cc: git, Remi Galan, Remi Lespinet, Louis-Alexandre Stuber,
	Antoine Delaite, Matthieu Moy

Guillaume Pagès  <guillaume.pages@ensimag.grenoble-inp.fr> writes:

> 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.
> ---

Without 1/4 and 2/4 in the same thread, it is hard to guess what you
wanted to do with these two patches.  Remember, reviewers review not
just your patches but those from many others.

I would in the meantime assume these are replacement patches for the
ones in

  http://thread.gmane.org/gmane.comp.version-control.git/270743/focus=270744

> diff --git a/wt-status.c b/wt-status.c
> index c83eca5..7f88470 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -1026,12 +1026,73 @@ static int split_commit_in_progress(struct wt_status *s)
>  	return split_in_progress;
>  }
>  
> +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, begin;
> +		int lines_to_show_nr = 2;

"lines_to_show = 2" or "nr_lines_to_show = 2" would be easier to read.

> +
> +		struct strbuf buf = STRBUF_INIT;
> +		struct string_list have_done = STRING_LIST_INIT_DUP;
> +		struct string_list yet_to_do = STRING_LIST_INIT_DUP;
> +
> +		strbuf_read_file(&buf, git_path("rebase-merge/done"), 0);
> +		stripspace(&buf, 1);
> +		have_done.nr = string_list_split(&have_done, buf.buf, '\n', -1);
> +		string_list_remove_empty_items(&have_done, 1);
> +		strbuf_release(&buf);
> +
> +		strbuf_read_file(&buf, git_path("rebase-merge/git-rebase-todo"), 0);
> +		stripspace(&buf, 1);
> +		string_list_split(&yet_to_do, buf.buf, '\n', -1);
> +		string_list_remove_empty_items(&yet_to_do, 1);
> +		strbuf_release(&buf);
> +
> +		if (have_done.nr == 0)
> +			status_printf_ln(s, color, _("No commands done."));

Do the users even need to be told that, I wonder?

> +		else{

Style:	"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);
> +			begin = (have_done.nr > lines_to_show_nr) ? have_done.nr-lines_to_show_nr : 0;
> +			for (i = begin; i < have_done.nr; i++) {
> +				status_printf_ln(s, color, "   %s", have_done.items[i].string);
> +			}

Hmm, perhaps fold lines like this (and you do not need "begin")?

			for (i = (lines_to_show_nr < have_done.nr)
                             ? have_done.nr - lines_to_show_nr : 0;
                             i < have_done.nr;
                             i++)
				status_printf_ln(...);

> +			if (have_done.nr > lines_to_show_nr && s->hints)
> +			   status_printf_ln(s, color,
> +				_("  (see more in file %s)"), git_path("rebase-merge/done"));

That's a nice touch ;-)

> +		}
> +		if (yet_to_do.nr == 0)
> +			status_printf_ln(s, color,
> +					 _("No commands remaining."));

This I can see why we may want to say it.

> +		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 = 0; i < lines_to_show_nr && 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)"));
> +		}

Make sure you do not leak memory used by two string lists here...

> +	}
> +}
> +
>  static void show_rebase_in_progress(struct wt_status *s,
>  				struct wt_status_state *state,
>  				const char *color)
>  {
>  	struct stat st;
>  
> +	show_rebase_information(s, state, color);
>  	if (has_unmerged(s) || state->rebase_in_progress || !stat(git_path("MERGE_MSG"), &st)) {
>  		if (state->branch)
>  			status_printf_ln(s, color,

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 3/4] status: give more information during rebase -i
  2015-06-08 22:11 ` Junio C Hamano
@ 2015-06-09  8:57   ` Guillaume Pages
  0 siblings, 0 replies; 11+ messages in thread
From: Guillaume Pages @ 2015-06-09  8:57 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Remi Galan, Remi Lespinet, Louis-Alexandre Stuber,
	Antoine Delaite, Matthieu Moy

"Junio C Hamano" <gitster@pobox.com> writes:

>Guillaume Pagès <guillaume.pages@ensimag.grenoble-inp.fr> writes: 

>> 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. 
>> --- 

>Without 1/4 and 2/4 in the same thread, it is hard to guess what you 
>wanted to do with these two patches. Remember, reviewers review not 
>just your patches but those from many others. 

>I would in the meantime assume these are replacement patches for the 
>ones in 

>http://thread.gmane.org/gmane.comp.version-control.git/270743/focus=270744 

You assumed correctly, I didn't wanted to flood the mailing list and I
assumed it would be linked correctly with the previous since. Looks like
I was wrong.

>> diff --git a/wt-status.c b/wt-status.c 
>> index c83eca5..7f88470 100644 
>> --- a/wt-status.c 
>> +++ b/wt-status.c 
>> @@ -1026,12 +1026,73 @@ static int split_commit_in_progress(struct wt_status *s) 
>> return split_in_progress; 
>> } 
>> 
>> +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, begin; 
>> + int lines_to_show_nr = 2; 

>"lines_to_show = 2" or "nr_lines_to_show = 2" would be easier to read. 

Done

>> + 
>> + struct strbuf buf = STRBUF_INIT; 
>> + struct string_list have_done = STRING_LIST_INIT_DUP; 
>> + struct string_list yet_to_do = STRING_LIST_INIT_DUP; 
>> + 
>> + strbuf_read_file(&buf, git_path("rebase-merge/done"), 0); 
>> + stripspace(&buf, 1); 
>> + have_done.nr = string_list_split(&have_done, buf.buf, '\n', -1); 
>> + string_list_remove_empty_items(&have_done, 1); 
>> + strbuf_release(&buf); 
>> + 
>> + strbuf_read_file(&buf, git_path("rebase-merge/git-rebase-todo"), 0); 
>> + stripspace(&buf, 1); 
>> + string_list_split(&yet_to_do, buf.buf, '\n', -1); 
>> + string_list_remove_empty_items(&yet_to_do, 1); 
>> + strbuf_release(&buf); 
>> + 
>> + if (have_done.nr == 0) 
>> + status_printf_ln(s, color, _("No commands done.")); 

>Do the users even need to be told that, I wonder? 

I guess it removes the ambiguity of being told nothing.

>> + else{ 

>Style: "else {" 

Ok thanks.

>> + status_printf_ln(s, color, 
>> + Q_("Last command done (%d command done):", 
>> + "Last commands done (%d commands done):", 
>> + have_done.nr), 
>> + have_done.nr); 
>> + begin = (have_done.nr > lines_to_show_nr) ? have_done.nr-lines_to_show_nr : 0; 
>> + for (i = begin; i < have_done.nr; i++) { 
>> + status_printf_ln(s, color, " %s", have_done.items[i].string); 
>> + } 

>Hmm, perhaps fold lines like this (and you do not need "begin")? 

>for (i = (lines_to_show_nr < have_done.nr) 
>? have_done.nr - lines_to_show_nr : 0; 
>i < have_done.nr; 
>i++) 
>status_printf_ln(...);



>> + if (have_done.nr > lines_to_show_nr && s->hints) 
>> + status_printf_ln(s, color, 
>> + _(" (see more in file %s)"), git_path("rebase-merge/done")); 

>That's a nice touch ;-) 

>> + } 
>> + if (yet_to_do.nr == 0) 
>> + status_printf_ln(s, color, 
>> + _("No commands remaining.")); 

>This I can see why we may want to say it. 

>> + 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 = 0; i < lines_to_show_nr && 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)")); 
>> + } 

>Make sure you do not leak memory used by two string lists here... 

Done, thanks again.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 3/4] status: give more information during rebase -i
  2015-06-09 14:42 [PATCH 1/4] status: factor two rebase-related messages together Guillaume Pagès
@ 2015-06-09 14:42 ` Guillaume Pagès
  0 siblings, 0 replies; 11+ messages in thread
From: Guillaume Pagès @ 2015-06-09 14:42 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Remi Galan, Remi Lespinet, Guillaume Pages,
	Louis-Alexandre Stuber, Antoine Delaite, Matthieu Moy

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ès <guillaume.pages@ensimag.grenoble-inp.fr>
---
 t/t7512-status-help.sh | 111 +++++++++++++++++++++++++++++++++++++++++++++++++
 wt-status.c            |  64 ++++++++++++++++++++++++++++
 2 files changed, 175 insertions(+)

diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh
index 190656d..0c889fa 100755
--- a/t/t7512-status-help.sh
+++ b/t/t7512-status-help.sh
@@ -134,9 +134,13 @@ test_expect_success 'prepare for rebase_i_conflicts' '
 test_expect_success 'status during rebase -i when conflicts unresolved' '
 	test_when_finished "git rebase --abort" &&
 	ONTO=$(git rev-parse --short rebase_i_conflicts) &&
+	LAST_COMMIT=$(git rev-parse rebase_i_conflicts_second) &&
 	test_must_fail git rebase -i rebase_i_conflicts &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command done (1 command done):
+   pick $LAST_COMMIT one_second
+No commands remaining.
 You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
   (fix conflicts and then run "git rebase --continue")
   (use "git rebase --skip" to skip this patch)
@@ -159,10 +163,14 @@ test_expect_success 'status during rebase -i after resolving conflicts' '
 	git reset --hard rebase_i_conflicts_second &&
 	test_when_finished "git rebase --abort" &&
 	ONTO=$(git rev-parse --short rebase_i_conflicts) &&
+	LAST_COMMIT=$(git rev-parse rebase_i_conflicts_second) &&
 	test_must_fail git rebase -i rebase_i_conflicts &&
 	git add main.txt &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last command done (1 command done):
+   pick $LAST_COMMIT one_second
+No commands remaining.
 You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
   (all conflicts fixed: run "git rebase --continue")
 
@@ -183,7 +191,9 @@ test_expect_success 'status when rebasing -i in edit mode' '
 	git checkout -b rebase_i_edit &&
 	test_commit one_rebase_i main.txt one &&
 	test_commit two_rebase_i main.txt two &&
+	COMMIT2=$(git rev-parse rebase_i_edit) &&
 	test_commit three_rebase_i main.txt three &&
+	COMMIT3=$(git rev-parse rebase_i_edit) &&
 	FAKE_LINES="1 edit 2" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
@@ -191,6 +201,10 @@ test_expect_success 'status when rebasing -i in edit mode' '
 	git rebase -i HEAD~2 &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   pick $COMMIT2 two_rebase_i
+   edit $COMMIT3 three_rebase_i
+No commands remaining.
 You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -207,8 +221,11 @@ test_expect_success 'status when splitting a commit' '
 	git checkout -b split_commit &&
 	test_commit one_split main.txt one &&
 	test_commit two_split main.txt two &&
+	COMMIT2=$(git rev-parse split_commit) &&
 	test_commit three_split main.txt three &&
+	COMMIT3=$(git rev-parse split_commit) &&
 	test_commit four_split main.txt four &&
+	COMMIT4=$(git rev-parse split_commit) &&
 	FAKE_LINES="1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
@@ -217,6 +234,12 @@ test_expect_success 'status when splitting a commit' '
 	git reset HEAD^ &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   pick $COMMIT2 two_split
+   edit $COMMIT3 three_split
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_split
+  (use "git rebase --edit-todo" to view and edit)
 You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
   (Once your working directory is clean, run "git rebase --continue")
 
@@ -239,7 +262,9 @@ test_expect_success 'status after editing the last commit with --amend during a
 	test_commit one_amend main.txt one &&
 	test_commit two_amend main.txt two &&
 	test_commit three_amend main.txt three &&
+	COMMIT3=$(git rev-parse amend_last) &&
 	test_commit four_amend main.txt four &&
+	COMMIT4=$(git rev-parse amend_last) &&
 	FAKE_LINES="1 2 edit 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
@@ -248,6 +273,11 @@ test_expect_success 'status after editing the last commit with --amend during a
 	git commit --amend -m "foo" &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (3 commands done):
+   pick $COMMIT3 three_amend
+   edit $COMMIT4 four_amend
+  (see more in file .git/rebase-merge/done)
+No commands remaining.
 You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -273,11 +303,20 @@ test_expect_success 'status: (continue first edit) second edit' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git rebase --continue &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -294,12 +333,21 @@ test_expect_success 'status: (continue first edit) second edit and split' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git rebase --continue &&
 	git reset HEAD^ &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (Once your working directory is clean, run "git rebase --continue")
 
@@ -321,12 +369,21 @@ test_expect_success 'status: (continue first edit) second edit and amend' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git rebase --continue &&
 	git commit --amend -m "foo" &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -343,12 +400,21 @@ test_expect_success 'status: (amend first edit) second edit' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git commit --amend -m "a" &&
 	git rebase --continue &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -366,12 +432,21 @@ test_expect_success 'status: (amend first edit) second edit and split' '
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	git rebase -i HEAD~3 &&
 	git commit --amend -m "b" &&
 	git rebase --continue &&
 	git reset HEAD^ &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (Once your working directory is clean, run "git rebase --continue")
 
@@ -393,6 +468,9 @@ test_expect_success 'status: (amend first edit) second edit and amend' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git commit --amend -m "c" &&
@@ -400,6 +478,12 @@ test_expect_success 'status: (amend first edit) second edit and amend' '
 	git commit --amend -m "d" &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -416,6 +500,9 @@ test_expect_success 'status: (split first edit) second edit' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git reset HEAD^ &&
@@ -424,6 +511,12 @@ test_expect_success 'status: (split first edit) second edit' '
 	git rebase --continue &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
@@ -440,6 +533,9 @@ test_expect_success 'status: (split first edit) second edit and split' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git reset HEAD^ &&
@@ -449,6 +545,12 @@ test_expect_success 'status: (split first edit) second edit and split' '
 	git reset HEAD^ &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (Once your working directory is clean, run "git rebase --continue")
 
@@ -470,6 +572,9 @@ test_expect_success 'status: (split first edit) second edit and amend' '
 	FAKE_LINES="edit 1 edit 2 3" &&
 	export FAKE_LINES &&
 	test_when_finished "git rebase --abort" &&
+	COMMIT2=$(git rev-parse several_edits^^) &&
+	COMMIT3=$(git rev-parse several_edits^) &&
+	COMMIT4=$(git rev-parse several_edits) &&
 	ONTO=$(git rev-parse --short HEAD~3) &&
 	git rebase -i HEAD~3 &&
 	git reset HEAD^ &&
@@ -479,6 +584,12 @@ test_expect_success 'status: (split first edit) second edit and amend' '
 	git commit --amend -m "h" &&
 	cat >expected <<EOF &&
 interactive rebase in progress; onto $ONTO
+Last commands done (2 commands done):
+   edit $COMMIT2 two_edits
+   edit $COMMIT3 three_edits
+Next command to do (1 remaining command):
+   pick $COMMIT4 four_edits
+  (use "git rebase --edit-todo" to view and edit)
 You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
   (use "git commit --amend" to amend the current commit)
   (use "git rebase --continue" once you are satisfied with your changes)
diff --git a/wt-status.c b/wt-status.c
index 2339000..8b6d29c 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1025,6 +1025,69 @@ static int split_commit_in_progress(struct wt_status *s)
 	free(rebase_orig_head);
 	return split_in_progress;
 }
+
+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 = 2;
+
+		struct strbuf buf = STRBUF_INIT;
+		struct string_list have_done = STRING_LIST_INIT_DUP;
+		struct string_list yet_to_do = STRING_LIST_INIT_DUP;
+
+		strbuf_read_file(&buf, git_path("rebase-merge/done"), 0);
+		stripspace(&buf, 1);
+		string_list_split(&have_done, buf.buf, '\n', -1);
+		string_list_remove_empty_items(&have_done, 1);
+		strbuf_release(&buf);
+
+		strbuf_read_file(&buf, git_path("rebase-merge/git-rebase-todo"), 0);
+		stripspace(&buf, 1);
+		string_list_split(&yet_to_do, buf.buf, '\n', -1);
+		string_list_remove_empty_items(&yet_to_do, 1);
+		strbuf_release(&buf);
+
+		if (have_done.nr == 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 = (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 == 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 = 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)
@@ -1045,6 +1108,7 @@ static void show_rebase_in_progress(struct wt_status *s,
 {
 	struct stat st;
 
+	show_rebase_information(s, state, color);
 	if (has_unmerged(s)) {
 		print_rebase_state(s, state, color);
 		if (s->hints) {
-- 
2.4.2.342.ga3499d3

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-06-09 14:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-08 14:55 [PATCH 3/4] status: give more information during rebase -i Guillaume Pagès
2015-06-08 14:55 ` [PATCH 4/4] status: add new tests for status " Guillaume Pagès
2015-06-08 16:17 ` [PATCH 3/4] status: give more information " Matthieu Moy
2015-06-08 22:11 ` Junio C Hamano
2015-06-09  8:57   ` Guillaume Pages
  -- strict thread matches above, loose matches on Subject: below --
2015-06-09 14:42 [PATCH 1/4] status: factor two rebase-related messages together Guillaume Pagès
2015-06-09 14:42 ` [PATCH 3/4] status: give more information during rebase -i Guillaume Pagès
2015-06-03 22:00 [PATCH 1/4] status: factor two rebase-related messages together Guillaume Pagès
2015-06-03 22:00 ` [PATCH 3/4] status: give more information during rebase -i Guillaume Pagès
2015-06-04  8:06   ` Matthieu Moy
2015-06-04 17:19     ` Junio C Hamano
2015-06-05 16:35       ` Guillaume Pages
2015-06-05 17:11         ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).