Git development
 help / color / mirror / Atom feed
* [RFC/PATCH 1/2] status: give more information during rebase -i
@ 2015-06-03  8:35 Guillaume Pagès
  2015-06-03  8:35 ` [RFC/PATCH 2/2] status: fix tests to handle new verbose git status during rebase Guillaume Pagès
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Guillaume Pagès @ 2015-06-03  8:35 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.

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

At the moment it only gives information during an interactive rebase. It 
displays full sha1 identifiers, changing to short sha1 would be better.

 wt-status.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 106 insertions(+), 20 deletions(-)

diff --git a/wt-status.c b/wt-status.c
index 33452f1..8a32aea 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1026,13 +1026,104 @@ 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)
+{
+	*numlines=0;
+	struct strbuf buf = STRBUF_INIT;
+	FILE *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);
+	}
+	if (!fclose(fp))
+		strbuf_detach(&buf, NULL);
+	else
+		strbuf_release(&buf);
+}
+
+void get_two_first_lines(char *filename,int * numlines, char ** lines)
+{
+	*numlines=0;
+	struct strbuf buf = STRBUF_INIT;
+	char *line;
+	FILE *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)++;
+	}
+	if (!fclose(fp))
+		strbuf_detach(&buf, NULL);
+	else
+		strbuf_release(&buf);
+}
+
+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;
 
-	if (has_unmerged(s)) {
+	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,
 					 _("You are currently rebasing branch '%s' on '%s'."),
@@ -1042,25 +1133,17 @@ static void show_rebase_in_progress(struct wt_status *s,
 			status_printf_ln(s, color,
 					 _("You are currently rebasing."));
 		if (s->hints) {
-			status_printf_ln(s, color,
-				_("  (fix conflicts and then run \"git rebase --continue\")"));
-			status_printf_ln(s, color,
-				_("  (use \"git rebase --skip\" to skip this patch)"));
-			status_printf_ln(s, color,
-				_("  (use \"git rebase --abort\" to check out the original branch)"));
+			if (has_unmerged(s)) {
+				status_printf_ln(s, color,
+						 _("  (fix conflicts and then run \"git rebase --continue\")"));
+				status_printf_ln(s, color,
+						 _("  (use \"git rebase --skip\" to skip this patch)"));
+				status_printf_ln(s, color,
+						 _("  (use \"git rebase --abort\" to check out the original branch)"));
+			} else
+				status_printf_ln(s, color,
+						 _("  (all conflicts fixed: run \"git rebase --continue\")"));
 		}
-	} else if (state->rebase_in_progress || !stat(git_path("MERGE_MSG"), &st)) {
-		if (state->branch)
-			status_printf_ln(s, color,
-					 _("You are currently rebasing branch '%s' on '%s'."),
-					 state->branch,
-					 state->onto);
-		else
-			status_printf_ln(s, color,
-					 _("You are currently rebasing."));
-		if (s->hints)
-			status_printf_ln(s, color,
-				_("  (all conflicts fixed: run \"git rebase --continue\")"));
 	} else if (split_commit_in_progress(s)) {
 		if (state->branch)
 			status_printf_ln(s, color,
@@ -1327,7 +1410,10 @@ void wt_status_print(struct wt_status *s)
 		else if (!strcmp(branch_name, "HEAD")) {
 			branch_status_color = color(WT_STATUS_NOBRANCH, s);
 			if (state.rebase_in_progress || state.rebase_interactive_in_progress) {
-				on_what = _("rebase in progress; onto ");
+				if (state.rebase_interactive_in_progress)
+					on_what = _("interactive rebase in progress; onto ");
+				else
+					on_what = _("rebase in progress; onto ");
 				branch_name = state.onto;
 			} else if (state.detached_from) {
 				branch_name = state.detached_from;
-- 
2.4.2.340.g37f3f38

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

end of thread, other threads:[~2015-06-03 19:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-03  8:35 [RFC/PATCH 1/2] status: give more information during rebase -i Guillaume Pagès
2015-06-03  8:35 ` [RFC/PATCH 2/2] status: fix tests to handle new verbose git status during rebase Guillaume Pagès
2015-06-03 17:42   ` Matthieu Moy
2015-06-03 18:25     ` Junio C Hamano
2015-06-03 19:51       ` Guillaume Pages
2015-06-03 17:12 ` [RFC/PATCH 1/2] status: give more information during rebase -i Matthieu Moy
2015-06-03 17:20 ` Matthieu Moy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox