summaryrefslogtreecommitdiff
path: root/parse-options.c
diff options
context:
space:
mode:
authorPierre Habouzit <madcoder@debian.org>2008-06-23 22:55:11 +0200
committerJunio C Hamano <gitster@pobox.com>2008-06-30 14:51:13 -0700
commit26141b5b60eea36f1d771312f6cae9e56dbbf760 (patch)
treea7e869a6ed39ba10b5e7d45d8ad0f18d0fee9096 /parse-options.c
parent07fe54db3cdf42500ac2e893b670fd74841afdc4 (diff)
downloadgit-26141b5b60eea36f1d771312f6cae9e56dbbf760.tar.gz
parse-opt: fake short strings for callers to believe in.
If we begin to parse -abc and that the parser knew about -a and -b, it will fake a -c switch for the caller to deal with. Of course in the case of -acb (supposing -c is not taking an argument) the caller will have to be especially clever to do the same thing. We could think about exposing an API to do so if it's really needed, but oh well... Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'parse-options.c')
-rw-r--r--parse-options.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/parse-options.c b/parse-options.c
index 19fc849f4b..0d3818ab48 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1,5 +1,6 @@
#include "git-compat-util.h"
#include "parse-options.h"
+#include "cache.h"
#define OPT_SHORT 1
#define OPT_UNSET 2
@@ -257,6 +258,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 +290,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;
}
}