Code

Obsolete the cherry-pick action and define as builtin external command
authorJonas Fonseca <fonseca@diku.dk>
Sat, 6 Oct 2007 22:32:54 +0000 (00:32 +0200)
committerJonas Fonseca <fonseca@diku.dk>
Sat, 6 Oct 2007 22:56:50 +0000 (00:56 +0200)
manual.txt
tig.1.txt
tig.c
tigrc.5.txt

index b976ece2a095faf39e60eb2536529b2a5d3474ce..372391ecf44adbbb9e9dcc448407269982e62d00 100644 (file)
@@ -345,6 +345,21 @@ M  Resolve unmerged file by launching git-mergetool(1). Note, to work \
        preferred merge tool. See the manpage of git-mergetool(1).
 -----------------------------------------------------------------------------
 
+[[external-commands]]
+External Commands
+~~~~~~~~~~~~~~~~~
+
+Tig also comes with a few builtin external commands. These are simple shell
+commands that are run and can take arguments from the current browsing state,
+such as the current commit ID. The default commands are:
+
+`-------`--------------------------------------------------------------------
+Key    Action
+-----------------------------------------------------------------------------
+C      git cherry-pick %(commit)
+G      git gc
+-----------------------------------------------------------------------------
+
 [[refspec]]
 Revision Specification
 ----------------------
index efc937b93d31ab53c765dde83140a892e8093a3b..13d4059c63eb1ebb27bf8698d1d7a6c7375444cd 100644 (file)
--- a/tig.1.txt
+++ b/tig.1.txt
@@ -82,10 +82,6 @@ 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 84e51b0733bf9e81766e449faafebf0bed068657..5fb529ec69b5d96f2ab781c4d7bba2bdcaa574aa 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -353,7 +353,6 @@ sq_quote(char buf[SIZEOF_STR], size_t bufsize, const char *src)
        REQ_(STATUS_UPDATE,     "Update file status"), \
        REQ_(STATUS_MERGE,      "Merge file using external tool"), \
        REQ_(EDIT,              "Open in editor"), \
-       REQ_(CHERRY_PICK,       "Cherry-pick commit to current branch"), \
        REQ_(NONE,              "Do nothing")
 
 
@@ -789,7 +788,6 @@ static struct keybinding default_keybindings[] = {
        { 'u',          REQ_STATUS_UPDATE },
        { 'M',          REQ_STATUS_MERGE },
        { 'e',          REQ_EDIT },
-       { 'C',          REQ_CHERRY_PICK },
 
        /* Using the ncurses SIGWINCH handler. */
        { KEY_RESIZE,   REQ_SCREEN_RESIZE },
@@ -1016,6 +1014,28 @@ get_run_request(enum request request)
        return &run_request[request - REQ_NONE - 1];
 }
 
+static void
+add_builtin_run_requests(void)
+{
+       struct {
+               enum keymap keymap;
+               int key;
+               char *argv[1];
+       } reqs[] = {
+               { KEYMAP_MAIN,    'C', { "git cherry-pick %(commit)" } },
+               { KEYMAP_GENERIC, 'G', { "git gc" } },
+       };
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(reqs); i++) {
+               enum request req;
+
+               req = add_run_request(reqs[i].keymap, reqs[i].key, 1, reqs[i].argv);
+               if (req != REQ_NONE)
+                       add_keybinding(reqs[i].keymap, req, reqs[i].key);
+       }
+}
+
 /*
  * User config file handling.
  */
@@ -1164,6 +1184,19 @@ option_bind_command(int argc, char *argv[])
        }
 
        request = get_request(argv[2]);
+       if (request = REQ_NONE) {
+               const char *obsolete[] = { "cherry-pick" };
+               size_t namelen = strlen(argv[2]);
+               int i;
+
+               for (i = 0; i < ARRAY_SIZE(obsolete); i++) {
+                       if (namelen == strlen(obsolete[i]) &&
+                           !string_enum_compare(obsolete[i], argv[2], namelen)) {
+                               config_msg = "Obsolete request name";
+                               return ERR;
+                       }
+               }
+       }
        if (request == REQ_NONE && *argv[2]++ == '!')
                request = add_run_request(keymap, key, argc - 2, argv + 2);
        if (request == REQ_NONE) {
@@ -1259,6 +1292,8 @@ load_options(void)
        config_lineno = 0;
        config_errors = FALSE;
 
+       add_builtin_run_requests();
+
        if (!home || !string_format(buf, "%s/.tigrc", home))
                return ERR;
 
@@ -2486,9 +2521,6 @@ 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");
@@ -4226,20 +4258,6 @@ 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)) {
-               open_external_viewer(cmd);
-       }
-}
-
 static enum request
 main_request(struct view *view, enum request request, struct line *line)
 {
@@ -4247,8 +4265,6 @@ 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 bfb122396b29ea2a3d9a2086ac3daf3d05d52bf2..55e34a5cec0aeedfb8a88cddba12dada29fb40ff 100644 (file)
@@ -247,7 +247,6 @@ toggle-rev-graph    Toggle revision graph visualization
 status-update          Update file status
 status-merge           Resolve unmerged file
 edit                   Open in editor
-cherry-pick            Cherry-pick commit to current branch
 ------------------------------------------------------------------------------