Add shortcuts for very often used options.
[gitweb.git] / parse-options.c
index c751ebf601825c6354c6e2c7ed650f1693947a45..12a9f9ea68f5ceac24aa4d2f530b68e8c0468983 100644 (file)
@@ -254,3 +254,24 @@ void usage_with_options(const char * const *usagestr,
 
        exit(129);
 }
+
+/*----- some often used options -----*/
+#include "cache.h"
+int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
+{
+       int v;
+
+       if (!arg) {
+               v = unset ? 0 : DEFAULT_ABBREV;
+       } else {
+               v = strtol(arg, (char **)&arg, 10);
+               if (*arg)
+                       return opterror(opt, "expects a numerical value", 0);
+               if (v && v < MINIMUM_ABBREV)
+                       v = MINIMUM_ABBREV;
+               else if (v > 40)
+                       v = 40;
+       }
+       *(int *)(opt->value) = v;
+       return 0;
+}