diff options
author | Junio C Hamano <junkio@cox.net> | 2006-05-09 13:54:42 -0700 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-05-09 13:54:42 -0700 |
commit | 016cd9f6654248ebfc25f3c0d3b0e6ee6f2c81f0 (patch) | |
tree | 59ea0858fbdb88a97a466e6c3468038796ad252c | |
parent | 45f75a0167b4a4693f2c6005bf7db231ca91ecc8 (diff) | |
parent | 28cc4ab4224164971a523e8a6c222b5ab2bae27d (diff) | |
download | git-016cd9f6654248ebfc25f3c0d3b0e6ee6f2c81f0.tar.gz |
Merge branch 'fix'
* fix:
read-cache.c: use xcalloc() not calloc()
apply: fix infinite loop with multiple patches with --index
-rw-r--r-- | apply.c | 18 | ||||
-rw-r--r-- | read-cache.c | 2 |
2 files changed, 10 insertions, 10 deletions
@@ -19,6 +19,7 @@ // static const char *prefix; static int prefix_length = -1; +static int newfd = -1; static int p_value = 1; static int allow_binary_replacement = 0; @@ -1873,7 +1874,6 @@ static int use_patch(struct patch *p) static int apply_patch(int fd, const char *filename) { - int newfd; unsigned long offset, size; char *buffer = read_patch_file(fd, &size); struct patch *list = NULL, **listp = &list; @@ -1904,12 +1904,11 @@ static int apply_patch(int fd, const char *filename) size -= nr; } - newfd = -1; if (whitespace_error && (new_whitespace == error_on_whitespace)) apply = 0; write_index = check_index && apply; - if (write_index) + if (write_index && newfd < 0) newfd = hold_index_file_for_update(&cache_file, get_index_file()); if (check_index) { if (read_cache() < 0) @@ -1922,12 +1921,6 @@ static int apply_patch(int fd, const char *filename) if (apply) write_out_results(list, skipped_patch); - if (write_index) { - if (write_cache(newfd, active_cache, active_nr) || - commit_index_file(&cache_file)) - die("Unable to write new cachefile"); - } - if (show_index_info) show_index_list(list); @@ -2085,5 +2078,12 @@ int main(int argc, char **argv) whitespace_error == 1 ? "" : "s", whitespace_error == 1 ? "s" : ""); } + + if (write_index) { + if (write_cache(newfd, active_cache, active_nr) || + commit_index_file(&cache_file)) + die("Unable to write new cachefile"); + } + return 0; } diff --git a/read-cache.c b/read-cache.c index f97f92d90a..a917ab0cfe 100644 --- a/read-cache.c +++ b/read-cache.c @@ -552,7 +552,7 @@ int read_cache(void) active_nr = ntohl(hdr->hdr_entries); active_alloc = alloc_nr(active_nr); - active_cache = calloc(active_alloc, sizeof(struct cache_entry *)); + active_cache = xcalloc(active_alloc, sizeof(struct cache_entry *)); offset = sizeof(*hdr); for (i = 0; i < active_nr; i++) { |