checkout_entry(): use the strbuf throughout the function
There is no need to break out the "buf" and "len" members into separate temporary variables. Rename path_buf to path and use path.buf and path.len directly. This makes it easier to reason about the data flow in the function. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
fd356f6aa8
commit
f63272a35e
32
entry.c
32
entry.c
|
@ -237,27 +237,25 @@ static int check_path(const char *path, int len, struct stat *st, int skiplen)
|
||||||
int checkout_entry(struct cache_entry *ce,
|
int checkout_entry(struct cache_entry *ce,
|
||||||
const struct checkout *state, char *topath)
|
const struct checkout *state, char *topath)
|
||||||
{
|
{
|
||||||
static struct strbuf path_buf = STRBUF_INIT;
|
static struct strbuf path = STRBUF_INIT;
|
||||||
char *path;
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int len;
|
|
||||||
|
|
||||||
if (topath)
|
if (topath)
|
||||||
return write_entry(ce, topath, state, 1);
|
return write_entry(ce, topath, state, 1);
|
||||||
|
|
||||||
strbuf_reset(&path_buf);
|
strbuf_reset(&path);
|
||||||
strbuf_add(&path_buf, state->base_dir, state->base_dir_len);
|
strbuf_add(&path, state->base_dir, state->base_dir_len);
|
||||||
strbuf_add(&path_buf, ce->name, ce_namelen(ce));
|
strbuf_add(&path, ce->name, ce_namelen(ce));
|
||||||
path = path_buf.buf;
|
|
||||||
len = path_buf.len;
|
|
||||||
|
|
||||||
if (!check_path(path, len, &st, state->base_dir_len)) {
|
if (!check_path(path.buf, path.len, &st, state->base_dir_len)) {
|
||||||
unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
|
unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
|
||||||
if (!changed)
|
if (!changed)
|
||||||
return 0;
|
return 0;
|
||||||
if (!state->force) {
|
if (!state->force) {
|
||||||
if (!state->quiet)
|
if (!state->quiet)
|
||||||
fprintf(stderr, "%s already exists, no checkout\n", path);
|
fprintf(stderr,
|
||||||
|
"%s already exists, no checkout\n",
|
||||||
|
path.buf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,12 +270,14 @@ int checkout_entry(struct cache_entry *ce,
|
||||||
if (S_ISGITLINK(ce->ce_mode))
|
if (S_ISGITLINK(ce->ce_mode))
|
||||||
return 0;
|
return 0;
|
||||||
if (!state->force)
|
if (!state->force)
|
||||||
return error("%s is a directory", path);
|
return error("%s is a directory", path.buf);
|
||||||
remove_subtree(path);
|
remove_subtree(path.buf);
|
||||||
} else if (unlink(path))
|
} else if (unlink(path.buf))
|
||||||
return error("unable to unlink old '%s' (%s)", path, strerror(errno));
|
return error("unable to unlink old '%s' (%s)",
|
||||||
|
path.buf, strerror(errno));
|
||||||
} else if (state->not_new)
|
} else if (state->not_new)
|
||||||
return 0;
|
return 0;
|
||||||
create_directories(path, len, state);
|
|
||||||
return write_entry(ce, path, state, 0);
|
create_directories(path.buf, path.len, state);
|
||||||
|
return write_entry(ce, path.buf, state, 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue