From dbd0f7d3221fbf8e9943a114c11e5b5e5fc0c201 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 9 May 2006 01:08:23 -0700 Subject: [PATCH 1/4] apply: fix infinite loop with multiple patches with --index When multiple patches are passed to git-apply, it will attempt to open multiple file descriptors to an index, which means multiple entries will be in the circular cache_file_list. This change makes git-apply only open the index once and write the index at exit. Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- apply.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/apply.c b/apply.c index 269210a578..ca36391bb2 100644 --- a/apply.c +++ b/apply.c @@ -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; } From 28cc4ab4224164971a523e8a6c222b5ab2bae27d Mon Sep 17 00:00:00 2001 From: Yakov Lerner Date: Tue, 9 May 2006 16:14:00 +0000 Subject: [PATCH 2/4] read-cache.c: use xcalloc() not calloc() Elsewhere we use xcalloc(); we should consistently do so. Signed-off-by: Yakov Lerner Signed-off-by: Junio C Hamano --- read-cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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++) { From d1802851b0c112a065b43e3f83d631f867b7e1ce Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 9 May 2006 19:22:25 -0700 Subject: [PATCH 3/4] revert/cherry-pick: use aggressive merge. After doing an in-index 3-way merge, we always do the stock "merge-index merge-one-file" without doing anything fancy; use of --aggressive helps performance quite a bit. Signed-off-by: Junio C Hamano --- git-revert.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-revert.sh b/git-revert.sh index c19d3a6916..de8b5f0f0f 100755 --- a/git-revert.sh +++ b/git-revert.sh @@ -137,7 +137,7 @@ esac >.msg # $prev and $commit on top of us (when cherry-picking or replaying). echo >&2 "First trying simple merge strategy to $me." -git-read-tree -m -u $base $head $next && +git-read-tree -m -u --aggressive $base $head $next && result=$(git-write-tree 2>/dev/null) || { echo >&2 "Simple $me fails; trying Automatic $me." git-merge-index -o git-merge-one-file -a || { From 8d7a397aab561d3782f531e733b617e0e211f04a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 9 May 2006 19:23:23 -0700 Subject: [PATCH 4/4] checkout: use --aggressive when running a 3-way merge (-m). After doing an in-index 3-way merge, we always do the stock "merge-index merge-one-file" without doing anything fancy; use of --aggressive helps performance quite a bit. Signed-off-by: Junio C Hamano --- git-checkout.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-checkout.sh b/git-checkout.sh index 463ed2eaff..a11c939c30 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -144,7 +144,7 @@ else work=`git write-tree` && git read-tree --reset $new && git checkout-index -f -u -q -a && - git read-tree -m -u $old $new $work || exit + git read-tree -m -u --aggressive $old $new $work || exit if result=`git write-tree 2>/dev/null` then