Merge branch 'jk/init-core-worktree-at-root'
[gitweb.git] / builtin / apply.c
index 0ca687fa6b049b29d12ec417afcbec8491ecdc2c..146be97a1a879242aa12eb066c5c69cd6af92409 100644 (file)
@@ -56,7 +56,7 @@ static const char *fake_ancestor;
 static int line_termination = '\n';
 static unsigned int p_context = UINT_MAX;
 static const char * const apply_usage[] = {
-       N_("git apply [options] [<patch>...]"),
+       N_("git apply [<options>] [<patch>...]"),
        NULL
 };
 
@@ -208,7 +208,7 @@ struct patch {
        struct patch *next;
 
        /* three-way fallback result */
-       unsigned char threeway_stage[3][20];
+       struct object_id threeway_stage[3];
 };
 
 static void free_fragment_list(struct fragment *list)
@@ -1601,6 +1601,9 @@ static int parse_fragment(const char *line, unsigned long size,
                        if (!deleted && !added)
                                leading++;
                        trailing++;
+                       if (!apply_in_reverse &&
+                           ws_error_action == correct_ws_error)
+                               check_whitespace(line, len, patch->ws_rule);
                        break;
                case '-':
                        if (apply_in_reverse &&
@@ -2773,7 +2776,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
                default:
                        if (apply_verbosely)
                                error(_("invalid start of line: '%c'"), first);
-                       return -1;
+                       applied_pos = -1;
+                       goto out;
                }
                if (added_blank_line) {
                        if (!new_blank_lines_at_end)
@@ -2912,6 +2916,7 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
                              (int)(old - oldlines), oldlines);
        }
 
+out:
        free(oldlines);
        strbuf_release(&newlines);
        free(preimage.line_allocated);
@@ -3421,11 +3426,11 @@ static int try_threeway(struct image *image, struct patch *patch,
        if (status) {
                patch->conflicted_threeway = 1;
                if (patch->is_new)
-                       hashclr(patch->threeway_stage[0]);
+                       oidclr(&patch->threeway_stage[0]);
                else
-                       hashcpy(patch->threeway_stage[0], pre_sha1);
-               hashcpy(patch->threeway_stage[1], our_sha1);
-               hashcpy(patch->threeway_stage[2], post_sha1);
+                       hashcpy(patch->threeway_stage[0].hash, pre_sha1);
+               hashcpy(patch->threeway_stage[1].hash, our_sha1);
+               hashcpy(patch->threeway_stage[2].hash, post_sha1);
                fprintf(stderr, "Applied patch to '%s' with conflicts.\n", patch->new_name);
        } else {
                fprintf(stderr, "Applied patch to '%s' cleanly.\n", patch->new_name);
@@ -4181,14 +4186,14 @@ static void add_conflicted_stages_file(struct patch *patch)
 
        remove_file_from_cache(patch->new_name);
        for (stage = 1; stage < 4; stage++) {
-               if (is_null_sha1(patch->threeway_stage[stage - 1]))
+               if (is_null_oid(&patch->threeway_stage[stage - 1]))
                        continue;
                ce = xcalloc(1, ce_size);
                memcpy(ce->name, patch->new_name, namelen);
                ce->ce_mode = create_ce_mode(mode);
                ce->ce_flags = create_ce_flags(stage);
                ce->ce_namelen = namelen;
-               hashcpy(ce->sha1, patch->threeway_stage[stage - 1]);
+               hashcpy(ce->sha1, patch->threeway_stage[stage - 1].hash);
                if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0)
                        die(_("unable to add cache entry for %s"), patch->new_name);
        }