Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit f63272a

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fd356f6 commit f63272a

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

entry.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -237,27 +237,25 @@ static int check_path(const char *path, int len, struct stat *st, int skiplen)
237237
int checkout_entry(struct cache_entry *ce,
238238
const struct checkout *state, char *topath)
239239
{
240-
static struct strbuf path_buf = STRBUF_INIT;
241-
char *path;
240+
static struct strbuf path = STRBUF_INIT;
242241
struct stat st;
243-
int len;
244242

245243
if (topath)
246244
return write_entry(ce, topath, state, 1);
247245

248-
strbuf_reset(&path_buf);
249-
strbuf_add(&path_buf, state->base_dir, state->base_dir_len);
250-
strbuf_add(&path_buf, ce->name, ce_namelen(ce));
251-
path = path_buf.buf;
252-
len = path_buf.len;
246+
strbuf_reset(&path);
247+
strbuf_add(&path, state->base_dir, state->base_dir_len);
248+
strbuf_add(&path, ce->name, ce_namelen(ce));
253249

254-
if (!check_path(path, len, &st, state->base_dir_len)) {
250+
if (!check_path(path.buf, path.len, &st, state->base_dir_len)) {
255251
unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
256252
if (!changed)
257253
return 0;
258254
if (!state->force) {
259255
if (!state->quiet)
260-
fprintf(stderr, "%s already exists, no checkout\n", path);
256+
fprintf(stderr,
257+
"%s already exists, no checkout\n",
258+
path.buf);
261259
return -1;
262260
}
263261

@@ -272,12 +270,14 @@ int checkout_entry(struct cache_entry *ce,
272270
if (S_ISGITLINK(ce->ce_mode))
273271
return 0;
274272
if (!state->force)
275-
return error("%s is a directory", path);
276-
remove_subtree(path);
277-
} else if (unlink(path))
278-
return error("unable to unlink old '%s' (%s)", path, strerror(errno));
273+
return error("%s is a directory", path.buf);
274+
remove_subtree(path.buf);
275+
} else if (unlink(path.buf))
276+
return error("unable to unlink old '%s' (%s)",
277+
path.buf, strerror(errno));
279278
} else if (state->not_new)
280279
return 0;
281-
create_directories(path, len, state);
282-
return write_entry(ce, path, state, 0);
280+
281+
create_directories(path.buf, path.len, state);
282+
return write_entry(ce, path.buf, state, 0);
283283
}

0 commit comments

Comments
 (0)