manual: remove section on porcelains
[tig] / tig.c
diff --git a/tig.c b/tig.c
index 5fb529e..fbc65b9 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -105,13 +105,13 @@ static size_t utf8_length(const char *string, size_t max_width, int *coloffset,
        "git ls-remote $(git rev-parse --git-dir) 2>/dev/null"
 
 #define TIG_DIFF_CMD \
-       "git show --root --patch-with-stat --find-copies-harder -B -C %s 2>/dev/null"
+       "git show --no-color --root --patch-with-stat --find-copies-harder -B -C %s 2>/dev/null"
 
 #define TIG_LOG_CMD    \
-       "git log --cc --stat -n100 %s 2>/dev/null"
+       "git log --no-color --cc --stat -n100 %s 2>/dev/null"
 
 #define TIG_MAIN_CMD \
-       "git log --topo-order --pretty=raw %s 2>/dev/null"
+       "git log --no-color --topo-order --pretty=raw %s 2>/dev/null"
 
 #define TIG_TREE_CMD   \
        "git ls-tree %s %s"
@@ -505,6 +505,26 @@ parse_options(int argc, char *argv[])
                if (opt[0] && opt[0] != '-')
                        break;
 
+               if (!strcmp(opt, "--")) {
+                       i++;
+                       break;
+               }
+
+               if (check_option(opt, 'v', "version", OPT_NONE)) {
+                       printf("tig version %s\n", TIG_VERSION);
+                       return FALSE;
+               }
+
+               if (check_option(opt, 'h', "help", OPT_NONE)) {
+                       printf(usage);
+                       return FALSE;
+               }
+
+               if (!strcmp(opt, "-S")) {
+                       opt_request = REQ_VIEW_STATUS;
+                       continue;
+               }
+
                if (!strcmp(opt, "-l")) {
                        opt_request = REQ_VIEW_LOG;
                        continue;
@@ -515,11 +535,6 @@ parse_options(int argc, char *argv[])
                        continue;
                }
 
-               if (!strcmp(opt, "-S")) {
-                       opt_request = REQ_VIEW_STATUS;
-                       continue;
-               }
-
                if (check_option(opt, 'n', "line-number", OPT_INT, &opt_num_interval)) {
                        opt_line_number = TRUE;
                        continue;
@@ -530,21 +545,6 @@ parse_options(int argc, char *argv[])
                        continue;
                }
 
-               if (check_option(opt, 'v', "version", OPT_NONE)) {
-                       printf("tig version %s\n", TIG_VERSION);
-                       return FALSE;
-               }
-
-               if (check_option(opt, 'h', "help", OPT_NONE)) {
-                       printf(usage);
-                       return FALSE;
-               }
-
-               if (!strcmp(opt, "--")) {
-                       i++;
-                       break;
-               }
-
                die("unknown option '%s'\n\n%s", opt, usage);
        }
 
@@ -558,7 +558,7 @@ parse_options(int argc, char *argv[])
                if (opt_request == REQ_VIEW_MAIN)
                        /* XXX: This is vulnerable to the user overriding
                         * options required for the main view parser. */
-                       string_copy(opt_cmd, "git log --pretty=raw");
+                       string_copy(opt_cmd, "git log --no-color --pretty=raw");
                else
                        string_copy(opt_cmd, "git");
                buf_size = strlen(opt_cmd);
@@ -937,7 +937,6 @@ static char *
 get_key(enum request request)
 {
        static char buf[BUFSIZ];
-       static char key_char[] = "'X'";
        size_t pos = 0;
        char *sep = "";
        int i;
@@ -946,27 +945,12 @@ get_key(enum request request)
 
        for (i = 0; i < ARRAY_SIZE(default_keybindings); i++) {
                struct keybinding *keybinding = &default_keybindings[i];
-               char *seq = NULL;
-               int key;
 
                if (keybinding->request != request)
                        continue;
 
-               for (key = 0; key < ARRAY_SIZE(key_table); key++)
-                       if (key_table[key].value == keybinding->alias)
-                               seq = key_table[key].name;
-
-               if (seq == NULL &&
-                   keybinding->alias < 127 &&
-                   isprint(keybinding->alias)) {
-                       key_char[1] = (char) keybinding->alias;
-                       seq = key_char;
-               }
-
-               if (!seq)
-                       seq = "'?'";
-
-               if (!string_format_from(buf, &pos, "%s%s", sep, seq))
+               if (!string_format_from(buf, &pos, "%s%s", sep,
+                                       get_key_name(keybinding->alias)))
                        return "Too many keybindings!";
                sep = ", ";
        }
@@ -1184,7 +1168,7 @@ option_bind_command(int argc, char *argv[])
        }
 
        request = get_request(argv[2]);
