Allow diff and index commands to be interrupted
[git.git] / rev-parse.c
index 42969a6..6bf205a 100644 (file)
@@ -53,6 +53,10 @@ static int is_rev_argument(const char *arg)
        };
        const char **p = rev_args;
 
+       /* accept -<digit>, like traditional "head" */
+       if ((*arg == '-') && isdigit(arg[1]))
+               return 1;
+
        for (;;) {
                const char *str = *p++;
                int len;
@@ -165,6 +169,21 @@ int main(int argc, char **argv)
                        show_file(arg);
                        continue;
                }
+               if (!strcmp(arg,"-n")) {
+                       if (++i >= argc)
+                               die("-n requires an argument");
+                       if ((filter & DO_FLAGS) && (filter & DO_REVS)) {
+                               show(arg);
+                               show(argv[i]);
+                       }
+                       continue;
+               }
+               if (!strncmp(arg,"-n",2)) {
+                       if ((filter & DO_FLAGS) && (filter & DO_REVS))
+                               show(arg);
+                       continue;
+               }
+
                if (*arg == '-') {
                        if (!strcmp(arg, "--")) {
                                as_is = 1;
@@ -199,15 +218,17 @@ int main(int argc, char **argv)
                                verify = 1;
                                continue;
                        }
-                       if (!strcmp(arg, "--abbrev") ||
-                           !strncmp(arg, "--abbrev=", 9)) {
+                       if (!strcmp(arg, "--short") ||
+                           !strncmp(arg, "--short=", 9)) {
                                filter &= ~(DO_FLAGS|DO_NOREV);
                                verify = 1;
                                abbrev = DEFAULT_ABBREV;
                                if (arg[8] == '=')
                                        abbrev = strtoul(arg + 9, NULL, 10);
-                               if (abbrev < 0 || 40 <= abbrev)
-                                       abbrev = DEFAULT_ABBREV;
+                               if (abbrev < MINIMUM_ABBREV)
+                                       abbrev = MINIMUM_ABBREV;
+                               else if (40 <= abbrev)
+                                       abbrev = 40;
                                continue;
                        }
                        if (!strcmp(arg, "--sq")) {
@@ -308,7 +329,9 @@ int main(int argc, char **argv)
                }
                if (verify)
                        die("Needed a single revision");
-               if (lstat(arg, &st) < 0)
+               if ((filter & DO_REVS) &&
+                   (filter & DO_NONFLAGS) && /* !def && */
+                   lstat(arg, &st) < 0)
                        die("'%s': %s", arg, strerror(errno));
                as_is = 1;
                show_file(arg);