]> asedeno.scripts.mit.edu Git - git.git/blobdiff - parse-options.c
restore legacy behavior for read_sha1_file()
[git.git] / parse-options.c
index 19fc849f4b2728f9d40db9e0a8f50cecc165b86c..469831d21b99e2ea6d5d0be51555d853d68a7682 100644 (file)
@@ -1,5 +1,6 @@
 #include "git-compat-util.h"
 #include "parse-options.h"
+#include "cache.h"
 
 #define OPT_SHORT 1
 #define OPT_UNSET 2
@@ -247,6 +248,7 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,
        ctx->argc = argc - 1;
        ctx->argv = argv + 1;
        ctx->out  = argv;
+       ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0);
        ctx->flags = flags;
 }
 
@@ -257,6 +259,9 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
                       const struct option *options,
                       const char * const usagestr[])
 {
+       /* we must reset ->opt, unknown short option leave it dangling */
+       ctx->opt = NULL;
+
        for (; ctx->argc; ctx->argc--, ctx->argv++) {
                const char *arg = ctx->argv[0];
 
@@ -286,6 +291,13 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
                                case -1:
                                        return parse_options_usage(usagestr, options);
                                case -2:
+                                       /* fake a short option thing to hide the fact that we may have
+                                        * started to parse aggregated stuff
+                                        *
+                                        * This is leaky, too bad.
+                                        */
+                                       ctx->argv[0] = xstrdup(ctx->opt - 1);
+                                       *(char *)ctx->argv[0] = '-';
                                        return PARSE_OPT_UNKNOWN;
                                }
                        }