+static void apply_patch_list(struct patch *patch)
+{
+ if (!patch)
+ die("no patch found");
+ do {
+ const char *old_name = patch->old_name;
+ const char *new_name = patch->new_name;
+ struct fragment *frag;
+
+ if (old_name) {
+ if (cache_name_pos(old_name, strlen(old_name)) < 0)
+ die("file %s does not exist", old_name);
+ if (patch->is_new < 0)
+ patch->is_new = 0;
+ }
+ if (new_name && (patch->is_new | patch->is_rename | patch->is_copy)) {
+ if (cache_name_pos(new_name, strlen(new_name)) >= 0)
+ die("file %s already exists", new_name);
+ }
+
+ printf("Applying patch to %s\n", new_name);
+ printf(" new=%d delete=%d copy=%d rename=%d\n",
+ patch->is_new, patch->is_delete, patch->is_copy, patch->is_rename);
+ if (patch->old_mode != patch->new_mode)
+ printf(" %o->%o\n", patch->old_mode, patch->new_mode);
+ frag = patch->fragments;
+ while (frag) {
+ printf("Fragment %lu,%lu -> %lu,%lu\n%.*s",
+ frag->oldpos, frag->oldlines,
+ frag->newpos, frag->newlines,
+ frag->size, frag->patch);
+ frag = frag->next;
+ }
+
+ } while ((patch = patch->next) != NULL);
+}
+