summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-10-30 19:10:56 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-10-30 19:10:56 (GMT)
commitc02e1e4a079dd8c3cd7ec21e82403867ebf22c19 (patch)
treee2431e759096e0428c6c919d6e39ce1dc2e0bdc7
parentf9891802624a99b84e5504cb166ee9ffcb6d976d (diff)
parentaf2a651d2ecb3967244c9a44a5813a0cf9977df5 (diff)
downloadgit-c02e1e4a079dd8c3cd7ec21e82403867ebf22c19.zip
git-c02e1e4a079dd8c3cd7ec21e82403867ebf22c19.tar.gz
git-c02e1e4a079dd8c3cd7ec21e82403867ebf22c19.tar.bz2
Merge branch 'nd/lift-path-max'
* nd/lift-path-max: checkout_entry(): clarify the use of topath[] parameter entry.c: convert checkout_entry to use strbuf
-rw-r--r--builtin/checkout-index.c2
-rw-r--r--cache.h1
-rw-r--r--entry.c21
3 files changed, 18 insertions, 6 deletions
diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index 69e167b..61e75eb 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -14,7 +14,7 @@
static int line_termination = '\n';
static int checkout_stage; /* default to checkout stage0 */
static int to_tempfile;
-static char topath[4][PATH_MAX + 1];
+static char topath[4][TEMPORARY_FILENAME_LENGTH + 1];
static struct checkout state;
diff --git a/cache.h b/cache.h
index 70ad174..9aa46e7 100644
--- a/cache.h
+++ b/cache.h
@@ -976,6 +976,7 @@ struct checkout {
refresh_cache:1;
};
+#define TEMPORARY_FILENAME_LENGTH 25
extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
struct cache_def {
diff --git a/entry.c b/entry.c
index acc892f..7b7aa81 100644
--- a/entry.c
+++ b/entry.c
@@ -234,19 +234,30 @@ static int check_path(const char *path, int len, struct stat *st, int skiplen)
return lstat(path, st);
}
+/*
+ * Write the contents from ce out to the working tree.
+ *
+ * When topath[] is not NULL, instead of writing to the working tree
+ * file named by ce, a temporary file is created by this function and
+ * its name is returned in topath[], which must be able to hold at
+ * least TEMPORARY_FILENAME_LENGTH bytes long.
+ */
int checkout_entry(struct cache_entry *ce,
const struct checkout *state, char *topath)
{
- static char path[PATH_MAX + 1];
+ static struct strbuf path_buf = STRBUF_INIT;
+ char *path;
struct stat st;
- int len = state->base_dir_len;
+ int len;
if (topath)
return write_entry(ce, topath, state, 1);
- memcpy(path, state->base_dir, len);
- strcpy(path + len, ce->name);
- len += ce_namelen(ce);
+ strbuf_reset(&path_buf);
+ strbuf_add(&path_buf, state->base_dir, state->base_dir_len);
+ strbuf_add(&path_buf, ce->name, ce_namelen(ce));
+ path = path_buf.buf;
+ len = path_buf.len;
if (!check_path(path, len, &st, state->base_dir_len)) {
unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);