#include "blob.h"
#include "delta.h"
#include "builtin.h"
-#include "path-list.h"
+#include "string-list.h"
/*
* --check turns on checking that the working tree matches the
static int line_termination = '\n';
static unsigned long p_context = ULONG_MAX;
static const char apply_usage[] =
-"git-apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [--reverse] [--reject] [--verbose] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|fix|error|error-all>] <patch>...";
+"git apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [--reverse] [--reject] [--verbose] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|fix|error|error-all>] <patch>...";
static enum ws_error_action {
nowarn_ws_error,
* the case where more than one patches touch the same file.
*/
-static struct path_list fn_table;
+static struct string_list fn_table;
static uint32_t hash_line(const char *cp, size_t len)
{
static struct patch *in_fn_table(const char *name)
{
- struct path_list_item *item;
+ struct string_list_item *item;
if (name == NULL)
return NULL;
- item = path_list_lookup(name, &fn_table);
+ item = string_list_lookup(name, &fn_table);
if (item != NULL)
return (struct patch *)item->util;
static void add_to_fn_table(struct patch *patch)
{
- struct path_list_item *item;
+ struct string_list_item *item;
/*
* Always add new_name unless patch is a deletion
* file creations and copies
*/
if (patch->new_name != NULL) {
- item = path_list_insert(patch->new_name, &fn_table);
+ item = string_list_insert(patch->new_name, &fn_table);
item->util = patch;
}
* later chunks shouldn't patch old names
*/
if ((patch->new_name == NULL) || (patch->is_rename)) {
- item = path_list_insert(patch->old_name, &fn_table);
+ item = string_list_insert(patch->old_name, &fn_table);
item->util = (struct patch *) -1;
}
}
strbuf_init(&buf, 0);
- if ((tpatch = in_fn_table(patch->old_name)) != NULL) {
+ if (!(patch->is_copy || patch->is_rename) &&
+ ((tpatch = in_fn_table(patch->old_name)) != NULL)) {
if (tpatch == (struct patch *) -1) {
return error("patch %s has been renamed/deleted",
patch->old_name);
static int check_preimage(struct patch *patch, struct cache_entry **ce, struct stat *st)
{
const char *old_name = patch->old_name;
- struct patch *tpatch;
+ struct patch *tpatch = NULL;
int stat_ret = 0;
unsigned st_mode = 0;
return 0;
assert(patch->is_new <= 0);
- if ((tpatch = in_fn_table(old_name)) != NULL) {
+
+ if (!(patch->is_copy || patch->is_rename) &&
+ (tpatch = in_fn_table(old_name)) != NULL) {
if (tpatch == (struct patch *) -1) {
return error("%s: has been deleted/renamed", old_name);
}
if (stat_ret && errno != ENOENT)
return error("%s: %s", old_name, strerror(errno));
}
+
if (check_index && !tpatch) {
int pos = cache_name_pos(old_name, strlen(old_name));
if (pos < 0) {
int skipped_patch = 0;
/* FIXME - memory leak when using multiple patch files as inputs */
- memset(&fn_table, 0, sizeof(struct path_list));
+ memset(&fn_table, 0, sizeof(struct string_list));
strbuf_init(&buf, 0);
patch_input_file = filename;
read_patch_file(&buf, fd);