@ -130,33 +130,6 @@ static const char * const builtin_checkout_index_usage[] = {
@@ -130,33 +130,6 @@ static const char * const builtin_checkout_index_usage[] = {
static struct lock_file lock_file;
static int option_parse_u(const struct option *opt,
const char *arg, int unset)
{
int *newfd = opt->value;
state.refresh_cache = 1;
state.istate = &the_index;
if (*newfd < 0)
*newfd = hold_locked_index(&lock_file, 1);
return 0;
}
static int option_parse_z(const struct option *opt,
const char *arg, int unset)
{
nul_term_line = !unset;
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)
{
@ -168,7 +141,7 @@ static int option_parse_stage(const struct option *opt,
@@ -168,7 +141,7 @@ static int option_parse_stage(const struct option *opt,
if ('1' <= ch && ch <= '3')
checkout_stage = arg[0] - '0';
else
die("stage should be between 1 and 3 or all");
die(_("stage should be between 1 and 3 or all"));
}
return 0;
}
@ -181,6 +154,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
@@ -181,6 +154,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
int read_from_stdin = 0;
int prefix_length;
int force = 0, quiet = 0, not_new = 0;
int index_opt = 0;
struct option builtin_checkout_index_options[] = {
OPT_BOOL('a', "all", &all,
N_("check out all files in the index")),
@ -189,22 +163,19 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
@@ -189,22 +163,19 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
N_("no warning for existing files and files not in index")),
OPT_BOOL('n', "no-create", ¬_new,
N_("don't checkout new files")),
{ OPTION_CALLBACK, 'u', "index", &newfd, NULL,
N_("update stat information in the index file"),
PARSE_OPT_NOARG, option_parse_u },
{ OPTION_CALLBACK, 'z', NULL, NULL, NULL,
N_("paths are separated with NUL character"),
PARSE_OPT_NOARG, option_parse_z },
OPT_BOOL('u', "index", &index_opt,
N_("update stat information in the index file")),
OPT_BOOL('z', NULL, &nul_term_line,
N_("paths are separated with NUL character")),
OPT_BOOL(0, "stdin", &read_from_stdin,
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_CALLBACK(0, "stage", NULL, NULL,
OPT_STRING(0, "prefix", &state.base_dir, N_("string"),
N_("when creating files, prepend <string>")),
{ OPTION_CALLBACK, 0, "stage", NULL, "1-3|all",
N_("copy out the files from named stage"),
option_parse_stage),
PARSE_OPT_NONEG, option_parse_stage },
OPT_END()
};
@ -212,7 +183,6 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
@@ -212,7 +183,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) {
@ -225,15 +195,17 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
@@ -225,15 +195,17 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
state.quiet = quiet;
state.not_new = not_new;
if (state.base_dir_len || to_tempfile) {
/* when --prefix is specified we do not
* want to update cache.
*/
if (state.refresh_cache) {
rollback_lock_file(&lock_file);
newfd = -1;
}
state.refresh_cache = 0;
if (!state.base_dir)
state.base_dir = "";
state.base_dir_len = strlen(state.base_dir);
/*
* when --prefix is specified we do not want to update cache.
*/
if (index_opt && !state.base_dir_len && !to_tempfile) {
state.refresh_cache = 1;
state.istate = &the_index;
newfd = hold_locked_index(&lock_file, 1);
}
/* Check out named files first */
@ -251,7 +223,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
@@ -251,7 +223,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
}
if (read_from_stdin) {
struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT;
struct strbuf buf = STRBUF_INIT;
struct strbuf unquoted = STRBUF_INIT;
strbuf_getline_fn getline_fn;
if (all)
@ -261,16 +234,16 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
@@ -261,16 +234,16 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
while (getline_fn(&buf, stdin) != EOF) {
char *p;
if (!nul_term_line && buf.buf[0] == '"') {
strbuf_reset(&nbuf);
if (unquote_c_style(&nbuf, buf.buf, NULL))
strbuf_reset(&unquoted);
if (unquote_c_style(&unquoted, buf.buf, NULL))
die("line is badly quoted");
strbuf_swap(&buf, &nbuf);
strbuf_swap(&buf, &unquoted);
}
p = prefix_path(prefix, prefix_length, buf.buf);
checkout_file(p, prefix);
free(p);
}
strbuf_release(&nbuf);
strbuf_release(&unquoted);
strbuf_release(&buf);
}