Code

Support cherry-picking commits in main view to current branch
authorJonas Fonseca <fonseca@diku.dk>
Mon, 17 Sep 2007 23:38:42 +0000 (01:38 +0200)
committerJonas Fonseca <fonseca@diku.dk>
Mon, 17 Sep 2007 23:43:47 +0000 (01:43 +0200)
Bound to 'C' by default. Idea by krh on #git.

tig.1.txt
tig.c
tigrc.5.txt

index 13d4059c63eb1ebb27bf8698d1d7a6c7375444cd..efc937b93d31ab53c765dde83140a892e8093a3b 100644 (file)
--- a/tig.1.txt
+++ b/tig.1.txt
@@ -82,6 +82,10 @@ TIG_LS_REMOTE::
        Set command for retrieving all repository references. The command
        should output data in the same format as git-ls-remote(1).
 
+TIG_CHERRY_PICK::
+       Set command for cherry-picking a commit. The command should expect
+       a commit SHA as its final argument.
+
 TIG_DIFF_CMD::
        The command used for the diff view. By default, git show is used
        as a backend.
diff --git a/tig.c b/tig.c
index 05ec10c7b407736d111be1e927fe6b182af74f6e..246812f2c6e7fa1518a05a621fe664e95495a600 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -351,7 +351,8 @@ sq_quote(char buf[SIZEOF_STR], size_t bufsize, const char *src)
        REQ_(TOGGLE_LINENO,     "Toggle line numbers"), \
        REQ_(TOGGLE_REV_GRAPH,  "Toggle revision graph visualization"), \
        REQ_(STATUS_UPDATE,     "Update file status"), \
-       REQ_(EDIT,              "Open in editor")
+       REQ_(EDIT,              "Open in editor"), \
+       REQ_(CHERRY_PICK,       "Cherry-pick commit to current branch")
 
 
 /* User action requests. */
@@ -784,6 +785,7 @@ static struct keybinding default_keybindings[] = {
        { ':',          REQ_PROMPT },
        { 'u',          REQ_STATUS_UPDATE },
        { 'e',          REQ_EDIT },
+       { 'C',          REQ_CHERRY_PICK },
 
        /* Using the ncurses SIGWINCH handler. */
        { KEY_RESIZE,   REQ_SCREEN_RESIZE },
@@ -2326,13 +2328,14 @@ view_driver(struct view *view, enum request request)
                report("Nothing to edit");
                break;
 
+       case REQ_CHERRY_PICK:
+               report("Nothing to cherry-pick");
+               break;
+
        case REQ_ENTER:
                report("Nothing to enter");
                break;
 
-       case REQ_NONE:
-               doupdate();
-               return TRUE;
 
        case REQ_VIEW_CLOSE:
                /* XXX: Mark closed views by letting view->parent point to the
@@ -3986,6 +3989,26 @@ main_read(struct view *view, char *line)
        return TRUE;
 }
 
+static void
+cherry_pick_commit(struct commit *commit)
+{
+       char cmd[SIZEOF_STR];
+       char *cherry_pick = getenv("TIG_CHERRY_PICK");
+
+       if (!cherry_pick)
+               cherry_pick = "git cherry-pick";
+
+       if (string_format(cmd, "%s %s", cherry_pick, commit->id)) {
+               def_prog_mode();           /* save current tty modes */
+               endwin();                  /* restore original tty modes */
+               system(cmd);
+               fprintf(stderr, "Press Enter to continue");
+               getc(stdin);
+               reset_prog_mode();
+               redraw_display();
+       }
+}
+
 static enum request
 main_request(struct view *view, enum request request, struct line *line)
 {
@@ -3993,6 +4016,8 @@ main_request(struct view *view, enum request request, struct line *line)
 
        if (request == REQ_ENTER)
                open_view(view, REQ_VIEW_DIFF, flags);
+       else if (request == REQ_CHERRY_PICK)
+               cherry_pick_commit(line->data);
        else
                return request;
 
index 9d3ad6992f8afc9b2e21780418062e9e312e3121..540de87cc2c7974fa941d608b591f38148c54f2c 100644 (file)
@@ -233,6 +233,7 @@ toggle-lineno               Toggle line numbers
 toggle-rev-graph       Toggle revision graph visualization
 status-update          Update file status
 edit                   Open in editor
+cherry-pick            Cherry-pick commit to current branch
 ------------------------------------------------------------------------------