push: propagate remote and refspec with --recurse-submodules
[gitweb.git] / apply.c
diff --git a/apply.c b/apply.c
index 201d3a73586bdd52131439a8d259345e5f188d19..e6dbab26ad54b9a3af06f6adad928c6e1526db58 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -122,9 +122,9 @@ int check_apply_state(struct apply_state *state, int force_apply)
        int is_not_gitdir = !startup_info->have_repository;
 
        if (state->apply_with_reject && state->threeway)
-               return error("--reject and --3way cannot be used together.");
+               return error(_("--reject and --3way cannot be used together."));
        if (state->cached && state->threeway)
-               return error("--cached and --3way cannot be used together.");
+               return error(_("--cached and --3way cannot be used together."));
        if (state->threeway) {
                if (is_not_gitdir)
                        return error(_("--3way outside a repository"));
@@ -1586,8 +1586,8 @@ static int find_header(struct apply_state *state,
                                patch->new_name = xstrdup(patch->def_name);
                        }
                        if (!patch->is_delete && !patch->new_name) {
-                               error("git diff header lacks filename information "
-                                            "(line %d)", state->linenr);
+                               error(_("git diff header lacks filename information "
+                                            "(line %d)"), state->linenr);
                                return -128;
                        }
                        patch->is_toplevel_relative = 1;
@@ -2046,7 +2046,7 @@ static void prefix_one(struct apply_state *state, char **name)
        char *old_name = *name;
        if (!old_name)
                return;
-       *name = xstrdup(prefix_filename(state->prefix, state->prefix_length, *name));
+       *name = prefix_filename(state->prefix, *name);
        free(old_name);
 }
 
@@ -2187,29 +2187,20 @@ static int parse_chunk(struct apply_state *state, char *buffer, unsigned long si
        return offset + hdrsize + patchsize;
 }
 
-#define swap(a,b) myswap((a),(b),sizeof(a))
-
-#define myswap(a, b, size) do {                \
-       unsigned char mytmp[size];      \
-       memcpy(mytmp, &a, size);                \
-       memcpy(&a, &b, size);           \
-       memcpy(&b, mytmp, size);                \
-} while (0)
-
 static void reverse_patches(struct patch *p)
 {
        for (; p; p = p->next) {
                struct fragment *frag = p->fragments;
 
-               swap(p->new_name, p->old_name);
-               swap(p->new_mode, p->old_mode);
-               swap(p->is_new, p->is_delete);
-               swap(p->lines_added, p->lines_deleted);
-               swap(p->old_sha1_prefix, p->new_sha1_prefix);
+               SWAP(p->new_name, p->old_name);
+               SWAP(p->new_mode, p->old_mode);
+               SWAP(p->is_new, p->is_delete);
+               SWAP(p->lines_added, p->lines_deleted);
+               SWAP(p->old_sha1_prefix, p->new_sha1_prefix);
 
                for (; frag; frag = frag->next) {
-                       swap(frag->newpos, frag->oldpos);
-                       swap(frag->newlines, frag->oldlines);
+                       SWAP(frag->newpos, frag->oldpos);
+                       SWAP(frag->newlines, frag->oldlines);
                }
        }
 }
