X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=apply.c;h=7c8146a7f317d9d1743e6a780eec823be72905a6;hb=18b01f4ff6db66b6419c7501bb303b643638b297;hp=1b93aab8af1a5498e69fe3cffe7cdfb527fa4317;hpb=0660626caff6ac3745cd7b7908a2ca540141a2ec;p=git.git diff --git a/apply.c b/apply.c index 1b93aab8..7c8146a7 100644 --- a/apply.c +++ b/apply.c @@ -20,6 +20,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; @@ -2048,7 +2049,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; @@ -2079,12 +2079,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) @@ -2097,12 +2096,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); @@ -2261,5 +2254,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; }