chiark / gitweb /
add_keybinding: always allocate the new keybinding
[tig] / tig.c
diff --git a/tig.c b/tig.c
index 1f92114dc0710c9b2660deda4a7daa6601eaa460..6c2b7d08f8b460a286cc717363b4fb180ed03e02 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -12,7 +12,7 @@
  */
 
 #ifndef        VERSION
-#define VERSION        "tig-0.4.git"
+#define VERSION        "tig-0.5.git"
 #endif
 
 #ifndef DEBUG
@@ -451,6 +451,14 @@ parse_options(int argc, char *argv[])
        for (i = 1; i < argc; i++) {
                char *opt = argv[i];
 
+               if (!strcmp(opt, "log") ||
+                   !strcmp(opt, "diff") ||
+                   !strcmp(opt, "show")) {
+                       opt_request = opt[0] == 'l'
+                                   ? REQ_VIEW_LOG : REQ_VIEW_DIFF;
+                       break;
+               }
+
                if (opt[0] && opt[0] != '-')
                        break;
 
@@ -489,14 +497,6 @@ parse_options(int argc, char *argv[])
                        break;
                }
 
-               if (!strcmp(opt, "log") ||
-                   !strcmp(opt, "diff") ||
-                   !strcmp(opt, "show")) {
-                       opt_request = opt[0] == 'l'
-                                   ? REQ_VIEW_LOG : REQ_VIEW_DIFF;
-                       break;
-               }
-
                die("unknown option '%s'\n\n%s", opt, usage);
        }
 
@@ -767,10 +767,9 @@ static struct keybinding *keybindings[ARRAY_SIZE(keymap_table)];
 static void
 add_keybinding(enum keymap keymap, enum request request, int key)
 {
-       struct keybinding *keybinding = keybindings[keymap];
+       struct keybinding *keybinding;
 
-       if (!keybinding)
-               keybinding = calloc(1, sizeof(*keybinding));
+       keybinding = calloc(1, sizeof(*keybinding));
        if (!keybinding)
                die("Failed to allocate keybinding");
 
@@ -3269,12 +3268,12 @@ read_prompt(const char *prompt)
                }
        }
 
-       if (status == CANCEL) {
-               /* Clear the status window */
-               status_empty = FALSE;
-               report("");
+       /* Clear the status window */
+       status_empty = FALSE;
+       report("");
+
+       if (status == CANCEL)
                return NULL;
-       }
 
        buf[pos++] = 0;
 
@@ -3532,6 +3531,8 @@ main(int argc, char *argv[])
 
                /* Refresh, accept single keystroke of input */
                key = wgetch(status_win);
+               if (key == ERR)
+                       continue;
 
                request = get_keybinding(display[current_view]->keymap, key);