aboutsummaryrefslogtreecommitdiff
path: root/builtin-update-index.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2007-09-27 00:52:47 -0700
committerJunio C Hamano <gitster@pobox.com>2007-09-27 00:52:47 -0700
commita17ba31b0b75365e1245e494d46abae4afc57480 (patch)
tree41c1d800c92e60d97a8b984dce086bcb3473dcc2 /builtin-update-index.c
parent0f729f21348c43a1c80f48faed2e753b1c923e85 (diff)
parent6d69b6f6ac27ab6f71a10da34b813ca25fd2a358 (diff)
downloadgit-a17ba31b0b75365e1245e494d46abae4afc57480.tar.gz
git-a17ba31b0b75365e1245e494d46abae4afc57480.tar.xz
Merge branch 'ph/strbuf' into kh/commit
* ph/strbuf: Clean up stripspace a bit, use strbuf even more. Add strbuf_read_file(). rerere: Fix use of an empty strbuf.buf Small cache_tree_write refactor. Make builtin-rerere use of strbuf nicer and more efficient. Add strbuf_cmp. strbuf_setlen(): do not barf on setting length of an empty buffer to 0 sq_quote_argv and add_to_string rework with strbuf's. Full rework of quote_c_style and write_name_quoted. Rework unquote_c_style to work on a strbuf. strbuf API additions and enhancements. nfv?asprintf are broken without va_copy, workaround them. Fix the expansion pattern of the pseudo-static path buffer.
Diffstat (limited to 'builtin-update-index.c')
-rw-r--r--builtin-update-index.c51
1 files changed, 27 insertions, 24 deletions
diff --git a/builtin-update-index.c b/builtin-update-index.c
index acd5ab592..c76879ed7 100644
--- a/builtin-update-index.c
+++ b/builtin-update-index.c
@@ -295,8 +295,11 @@ static void update_one(const char *path, const char *prefix, int prefix_length)
static void read_index_info(int line_termination)
{
struct strbuf buf;
+ struct strbuf uq;
+
strbuf_init(&buf, 0);
- while (1) {
+ strbuf_init(&uq, 0);
+ while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
char *ptr, *tab;
char *path_name;
unsigned char sha1[20];
@@ -320,9 +323,6 @@ static void read_index_info(int line_termination)
* This format is to put higher order stages into the
* index file and matches git-ls-files --stage output.
*/
- if (strbuf_getline(&buf, stdin, line_termination) == EOF)
- break;
-
errno = 0;
ul = strtoul(buf.buf, &ptr, 8);
if (ptr == buf.buf || *ptr != ' '
@@ -347,15 +347,17 @@ static void read_index_info(int line_termination)
if (get_sha1_hex(tab - 40, sha1) || tab[-41] != ' ')
goto bad_line;
- if (line_termination && ptr[0] == '"')
- path_name = unquote_c_style(ptr, NULL);
- else
- path_name = ptr;
+ path_name = ptr;
+ if (line_termination && path_name[0] == '"') {
+ strbuf_reset(&uq);
+ if (unquote_c_style(&uq, path_name, NULL)) {
+ die("git-update-index: bad quoting of path name");
+ }
+ path_name = uq.buf;
+ }
if (!verify_path(path_name)) {
fprintf(stderr, "Ignoring path %s\n", path_name);
- if (path_name != ptr)
- free(path_name);
continue;
}
@@ -383,6 +385,7 @@ static void read_index_info(int line_termination)
die("malformed index info %s", buf.buf);
}
strbuf_release(&buf);
+ strbuf_release(&uq);
}
static const char update_index_usage[] =
@@ -705,26 +708,26 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
free((char*)p);
}
if (read_from_stdin) {
- struct strbuf buf;
+ struct strbuf buf, nbuf;
+
strbuf_init(&buf, 0);
- while (1) {
- char *path_name;
+ strbuf_init(&nbuf, 0);
+ while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
const char *p;
- if (strbuf_getline(&buf, stdin, line_termination) == EOF)
- break;
- if (line_termination && buf.buf[0] == '"')
- path_name = unquote_c_style(buf.buf, NULL);
- else
- path_name = buf.buf;
- p = prefix_path(prefix, prefix_length, path_name);
+ if (line_termination && buf.buf[0] == '"') {
+ strbuf_reset(&nbuf);
+ if (unquote_c_style(&nbuf, buf.buf, NULL))
+ die("line is badly quoted");
+ strbuf_swap(&buf, &nbuf);
+ }
+ p = prefix_path(prefix, prefix_length, buf.buf);
update_one(p, NULL, 0);
if (set_executable_bit)
chmod_path(set_executable_bit, p);
- if (p < path_name || p > path_name + strlen(path_name))
- free((char*) p);
- if (path_name != buf.buf)
- free(path_name);
+ if (p < buf.buf || p > buf.buf + buf.len)
+ free((char *)p);
}
+ strbuf_release(&nbuf);
strbuf_release(&buf);
}