+ struct stat st;
+ const char *old_name = patch->old_name;
+ const char *new_name = patch->new_name;
+
+ if (old_name) {
+ int pos = cache_name_pos(old_name, strlen(old_name));
+ int changed;
+
+ if (pos < 0)
+ return error("%s: does not exist in index", old_name);
+ if (patch->is_new < 0)
+ patch->is_new = 0;
+ if (lstat(old_name, &st) < 0)
+ return error("%s: %s\n", strerror(errno));
+ changed = ce_match_stat(active_cache[pos], &st);
+ if (changed)
+ return error("%s: does not match index", old_name);
+ if (!patch->old_mode)
+ patch->old_mode = st.st_mode;
+ }
+
+ if (new_name && (patch->is_new | patch->is_rename | patch->is_copy)) {
+ if (cache_name_pos(new_name, strlen(new_name)) >= 0)
+ return error("%s: already exists in index", new_name);
+ if (!lstat(new_name, &st))
+ return error("%s: already exists in working directory", new_name);
+ if (errno != ENOENT)
+ return error("%s: %s", new_name, strerror(errno));
+ }
+ return 0;
+}
+
+static int check_patch_list(struct patch *patch)
+{
+ int error = 0;
+
+ for (;patch ; patch = patch->next)
+ error |= check_patch(patch);
+ return error;
+}
+
+static void show_file(int c, unsigned int mode, const char *name)
+{
+ printf("%c %o %s\n", c, mode, name);
+}