From: Jonas Fonseca Date: Thu, 24 Apr 2008 08:07:34 +0000 (+0200) Subject: Add stage-next action to jump to next diff chunk that can be staged X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fd73e841d9db03eaddd929bd084adbffaafbc3c2;p=tig.git Add stage-next action to jump to next diff chunk that can be staged By default bound to '@'. Requested by Pascal Obry. --- diff --git a/NEWS b/NEWS index 2343292..5987ddd 100644 --- a/NEWS +++ b/NEWS @@ -8,7 +8,9 @@ Improvements: - F5 also refreshes the current view. - Allow line graphics to be disabled with new line-graphics option. - - Also include the reference names when searching. + - Main view: also include the reference names when searching. + - Stage view: add stage-next action to jump to next diff chunk that can be + staged. By default bound to '@'. - Configure: check for the ncurses header files. Bug fixes: diff --git a/manual.txt b/manual.txt index e4f937a..f157a09 100644 --- a/manual.txt +++ b/manual.txt @@ -366,6 +366,7 @@ u Update status of file. In the status view, this allows you to add an \ M Resolve unmerged file by launching git-mergetool(1). Note, to work \ correctly this might require some initial configuration of your \ preferred merge tool. See the manpage of git-mergetool(1). +@ Move to next chunk in the stage view. ',' Move tree view to the parent tree. e Open file in editor. ----------------------------------------------------------------------------- diff --git a/tig.c b/tig.c index 8e06c1a..2a0d793 100644 --- a/tig.c +++ b/tig.c @@ -376,6 +376,7 @@ sq_quote(char buf[SIZEOF_STR], size_t bufsize, const char *src) REQ_(TOGGLE_REFS, "Toggle reference display (tags/branches)"), \ REQ_(STATUS_UPDATE, "Update file status"), \ REQ_(STATUS_MERGE, "Merge file using external tool"), \ + REQ_(STAGE_NEXT, "Find next chunk to stage"), \ REQ_(TREE_PARENT, "Switch to parent directory in tree view"), \ REQ_(EDIT, "Open in editor"), \ REQ_(NONE, "Do nothing") @@ -779,6 +780,7 @@ static struct keybinding default_keybindings[] = { { ':', REQ_PROMPT }, { 'u', REQ_STATUS_UPDATE }, { 'M', REQ_STATUS_MERGE }, + { '@', REQ_STAGE_NEXT }, { ',', REQ_TREE_PARENT }, { 'e', REQ_EDIT }, @@ -3796,6 +3798,8 @@ struct status { static char status_onbranch[SIZEOF_STR]; static struct status stage_status; static enum line_type stage_line_type; +static size_t stage_chunks; +static int *stage_chunk; /* Get fields from the diff line: * :100644 100644 06a5d6ae9eca55be2e0e585a152e6b1336f2b20e 0000000000000000000000000000000000000000 M @@ -4187,6 +4191,7 @@ status_enter(struct view *view, struct line *line) } stage_line_type = line->type; + stage_chunks = 0; string_format(VIEW(REQ_VIEW_STAGE)->ref, info, stage_status.new.name); } @@ -4596,6 +4601,42 @@ stage_update(struct view *view, struct line *line) return TRUE; } +static void +stage_next(struct view *view, struct line *line) +{ + int i; + + if (!stage_chunks) { + static size_t alloc = 0; + int *tmp; + + for (line = view->line; line < view->line + view->lines; line++) { + if (line->type != LINE_DIFF_CHUNK) + continue; + + tmp = realloc_items(stage_chunk, &alloc, + stage_chunks, sizeof(*tmp)); + if (!tmp) { + report("Allocation failure"); + return; + } + + stage_chunk = tmp; + stage_chunk[stage_chunks++] = line - view->line; + } + } + + for (i = 0; i < stage_chunks; i++) { + if (stage_chunk[i] > view->lineno) { + do_scroll_view(view, stage_chunk[i] - view->lineno); + report("Chunk %d of %d", i + 1, stage_chunks); + return; + } + } + + report("No next chunk found"); +} + static enum request stage_request(struct view *view, enum request request, struct line *line) { @@ -4605,6 +4646,15 @@ stage_request(struct view *view, enum request request, struct line *line) return REQ_NONE; break; + case REQ_STAGE_NEXT: + if (stage_line_type == LINE_STAT_UNTRACKED) { + report("File is untracked; press %s to add", + get_key(REQ_STATUS_UPDATE)); + return REQ_NONE; + } + stage_next(view, line); + return REQ_NONE; + case REQ_EDIT: if (!stage_status.new.name[0]) return request; diff --git a/tigrc.5.txt b/tigrc.5.txt index 5e204f3..92ea256 100644 --- a/tigrc.5.txt +++ b/tigrc.5.txt @@ -264,6 +264,7 @@ toggle-rev-graph Toggle revision graph visualization toggle-refs Toggle reference display status-update Update file status status-merge Resolve unmerged file +stage-next Find next chunk to stage tree-parent Switch to parent directory in tree view edit Open in editor ------------------------------------------------------------------------------