Code

Add stage-next action to jump to next diff chunk that can be staged
authorJonas Fonseca <fonseca@diku.dk>
Thu, 24 Apr 2008 08:07:34 +0000 (10:07 +0200)
committerJonas Fonseca <fonseca@diku.dk>
Thu, 24 Apr 2008 08:14:30 +0000 (10:14 +0200)
By default bound to '@'. Requested by Pascal Obry.

NEWS
manual.txt
tig.c
tigrc.5.txt

diff --git a/NEWS b/NEWS
index 23432925967f84d0412e2bbdfc41ef9500d19957..5987ddd582862679bebfa0211de3ed2b55d6c6c0 100644 (file)
--- 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:
index e4f937a4ad5fa357da15dd0e952ebae91afa4c13..f157a09f23e225ce9867e70a71eb5f698529cb28 100644 (file)
@@ -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 8e06c1ac5031bbb19cb3e0275e91e46c71652976..2a0d793c0bc338aed2f1bc8a6eb50d31e2da3af0 100644 (file)
--- 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;
index 5e204f33c147c774a591d273734e8ef884e3958e..92ea256c4e38ad597c145b7e16a1f5fe96578d9e 100644 (file)
@@ -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
 ------------------------------------------------------------------------------