diff options
author | Junio C Hamano <junkio@cox.net> | 2007-03-23 17:38:22 -0700 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-03-23 23:38:04 -0700 |
commit | 1c2c6112a4bf655faa768ddfca067945edf2809e (patch) | |
tree | 985973c2d5ac3611db6e25f702eecacf7cb41939 /builtin-apply.c | |
parent | t6004: add a bit more path optimization test. (diff) | |
parent | Merge branch 'maint' (diff) | |
download | tgif-1c2c6112a4bf655faa768ddfca067945edf2809e.tar.xz |
Merge branch 'master' into jc/bisect
This is to merge in the fix for path-limited bisection
from the 'master' branch.
Diffstat (limited to 'builtin-apply.c')
-rw-r--r-- | builtin-apply.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/builtin-apply.c b/builtin-apply.c index dfa1716796..27a182bfaa 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -2355,7 +2355,7 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size) { - int fd; + int fd, converted; char *nbuf; unsigned long nsize; @@ -2364,17 +2364,18 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf, * terminated. */ return symlink(buf, path); + + fd = open(path, O_CREAT | O_EXCL | O_WRONLY, (mode & 0100) ? 0777 : 0666); + if (fd < 0) + return -1; + nsize = size; nbuf = (char *) buf; - if (convert_to_working_tree(path, &nbuf, &nsize)) { - free((char *) buf); + converted = convert_to_working_tree(path, &nbuf, &nsize); + if (converted) { buf = nbuf; size = nsize; } - - fd = open(path, O_CREAT | O_EXCL | O_WRONLY, (mode & 0100) ? 0777 : 0666); - if (fd < 0) - return -1; while (size) { int written = xwrite(fd, buf, size); if (written < 0) @@ -2386,6 +2387,8 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf, } if (close(fd) < 0) die("closing file %s: %s", path, strerror(errno)); + if (converted) + free(nbuf); return 0; } |