From: Paul Tan <pyokagan@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <johannes.schindelin@gmx.de>,
Duy Nguyen <pclouds@gmail.com>,
Stefan Beller <sbeller@google.com>,
sam.halliday@gmail.com, Paul Tan <pyokagan@gmail.com>
Subject: [PATCH/RFC/GSoC 14/17] status: use rebase_todo_list
Date: Sat, 12 Mar 2016 18:46:34 +0800 [thread overview]
Message-ID: <1457779597-6918-15-git-send-email-pyokagan@gmail.com> (raw)
In-Reply-To: <1457779597-6918-1-git-send-email-pyokagan@gmail.com>
Since 84e6fb9 (status: give more information during rebase -i,
2015-07-06), git status during an interactive rebase will show the list
of commands that are done and yet to be done. It implemented its own
hand-rolled parser in order to achieve this.
Now that we are able to fully parse interactive rebase's todo lists with
rebase_todo_list_parse(), use it in wt-status.c to reduce the amount of
code needed to implement this feature.
Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
This patch is just an illustration, and is not quite right as it does not strip
comments and blank lines like the original did.
wt-status.c | 100 +++++++++++++++---------------------------------------------
1 file changed, 25 insertions(+), 75 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index ab4f80d..96b82ef 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -15,6 +15,7 @@
#include "column.h"
#include "strbuf.h"
#include "utf8.h"
+#include "rebase-todo.h"
static const char cut_line[] =
"------------------------ >8 ------------------------\n";
@@ -1026,94 +1027,39 @@ static int split_commit_in_progress(struct wt_status *s)
return split_in_progress;
}
-/*
- * Turn
- * "pick d6a2f0303e897ec257dd0e0a39a5ccb709bc2047 some message"
- * into
- * "pick d6a2f03 some message"
- *
- * The function assumes that the line does not contain useless spaces
- * before or after the command.
- */
-static void abbrev_sha1_in_line(struct strbuf *line)
-{
- struct strbuf **split;
- int i;
-
- if (starts_with(line->buf, "exec ") ||
- starts_with(line->buf, "x "))
- return;
-
- split = 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 = find_unique_abbrev(sha1, DEFAULT_ABBREV);
- strbuf_reset(split[1]);
- strbuf_addf(split[1], "%s ", abbrev);
- strbuf_reset(line);
- for (i = 0; split[i]; i++)
- strbuf_addf(line, "%s", split[i]->buf);
- }
- }
- for (i = 0; split[i]; i++)
- strbuf_release(split[i]);
-
-}
-
-static void read_rebase_todolist(const char *fname, struct string_list *lines)
-{
- struct strbuf line = STRBUF_INIT;
- FILE *f = fopen(git_path("%s", fname), "r");
-
- if (!f)
- die_errno("Could not open file %s for reading",
- git_path("%s", fname));
- while (!strbuf_getline_lf(&line, f)) {
- if (line.len && line.buf[0] == comment_line_char)
- continue;
- strbuf_trim(&line);
- if (!line.len)
- continue;
- abbrev_sha1_in_line(&line);
- string_list_append(lines, line.buf);
- }
-}
-
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;
+ unsigned int i;
+ unsigned int nr_lines_to_show = 2;
+ struct strbuf sb = STRBUF_INIT;
- struct string_list have_done = STRING_LIST_INIT_DUP;
- struct string_list yet_to_do = STRING_LIST_INIT_DUP;
+ struct rebase_todo_list have_done = REBASE_TODO_LIST_INIT;
+ struct rebase_todo_list yet_to_do = REBASE_TODO_LIST_INIT;
- read_rebase_todolist("rebase-merge/done", &have_done);
- read_rebase_todolist("rebase-merge/git-rebase-todo", &yet_to_do);
+ if (rebase_todo_list_load(&have_done, git_path("rebase-merge/done"), 1) < 0)
+ return;
+ if (rebase_todo_list_load(&yet_to_do, git_path("rebase-merge/git-rebase-todo"), 1) < 0)
+ return;
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):",
+ Q_("Last command done (%u command done):",
+ "Last commands done (%u 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);
+ i++) {
+ strbuf_reset(&sb);
+ strbuf_add_rebase_todo_item(&sb, &have_done.items[i], 1);
+ status_printf(s, color, " %s", sb.buf);
+ }
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"));
@@ -1128,14 +1074,18 @@ static void show_rebase_information(struct wt_status *s,
"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);
+ for (i = 0; i < nr_lines_to_show && i < yet_to_do.nr; i++) {
+ strbuf_reset(&sb);
+ strbuf_add_rebase_todo_item(&sb, &yet_to_do.items[i], 1);
+ status_printf(s, color, " %s", sb.buf);
+ }
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);
+ rebase_todo_list_clear(&yet_to_do);
+ rebase_todo_list_clear(&have_done);
+ strbuf_release(&sb);
}
}
--
2.7.0
next prev parent reply other threads:[~2016-03-12 10:47 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-12 10:46 [PATCH/RFC/GSoC 00/17] A barebones git-rebase in C Paul Tan
2016-03-12 10:46 ` [PATCH/RFC/GSoC 01/17] perf: introduce performance tests for git-rebase Paul Tan
2016-03-16 7:58 ` Johannes Schindelin
2016-03-16 11:51 ` Paul Tan
2016-03-16 15:59 ` Johannes Schindelin
2016-03-18 11:01 ` Thomas Gummerer
2016-03-18 16:00 ` Johannes Schindelin
2016-03-20 14:00 ` Thomas Gummerer
2016-03-21 7:54 ` Johannes Schindelin
2016-03-12 10:46 ` [PATCH/RFC/GSoC 02/17] sha1_name: implement get_oid() and friends Paul Tan
2016-03-12 10:46 ` [PATCH/RFC/GSoC 03/17] builtin-rebase: implement skeletal builtin rebase Paul Tan
2016-03-14 18:31 ` Stefan Beller
2016-03-15 8:01 ` Johannes Schindelin
2016-03-12 10:46 ` [PATCH/RFC/GSoC 04/17] builtin-rebase: parse rebase arguments into a common rebase_options struct Paul Tan
2016-03-14 20:05 ` Stefan Beller
2016-03-15 10:54 ` Johannes Schindelin
2016-03-12 10:46 ` [PATCH/RFC/GSoC 05/17] rebase-options: implement rebase_options_load() and rebase_options_save() Paul Tan
2016-03-14 20:30 ` Stefan Beller
2016-03-16 8:04 ` Johannes Schindelin
2016-03-16 12:28 ` Paul Tan
2016-03-16 17:11 ` Johannes Schindelin
2016-03-21 14:55 ` Paul Tan
2016-03-16 12:04 ` Paul Tan
2016-03-16 17:10 ` Stefan Beller
2016-03-12 10:46 ` [PATCH/RFC/GSoC 06/17] rebase-am: introduce am backend for builtin rebase Paul Tan
2016-03-16 13:21 ` Johannes Schindelin
2016-03-12 10:46 ` [PATCH/RFC/GSoC 07/17] rebase-common: implement refresh_and_write_cache() Paul Tan
2016-03-14 21:10 ` Junio C Hamano
2016-03-16 12:56 ` Paul Tan
2016-03-12 10:46 ` [PATCH/RFC/GSoC 08/17] rebase-common: let refresh_and_write_cache() take a flags argument Paul Tan
2016-03-12 10:46 ` [PATCH/RFC/GSoC 09/17] rebase-common: implement cache_has_unstaged_changes() Paul Tan
2016-03-14 20:54 ` Johannes Schindelin
2016-03-14 21:52 ` Junio C Hamano
2016-03-15 11:51 ` Johannes Schindelin
2016-03-15 11:07 ` Duy Nguyen
2016-03-15 14:15 ` Johannes Schindelin
2016-03-12 10:46 ` [PATCH/RFC/GSoC 10/17] rebase-common: implement cache_has_uncommitted_changes() Paul Tan
2016-03-12 10:46 ` [PATCH/RFC/GSoC 11/17] rebase-merge: introduce merge backend for builtin rebase Paul Tan
2016-03-12 10:46 ` [PATCH/RFC/GSoC 12/17] rebase-todo: introduce rebase_todo_item Paul Tan
2016-03-14 13:43 ` Christian Couder
2016-03-14 20:33 ` Johannes Schindelin
2016-03-16 12:54 ` Paul Tan
2016-03-16 15:55 ` Johannes Schindelin
2016-03-12 10:46 ` [PATCH/RFC/GSoC 13/17] rebase-todo: introduce rebase_todo_list Paul Tan
2016-03-12 10:46 ` Paul Tan [this message]
2016-03-12 10:46 ` [PATCH/RFC/GSoC 15/17] wrapper: implement append_file() Paul Tan
2016-03-12 10:46 ` [PATCH/RFC/GSoC 16/17] editor: implement git_sequence_editor() and launch_sequence_editor() Paul Tan
2016-03-15 7:00 ` Johannes Schindelin
2016-03-16 13:06 ` Paul Tan
2016-03-16 18:21 ` Johannes Schindelin
2016-03-12 10:46 ` [PATCH/RFC/GSoC 17/17] rebase-interactive: introduce interactive backend for builtin rebase Paul Tan
2016-03-15 7:57 ` Johannes Schindelin
2016-03-15 16:48 ` Paul Tan
2016-03-15 19:45 ` Johannes Schindelin
2016-03-14 12:15 ` [PATCH/RFC/GSoC 00/17] A barebones git-rebase in C Duy Nguyen
2016-03-14 17:32 ` Stefan Beller
2016-03-14 18:43 ` Junio C Hamano
2016-03-16 12:46 ` Paul Tan
2016-03-14 20:44 ` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1457779597-6918-15-git-send-email-pyokagan@gmail.com \
--to=pyokagan@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johannes.schindelin@gmx.de \
--cc=pclouds@gmail.com \
--cc=sam.halliday@gmail.com \
--cc=sbeller@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).