From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 3/6] checkout-index: handle "--no-prefix" option
Date: Sun, 31 Jan 2016 06:26:16 -0500 [thread overview]
Message-ID: <20160131112615.GC5116@sigill.intra.peff.net> (raw)
In-Reply-To: <20160131112215.GA4589@sigill.intra.peff.net>
We use a custom callback to parse "--prefix", but it does
not handle the "unset" case. As a result, passing
"--no-prefix" will cause a segfault.
We can fix this by switching it to an OPT_STRING, which
makes "--no-prefix" counteract a previous "--prefix". Note
that this assigns NULL, so we bump our default-case
initialization to lower in the main function.
Signed-off-by: Jeff King <peff@peff.net>
---
builtin/checkout-index.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index 3b913d1..43bedde 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -142,14 +142,6 @@ static int option_parse_u(const struct option *opt,
return 0;
}
-static int option_parse_prefix(const struct option *opt,
- const char *arg, int unset)
-{
- state.base_dir = arg;
- state.base_dir_len = strlen(arg);
- return 0;
-}
-
static int option_parse_stage(const struct option *opt,
const char *arg, int unset)
{
@@ -191,9 +183,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
N_("read list of paths from the standard input")),
OPT_BOOL(0, "temp", &to_tempfile,
N_("write the content to temporary files")),
- OPT_CALLBACK(0, "prefix", NULL, N_("string"),
- N_("when creating files, prepend <string>"),
- option_parse_prefix),
+ OPT_STRING(0, "prefix", &state.base_dir, N_("string"),
+ N_("when creating files, prepend <string>")),
OPT_CALLBACK(0, "stage", NULL, NULL,
N_("copy out the files from named stage"),
option_parse_stage),
@@ -204,7 +195,6 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
usage_with_options(builtin_checkout_index_usage,
builtin_checkout_index_options);
git_config(git_default_config, NULL);
- state.base_dir = "";
prefix_length = prefix ? strlen(prefix) : 0;
if (read_cache() < 0) {
@@ -217,6 +207,10 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
state.quiet = quiet;
state.not_new = not_new;
+ if (!state.base_dir)
+ state.base_dir = "";
+ state.base_dir_len = strlen(state.base_dir);
+
if (state.base_dir_len || to_tempfile) {
/* when --prefix is specified we do not
* want to update cache.
--
2.7.0.489.g6faad84
next prev parent reply other threads:[~2016-01-31 11:26 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-31 11:22 [PATCH 0/6] post-strbuf_getline cleanups Jeff King
2016-01-31 11:25 ` [PATCH 1/6] give "nbuf" strbuf a more meaningful name Jeff King
2016-01-31 11:54 ` Johannes Schindelin
2016-01-31 11:59 ` Jeff King
2016-01-31 12:01 ` Johannes Schindelin
2016-01-31 11:25 ` [PATCH 2/6] checkout-index: simplify "-z" option parsing Jeff King
2016-01-31 11:26 ` Jeff King [this message]
2016-01-31 11:29 ` [PATCH 4/6] checkout-index: handle "--no-index" option Jeff King
2016-02-01 2:25 ` Junio C Hamano
2016-02-01 3:22 ` Jeff King
2016-01-31 11:30 ` [PATCH 5/6] checkout-index: disallow "--no-stage" option Jeff King
2016-02-01 2:18 ` Junio C Hamano
2016-02-01 3:18 ` Jeff King
2016-01-31 11:35 ` [PATCH 6/6] apply, ls-files: simplify "-z" parsing Jeff King
2016-01-31 11:59 ` Johannes Schindelin
2016-02-01 21:47 ` Junio C Hamano
2016-02-01 22:52 ` Junio C Hamano
2016-02-02 5:29 ` Jeff King
2016-02-01 2:14 ` [PATCH 0/6] post-strbuf_getline cleanups Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160131112615.GC5116@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).