@@ -3095,8 +3086,8 @@ static int apply_binary_fragment(struct apply_state *state,
        /* Binary patch is irreversible without the optional second hunk */
        if (state->apply_in_reverse) {
                if (!fragment->next)
-                       return error("cannot reverse-apply a binary patch "
-                                    "without the reverse hunk to '%s'",
+                       return error(_("cannot reverse-apply a binary patch "
+                                      "without the reverse hunk to '%s'"),
                                     patch->new_name
                                     ? patch->new_name : patch->old_name);
                fragment = fragment->next;
@@ -3141,8 +3132,8 @@ static int apply_binary(struct apply_state *state,
            strlen(patch->new_sha1_prefix) != 40 ||
            get_oid_hex(patch->old_sha1_prefix, &oid) ||
            get_oid_hex(patch->new_sha1_prefix, &oid))
-               return error("cannot apply binary patch to '%s' "
-                            "without full index line", name);
+               return error(_("cannot apply binary patch to '%s' "
+                              "without full index line"), name);
 
        if (patch->old_name) {
                /*
@@ -3151,16 +3142,16 @@ static int apply_binary(struct apply_state *state,
                 */
                hash_sha1_file(img->buf, img->len, blob_type, oid.hash);
                if (strcmp(oid_to_hex(&oid), patch->old_sha1_prefix))
-                       return error("the patch applies to '%s' (%s), "
-                                    "which does not match the "
-                                    "current contents.",
+                       return error(_("the patch applies to '%s' (%s), "
+                                      "which does not match the "
+                                      "current contents."),
                                     name, oid_to_hex(&oid));
        }
        else {
                /* Otherwise, the old one must be empty. */
                if (img->len)
-                       return error("the patch applies to an empty "
-                                    "'%s' but it is not empty", name);
+                       return error(_("the patch applies to an empty "
+                                      "'%s' but it is not empty"), name);
        }
 
        get_oid_hex(patch->new_sha1_prefix, &oid);
@@ -3177,8 +3168,8 @@ static int apply_binary(struct apply_state *state,
 
                result = read_sha1_file(oid.hash, &type, &size);
                if (!result)
-                       return error("the necessary postimage %s for "
-                                    "'%s' cannot be read",
+                       return error(_("the necessary postimage %s for "
+                                      "'%s' cannot be read"),
                                     patch->new_sha1_prefix, name);
                clear_image(img);
                img->buf = result;
@@ -3551,10 +3542,10 @@ static int try_threeway(struct apply_state *state,
                write_sha1_file("", 0, blob_type, pre_oid.hash);
        else if (get_sha1(patch->old_sha1_prefix, pre_oid.hash) ||
                 read_blob_object(&buf, &pre_oid, patch->old_mode))
-               return error("repository lacks the necessary blob to fall back on 3-way merge.");
+               return error(_("repository lacks the necessary blob to fall back on 3-way merge."));
 
        if (state->apply_verbosity > verbosity_silent)
-               fprintf(stderr, "Falling back to three-way merge...\n");
+               fprintf(stderr, _("Falling back to three-way merge...\n"));
 
        img = strbuf_detach(&buf, &len);
        prepare_image(&tmp_image, img, len, 1);
@@ -3570,11 +3561,11 @@ static int try_threeway(struct apply_state *state,
        /* our_oid is ours */
        if (patch->is_new) {
                if (load_current(state, &tmp_image, patch))
-                       return error("cannot read the current contents of '%s'",
+                       return error(_("cannot read the current contents of '%s'"),
                                     patch->new_name);
        } else {
                if (load_preimage(state, &tmp_image, patch, st, ce))
-                       return error("cannot read the current contents of '%s'",
+                       return error(_("cannot read the current contents of '%s'"),
                                     patch->old_name);
        }
        write_sha1_file(tmp_image.buf, tmp_image.len, blob_type, our_oid.hash);
@@ -3586,7 +3577,7 @@ static int try_threeway(struct apply_state *state,
        if (status < 0) {
                if (state->apply_verbosity > verbosity_silent)
                        fprintf(stderr,
-                               "Failed to fall back on three-way merge...\n");
+                               _("Failed to fall back on three-way merge...\n"));
                return status;
        }
 
@@ -3600,12 +3591,12 @@ static int try_threeway(struct apply_state *state,
                oidcpy(&patch->threeway_stage[2], &post_oid);
                if (state->apply_verbosity > verbosity_silent)
                        fprintf(stderr,
-                               "Applied patch to '%s' with conflicts.\n",
+                               _("Applied patch to '%s' with conflicts.\n"),
                                patch->new_name);
        } else {
                if (state->apply_verbosity > verbosity_silent)
                        fprintf(stderr,
-                               "Applied patch to '%s' cleanly.\n",
+                               _("Applied patch to '%s' cleanly.\n"),
                                patch->new_name);
        }
        return 0;
@@ -4072,18 +4063,18 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
                        if (!preimage_oid_in_gitlink_patch(patch, &oid))
                                ; /* ok, the textual part looks sane */
                        else
-                               return error("sha1 information is lacking or "
-                                            "useless for submodule %s", name);
+                               return error(_("sha1 information is lacking or "
+                                              "useless for submodule %s"), name);
                } else if (!get_sha1_blob(patch->old_sha1_prefix, oid.hash)) {
                        ; /* ok */
                } else if (!patch->lines_added && !patch->lines_deleted) {
                        /* mode-only change: update the current */
                        if (get_current_oid(state, patch->old_name, &oid))
-                               return error("mode change for %s, which is not "
-                                            "in current HEAD", name);
+                               return error(_("mode change for %s, which is not "
+                                              "in current HEAD"), name);
                } else
-                       return error("sha1 information is lacking or useless "
-                                    "(%s).", name);
+                       return error(_("sha1 information is lacking or useless "
+                                      "(%s)."), name);
 
                ce = make_cache_entry(patch->old_mode, oid.hash, name, 0, 0);
                if (!ce)
@@ -4091,7 +4082,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
                                     name);
                if (add_index_entry(&result, ce, ADD_CACHE_OK_TO_ADD)) {
                        free(ce);
-                       return error("Could not add %s to temporary index",
+                       return error(_("could not add %s to temporary index"),
                                     name);
                }
        }
@@ -4101,7 +4092,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
        discard_index(&result);
 
         if (res)
-                return error("Could not write temporary index to %s",
+                return error(_("could not write temporary index to %s"),
                              state->fake_ancestor);
 
         return 0;
@@ -4688,7 +4679,7 @@ static int apply_patch(struct apply_state *state,
                                                                 state->index_file,
                                                                 LOCK_DIE_ON_ERROR);
                else
-                       state->newfd = hold_locked_index(state->lock_file, 1);
+                       state->newfd = hold_locked_index(state->lock_file, LOCK_DIE_ON_ERROR);
        }
 
        if (state->check_index && read_apply_cache(state) < 0) {
@@ -4814,6 +4805,7 @@ int apply_all_patches(struct apply_state *state,
 
        for (i = 0; i < argc; i++) {
                const char *arg = argv[i];
+               char *to_free = NULL;
                int fd;
 
                if (!strcmp(arg, "-")) {
@@ -4823,21 +4815,21 @@ int apply_all_patches(struct apply_state *state,
                        errs |= res;
                        read_stdin = 0;
                        continue;
-               } else if (0 < state->prefix_length)
-                       arg = prefix_filename(state->prefix,
-                                             state->prefix_length,
-                                             arg);
+               } else
+                       arg = to_free = prefix_filename(state->prefix, arg);
 
                fd = open(arg, O_RDONLY);
                if (fd < 0) {
                        error(_("can't open patch '%s': %s"), arg, strerror(errno));
                        res = -128;
+                       free(to_free);
                        goto end;
                }
                read_stdin = 0;
                set_default_whitespace_mode(state);
                res = apply_patch(state, fd, arg, options);
                close(fd);
+               free(to_free);
                if (res < 0)
                        goto end;
                errs |= res;