From: Jonas Fonseca Date: Sat, 6 Oct 2007 22:32:54 +0000 (+0200) Subject: Obsolete the cherry-pick action and define as builtin external command X-Git-Url: https://git.tokkee.org/?p=tig.git;a=commitdiff_plain;h=f655964f625ffdc0720f600477542602c66a6723 Obsolete the cherry-pick action and define as builtin external command --- diff --git a/manual.txt b/manual.txt index b976ece..372391e 100644 --- a/manual.txt +++ b/manual.txt @@ -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 ---------------------- diff --git a/tig.1.txt b/tig.1.txt index efc937b..13d4059 100644 --- 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 84e51b0..5fb529e 100644 --- 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; diff --git a/tigrc.5.txt b/tigrc.5.txt index bfb1223..55e34a5 100644 --- a/tigrc.5.txt +++ b/tigrc.5.txt @@ -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 ------------------------------------------------------------------------------