]> git.ipfire.org Git - thirdparty/git.git/blobdiff - apply.c
builtin/show-index: set the algorithm for object IDs
[thirdparty/git.git] / apply.c
diff --git a/apply.c b/apply.c
index 76dba93c974b3814117e3856d875e7e4381d2f62..466f880d737dbdbff8259e89ec9767643fb248e1 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -21,6 +21,7 @@
 #include "quote.h"
 #include "rerere.h"
 #include "apply.h"
+#include "entry.h"
 
 struct gitdiff_data {
        struct strbuf *root;
@@ -1781,7 +1782,7 @@ static int parse_single_patch(struct apply_state *state,
                struct fragment *fragment;
                int len;
 
-               fragment = xcalloc(1, sizeof(*fragment));
+               CALLOC_ARRAY(fragment, 1);
                fragment->linenr = state->linenr;
                len = parse_fragment(state, line, size, patch, fragment);
                if (len <= 0) {
@@ -1959,7 +1960,7 @@ static struct fragment *parse_binary_hunk(struct apply_state *state,
                size -= llen;
        }
 
-       frag = xcalloc(1, sizeof(*frag));
+       CALLOC_ARRAY(frag, 1);
        frag->patch = inflate_it(data, hunk_size, origlen);
        frag->free_patch = 1;
        if (!frag->patch)
@@ -3948,10 +3949,8 @@ static int check_patch(struct apply_state *state, struct patch *patch)
                        break; /* happy */
                case EXISTS_IN_INDEX:
                        return error(_("%s: already exists in index"), new_name);
-                       break;
                case EXISTS_IN_INDEX_AS_ITA:
                        return error(_("%s: does not match index"), new_name);
-                       break;
                case EXISTS_IN_WORKTREE:
                        return error(_("%s: already exists in working directory"),
                                     new_name);
@@ -4409,7 +4408,7 @@ static int create_one_file(struct apply_state *state,
                return 0;
 
        if (errno == ENOENT) {
-               if (safe_create_leading_directories(path))
+               if (safe_create_leading_directories_no_share(path))
                        return 0;
                res = try_create_file(state, path, mode, buf, size);
                if (res < 0)
@@ -4683,7 +4682,7 @@ static int apply_patch(struct apply_state *state,
                struct patch *patch;
                int nr;
 
-               patch = xcalloc(1, sizeof(*patch));
+               CALLOC_ARRAY(patch, 1);
                patch->inaccurate_eof = !!(options & APPLY_OPT_INACCURATE_EOF);
                patch->recount =  !!(options & APPLY_OPT_RECOUNT);
                nr = parse_chunk(state, buf.buf + offset, buf.len - offset, patch);
@@ -4699,8 +4698,13 @@ static int apply_patch(struct apply_state *state,
                        reverse_patches(patch);
                if (use_patch(state, patch)) {
                        patch_stats(state, patch);
-                       *listp = patch;
-                       listp = &patch->next;
+                       if (!list || !state->apply_in_reverse) {
+                               *listp = patch;
+                               listp = &patch->next;
+                       } else {
+                               patch->next = list;
+                               list = patch;
+                       }
 
                        if ((patch->new_name &&
                             ends_with_path_components(patch->new_name,