Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'apply.c')
-rw-r--r--apply.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/apply.c b/apply.c
index 7e5792c996..49752cde44 100644
--- a/apply.c
+++ b/apply.c
@@ -9,6 +9,7 @@
#include "cache.h"
#include "config.h"
+#include "object-store.h"
#include "blob.h"
#include "delta.h"
#include "diff.h"
@@ -141,6 +142,8 @@ int check_apply_state(struct apply_state *state, int force_apply)
return error(_("--cached outside a repository"));
state->check_index = 1;
}
+ if (state->ita_only && (state->check_index || is_not_gitdir))
+ state->ita_only = 0;
if (state->check_index)
state->unsafe_paths = 0;
@@ -2375,7 +2378,7 @@ static void update_pre_post_images(struct image *preimage,
if (postlen
? postlen < new_buf - postimage->buf
: postimage->len < new_buf - postimage->buf)
- die("BUG: caller miscounted postlen: asked %d, orig = %d, used = %d",
+ BUG("caller miscounted postlen: asked %d, orig = %d, used = %d",
(int)postlen, (int) postimage->len, (int)(new_buf - postimage->buf));
/* Fix the length of the whole thing */
@@ -3509,7 +3512,7 @@ static int load_current(struct apply_state *state,
unsigned mode = patch->new_mode;
if (!patch->is_new)
- die("BUG: patch to %s is not a creation", patch->old_name);
+ BUG("patch to %s is not a creation", patch->old_name);
pos = cache_name_pos(name, strlen(name));
if (pos < 0)
@@ -3860,9 +3863,9 @@ static int check_unsafe_path(struct patch *patch)
if (!patch->is_delete)
new_name = patch->new_name;
- if (old_name && !verify_path(old_name))
+ if (old_name && !verify_path(old_name, patch->old_mode))
return error(_("invalid path '%s'"), old_name);
- if (new_name && !verify_path(new_name))
+ if (new_name && !verify_path(new_name, patch->new_mode))
return error(_("invalid path '%s'"), new_name);
return 0;
}
@@ -4053,12 +4056,12 @@ static int preimage_oid_in_gitlink_patch(struct patch *p, struct object_id *oid)
return get_oid_hex(p->old_sha1_prefix, oid);
}
-/* Build an index that contains the just the files needed for a 3way merge */
+/* Build an index that contains just the files needed for a 3way merge */
static int build_fake_ancestor(struct apply_state *state, struct patch *list)
{
struct patch *patch;
struct index_state result = { NULL };
- static struct lock_file lock;
+ struct lock_file lock = LOCK_INIT;
int res;
/* Once we start supporting the reverse patch, it may be
@@ -4242,7 +4245,7 @@ static void patch_stats(struct apply_state *state, struct patch *patch)
static int remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)
{
- if (state->update_index) {
+ if (state->update_index && !state->ita_only) {
if (remove_file_from_cache(patch->old_name) < 0)
return error(_("unable to remove %s from index"), patch->old_name);
}
@@ -4265,15 +4268,15 @@ static int add_index_file(struct apply_state *state,
int namelen = strlen(path);
unsigned ce_size = cache_entry_size(namelen);
- if (!state->update_index)
- return 0;
-
ce = xcalloc(1, ce_size);
memcpy(ce->name, path, namelen);
ce->ce_mode = create_ce_mode(mode);
ce->ce_flags = create_ce_flags(0);
ce->ce_namelen = namelen;
- if (S_ISGITLINK(mode)) {
+ if (state->ita_only) {
+ ce->ce_flags |= CE_INTENT_TO_ADD;
+ set_object_name_for_intent_to_add_entry(ce);
+ } else if (S_ISGITLINK(mode)) {
const char *s;
if (!skip_prefix(buf, "Subproject commit ", &s) ||
@@ -4465,8 +4468,9 @@ static int create_file(struct apply_state *state, struct patch *patch)
if (patch->conflicted_threeway)
return add_conflicted_stages_file(state, patch);
- else
+ else if (state->update_index)
return add_index_file(state, path, mode, buf, size);
+ return 0;
}
/* phase zero is to remove, phase one is to create */
@@ -4686,7 +4690,7 @@ static int apply_patch(struct apply_state *state,
if (state->whitespace_error && (state->ws_error_action == die_on_ws_error))
state->apply = 0;
- state->update_index = state->check_index && state->apply;
+ state->update_index = (state->check_index || state->ita_only) && state->apply;
if (state->update_index && !is_lock_file_locked(&state->lock_file)) {
if (state->index_file)
hold_lock_file_for_update(&state->lock_file,
@@ -4941,6 +4945,8 @@ int apply_parse_options(int argc, const char **argv,
N_("instead of applying the patch, see if the patch is applicable")),
OPT_BOOL(0, "index", &state->check_index,
N_("make sure the patch is applicable to the current index")),
+ OPT_BOOL('N', "intent-to-add", &state->ita_only,
+ N_("mark new files with `git add --intent-to-add`")),
OPT_BOOL(0, "cached", &state->cached,
N_("apply a patch without touching the working tree")),
OPT_BOOL_F(0, "unsafe-paths", &state->unsafe_paths,