-       if (request = REQ_NONE) {
+       if (request == REQ_NONE) {
                const char *obsolete[] = { "cherry-pick" };
                size_t namelen = strlen(argv[2]);
                int i;
@@ -1219,9 +1203,10 @@ set_option(char *opt, char *value)
        /* Tokenize */
        while (argc < ARRAY_SIZE(argv) && (valuelen = strcspn(value, " \t"))) {
                argv[argc++] = value;
-
                value += valuelen;
-               if (!*value)
+
+               /* Nothing more to tokenize or last available token. */
+               if (!*value || argc >= ARRAY_SIZE(argv))
                        break;
 
                *value++ = 0;
@@ -3275,8 +3260,11 @@ error_out:
 #define STATUS_LIST_OTHER_CMD \
        "git ls-files -z --others --exclude-per-directory=.gitignore"
 
-#define STATUS_DIFF_SHOW_CMD \
-       "git diff --root --patch-with-stat --find-copies-harder -B -C %s -- %s 2>/dev/null"
+#define STATUS_DIFF_INDEX_SHOW_CMD \
+       "git diff-index --root --patch-with-stat --find-copies-harder -B -C --cached HEAD -- %s 2>/dev/null"
+
+#define STATUS_DIFF_FILES_SHOW_CMD \
+       "git diff-files --root --patch-with-stat --find-copies-harder -B -C -- %s 2>/dev/null"
 
 /* First parse staged info using git-diff-index(1), then parse unstaged
  * info using git-diff-files(1), and finally untracked files using
@@ -3407,8 +3395,8 @@ status_enter(struct view *view, struct line *line)
 
        switch (line->type) {
        case LINE_STAT_STAGED:
-               if (!string_format_from(opt_cmd, &cmdsize, STATUS_DIFF_SHOW_CMD,
-                                       "--cached", path))
+               if (!string_format_from(opt_cmd, &cmdsize,
+                                       STATUS_DIFF_INDEX_SHOW_CMD, path))
                        return REQ_QUIT;
                if (status)
                        info = "Staged changes to %s";
@@ -3417,8 +3405,8 @@ status_enter(struct view *view, struct line *line)
                break;
 
        case LINE_STAT_UNSTAGED:
-               if (!string_format_from(opt_cmd, &cmdsize, STATUS_DIFF_SHOW_CMD,
-                                       "", path))
+               if (!string_format_from(opt_cmd, &cmdsize,
+                                       STATUS_DIFF_FILES_SHOW_CMD, path))
                        return REQ_QUIT;
                if (status)
                        info = "Unstaged changes to %s";
@@ -3441,7 +3429,7 @@ status_enter(struct view *view, struct line *line)
                break;
 
        default:
-               die("w00t");
+               die("line type %d not handled in switch", line->type);
        }
 
        open_view(view, REQ_VIEW_STAGE, OPEN_RELOAD | OPEN_SPLIT);
@@ -3495,7 +3483,7 @@ status_update_file(struct view *view, struct status *status, enum line_type type
                break;
 
        default:
-               die("w00t");
+               die("line type %d not handled in switch", type);
        }
 
        pipe = popen(cmd, "w");
@@ -3548,6 +3536,10 @@ status_request(struct view *view, enum request request, struct line *line)
                break;
 
        case REQ_STATUS_MERGE:
+               if (!status || status->status != 'U') {
+                       report("Merging only possible for files with unmerged status ('U').");
+                       return REQ_NONE;
+               }
                open_mergetool(status->name);
                break;
 
@@ -3610,7 +3602,7 @@ status_select(struct view *view, struct line *line)
                break;
 
        default:
-               die("w00t");
+               die("line type %d not handled in switch", line->type);
        }
 
        if (status && status->status == 'U') {