git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 2/3] Fix the processing of multiple patch files with --check in git-apply.
  2005-08-30  0:01 [PATCH 1/3] Fix the processing of a patch file which modifies the same file in git-apply Robert Fitzsmons
@ 2005-08-30  0:01 ` Robert Fitzsmons
  2005-08-30  0:01   ` [PATCH 3/3] New option --ignore-applied for git-apply Robert Fitzsmons
       [not found]   ` <7vll2ccs4k.fsf@assigned-by-dhcp.cox.net>
  0 siblings, 2 replies; 4+ messages in thread
From: Robert Fitzsmons @ 2005-08-30  0:01 UTC (permalink / raw)
  To: git; +Cc: Robert Fitzsimons

When the --check option was used with multiple patch files which
modify the same files, the patch can fail because the previously
modified contents aren't written to the disk.

So save the in memory patch contents across the processing of multiple
patch files.  Added a new test case for --check with multiple patch
files.

Signed-off-by: Robert Fitzsimons <robfitz@273k.net>

---

 apply.c                |   10 ++++-
 t/t4105-apply-check.sh |   89 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 2 deletions(-)
 create mode 100644 t/t4105-apply-check.sh

797cc1bdcc647b9fb744784969c814145803407d
diff --git a/apply.c b/apply.c
--- a/apply.c
+++ b/apply.c
@@ -1439,13 +1439,16 @@ static int use_patch(struct patch *p)
 	return 1;
 }
 
+struct patch *master_list = NULL;
+struct patch *master_list_prev = NULL;
+
 static int apply_patch(int fd)
 {
 	int newfd;
 	unsigned long offset, size;
 	char *buffer = read_patch_file(fd, &size);
-	struct patch *list = NULL, **listp = &list;
-	struct patch *list_prev = NULL;
+	struct patch *list = master_list, **listp = &list;
+	struct patch *list_prev = master_list_prev;
 	int skipped_patch = 0;
 
 	if (!buffer)
@@ -1504,6 +1507,9 @@ static int apply_patch(int fd)
 	if (summary)
 		summary_patch_list(list);
 
+	master_list = list;
+	master_list_prev = list_prev;
+
 	free(buffer);
 	return 0;
 }
diff --git a/t/t4105-apply-check.sh b/t/t4105-apply-check.sh
new file mode 100644
--- /dev/null
+++ b/t/t4105-apply-check.sh
@@ -0,0 +1,89 @@
+#!/bin/sh
+#
+# Copyright (c) 2005 Junio C Hamano
+# Copyright (c) 2005 Robert Fitzsimons
+#
+
+test_description='git-apply --check with multiple files.
+
+'
+. ./test-lib.sh
+
+# setup
+
+cat > patch1.patch <<\EOF
+diff --git a/main.c b/main.c
+new file mode 100644
+--- /dev/null
++++ b/main.c
+@@ -0,0 +1,23 @@
++#include <stdio.h>
++
++void print_int(int num);
++int func(int num);
++
++int main() {
++	int i;
++
++	for (i = 0; i < 10; i++) {
++		print_int(func(i));
++	}
++
++	return 0;
++}
++
++int func(int num) {
++	return num * num;
++}
++
++void print_int(int num) {
++	printf("%d", num);
++}
++
+EOF
+cat > patch2.patch <<\EOF
+diff --git a/main.c b/main.c
+--- a/main.c
++++ b/main.c
+@@ -10,6 +10,8 @@
+ 		print_int(func(i));
+ 	}
+ 
++	printf("\n");
++
+ 	return 0;
+ }
+ 
+EOF
+cat > patch3.patch <<\EOF
+diff --git a/main.c b/main.c
+--- a/main.c
++++ b/main.c
+@@ -18,6 +20,6 @@
+ }
+ 
+ void print_int(int num) {
+-	printf("%d", num);
++	printf("%d ", num);
+ }
+ 
+EOF
+
+test_expect_success "S = test 1 (files)" \
+    'git-apply patch1.patch patch2.patch patch3.patch'
+rm -f main.c
+
+test_expect_success "S = test 2 (files --check)" \
+    'git-apply --check patch1.patch patch2.patch patch3.patch'
+rm -f main.c
+
+test_expect_success "S = test 3 (stdin)" \
+    'cat patch1.patch patch2.patch patch3.patch | git-apply'
+rm -f main.c
+
+test_expect_success "S = test 4 (stdin --check)" \
+    'cat patch1.patch patch2.patch patch3.patch | git-apply --check'
+rm -f main.c
+
+test_done
+

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] Fix the processing of a patch file which modifies the same file in git-apply.
@ 2005-08-30  0:01 Robert Fitzsmons
  2005-08-30  0:01 ` [PATCH 2/3] Fix the processing of multiple patch files with --check " Robert Fitzsmons
  0 siblings, 1 reply; 4+ messages in thread
From: Robert Fitzsmons @ 2005-08-30  0:01 UTC (permalink / raw)
  To: git; +Cc: Robert Fitzsimons

A patch file (or stdin) which modifies the same file more then once
will fail to apply the patch correctly.  In the worst case it will
apply some of the patch and leave an invalid output file(s).

apply.c has been changed to search for previously processed files and
use the in memory copy of the data instead of the on disk image.

Added a series of test cases for the processing of complex single
file patches.  The test cases have been updated to not use empty
files.

Signed-off-by: Robert Fitzsimons <robfitz@273k.net>

---

 apply.c                  |   64 +++++++++++-
 t/t4104-apply-complex.sh |  241 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 300 insertions(+), 5 deletions(-)
 create mode 100644 t/t4104-apply-complex.sh

1c680d2768e248e4df3ef24591b7d53913199885
diff --git a/apply.c b/apply.c
--- a/apply.c
+++ b/apply.c
@@ -67,6 +67,7 @@ struct patch {
 	char *result;
 	unsigned long resultsize;
 	struct patch *next;
+	struct patch *prev;
 };
 
 #define CHUNKSIZE (8192)
@@ -974,7 +975,7 @@ static int apply_fragments(struct buffer
 	return 0;
 }
 
-static int apply_data(struct patch *patch, struct stat *st)
+static int apply_data(struct patch *patch, struct patch *old_patch, struct stat *st)
 {
 	char *buf;
 	unsigned long size, alloc;
@@ -983,7 +984,13 @@ static int apply_data(struct patch *patc
 	size = 0;
 	alloc = 0;
 	buf = NULL;
-	if (patch->old_name) {
+
+	if (patch->old_name && old_patch) {
+		size = old_patch->resultsize;
+		alloc = size + 8192;
+		buf = xmalloc(alloc);
+		memcpy(buf, old_patch->result, size);
+	} else if (patch->old_name) {
 		size = st->st_size;
 		alloc = size + 8192;
 		buf = xmalloc(alloc);
@@ -1010,8 +1017,46 @@ static int check_patch(struct patch *pat
 	struct stat st;
 	const char *old_name = patch->old_name;
 	const char *new_name = patch->new_name;
+	struct patch *old_patch = NULL;
+	struct patch *new_patch = NULL;
 
 	if (old_name) {
+		for (old_patch = patch->prev; old_patch; old_patch = old_patch->prev) {
+			if (old_patch->new_name && !strcmp(old_name, old_patch->new_name)) {
+				break;
+			}
+			if (old_patch->old_name && !strcmp(old_name, old_patch->old_name)) {
+				if (old_patch->is_delete || old_patch->is_rename) {
+					return error("%s: file missing because of previous patch", old_name);
+				}
+				break;
+			}
+		}
+	}
+
+	if (new_name) {
+		for (new_patch = patch->prev; new_patch; new_patch = new_patch->prev) {
+			if (new_patch->new_name && !strcmp(new_name, new_patch->new_name)) {
+				if (patch->is_new || patch->is_rename || patch->is_copy)
+					return error("%s: file exists from previous patch (new)", new_name);
+				break;
+			}
+			if (new_patch->old_name && !strcmp(new_name, new_patch->old_name)) {
+				if (!(patch->is_new || patch->is_delete || patch->is_rename || patch->is_copy))
+					break;
+				if (new_patch->is_delete || new_patch->is_rename)
+					break;
+				return error("%s: file exists from previous patch (old)", new_name);
+			}
+		}
+	}
+
+	if (old_patch) {
+		if (patch->is_new < 0)
+			patch->is_new = 0;
+		if (!patch->old_mode)
+			patch->old_mode = old_patch->new_mode;
+	} else if (old_name) {
 		int changed;
 
 		if (lstat(old_name, &st) < 0)
@@ -1036,7 +1081,14 @@ static int check_patch(struct patch *pat
 				old_name, st.st_mode, patch->old_mode);
 	}
 
-	if (new_name && (patch->is_new | patch->is_rename | patch->is_copy)) {
+	if (new_patch) {
+		if (!patch->new_mode) {
+			if (patch->is_new)
+				patch->new_mode = S_IFREG | 0644;
+			else
+				patch->new_mode = patch->old_mode;
+		}
+	} else if (new_name && (patch->is_new | patch->is_rename | patch->is_copy)) {
 		if (check_index && cache_name_pos(new_name, strlen(new_name)) >= 0)
 			return error("%s: already exists in index", new_name);
 		if (!lstat(new_name, &st))
@@ -1061,7 +1113,7 @@ static int check_patch(struct patch *pat
 				same ? "" : " of ", same ? "" : old_name);
 	}	
 
-	if (apply_data(patch, &st) < 0)
+	if (apply_data(patch, old_patch, &st) < 0)
 		return error("%s: patch does not apply", old_name);
 	return 0;
 }
@@ -1393,6 +1445,7 @@ static int apply_patch(int fd)
 	unsigned long offset, size;
 	char *buffer = read_patch_file(fd, &size);
 	struct patch *list = NULL, **listp = &list;
+	struct patch *list_prev = NULL;
 	int skipped_patch = 0;
 
 	if (!buffer)
@@ -1409,7 +1462,8 @@ static int apply_patch(int fd)
 			break;
 		if (use_patch(patch)) {
 			patch_stats(patch);
-			*listp = patch;
+			patch->prev = list_prev;
+			list_prev = *listp = patch;
 			listp = &patch->next;
 		} else {
 			/* perhaps free it a bit better? */
diff --git a/t/t4104-apply-complex.sh b/t/t4104-apply-complex.sh
new file mode 100644
--- /dev/null
+++ b/t/t4104-apply-complex.sh
@@ -0,0 +1,241 @@
+#!/bin/sh
+#
+# Copyright (c) 2005 Junio C Hamano
+# Copyright (c) 2005 Robert Fitzsimons
+#
+
+test_description='git-apply complex patches.
+
+'
+. ./test-lib.sh
+
+# setup
+
+# Nx, new file x.txt
+# Dx, delete file x.txt
+# Rxy, rename x.txt to y.txt
+# Cxy, copy x.txt to y.txt
+# Px1, patch x.txt with patch number 1
+# etc
+
+cat > Nx <<\EOF
+diff --git a/x.txt b/x.txt
+new file mode 100644
+--- /dev/null
++++ b/x.txt
+@@ -0,0 +1 @@
++XYZ
+EOF
+cat > Ny <<\EOF
+diff --git a/y.txt b/y.txt
+new file mode 100644
+--- /dev/null
++++ b/y.txt
+@@ -0,0 +1 @@
++XYZ
+EOF
+cat > Rxy <<\EOF
+diff --git a/x.txt b/y.txt
+rename from x.txt
+rename to y.txt
+--- a/x.txt
++++ b/y.txt
+EOF
+cat > Ryx <<\EOF
+diff --git a/y.txt b/x.txt
+rename from y.txt
+rename to x.txt
+--- a/y.txt
++++ b/x.txt
+EOF
+cat > Cxy <<\EOF
+diff --git a/x.txt b/y.txt
+copy from x.txt
+copy to y.txt
+--- a/x.txt
++++ b/y.txt
+EOF
+cat > Cyx <<\EOF
+diff --git a/y.txt b/x.txt
+copy from y.txt
+copy to x.txt
+--- a/y.txt
++++ b/x.txt
+EOF
+cat > Dx <<\EOF
+diff --git a/x.txt b/x.txt
+deleted file mode 100644
+--- a/x.txt
++++ /dev/null
+@@ -1 +0,0 @@
+-XYZ
+EOF
+cat > Dy <<\EOF
+diff --git a/y.txt b/y.txt
+deleted file mode 100644
+--- a/y.txt
++++ /dev/null
+@@ -1 +0,0 @@
+-XYZ
+EOF
+cat > Px1 <<\EOF
+diff --git a/x.txt b/x.txt
+--- a/x.txt
++++ b/x.txt
+@@ -1 +1,2 @@
+ XYZ
++XXX
+EOF
+cat > Px2 <<\EOF
+diff --git a/x.txt b/x.txt
+--- a/x.txt
++++ b/x.txt
+@@ -1,2 +1,3 @@
+ XYZ
+ XXX
++XX
+EOF
+cat > Px3 <<\EOF
+diff --git a/x.txt b/x.txt
+--- a/x.txt
++++ b/x.txt
+@@ -1,3 +1,2 @@
+ XYZ
+ XXX
+-XX
+EOF
+cat > Px4 <<\EOF
+diff --git a/x.txt b/x.txt
+--- a/x.txt
++++ b/x.txt
+@@ -1,2 +1 @@
+ XYZ
+-XXX
+EOF
+
+test_expect_success "S = Nx Cxy Dx Dy Ny Ryx Cxy Dx Dy (files)" \
+    'git-apply Nx Cxy Dx Dy Ny Ryx Cxy Dx Dy'
+rm -f x.txt y.txt
+
+test_expect_success "S = Nx Cxy Dx Dy Ny Ryx Cxy Dx Dy (stdin)" \
+    'cat Nx Cxy Dx Dy Ny Ryx Cxy Dx Dy | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Nx" \
+    'cat Nx | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Nx Dx" \
+    'cat Nx Dx | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Nx Px1" \
+    'cat Nx Px1 | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Nx Px1 Px2" \
+    'cat Nx Px1 Px2 | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Nx Px1 Px2 Px3" \
+    'cat Nx Px1 Px2 Px3 | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Nx Px1 Px2 Px3 Px4" \
+    'cat Nx Px1 Px2 Px3 Px4 | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Nx Px1 Px2 Px3 Px4 Dx" \
+    'cat Nx Px1 Px2 Px3 Px4 Dx | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Nx Rxy" \
+    'cat Nx Rxy | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Nx Rxy Dy" \
+    'cat Nx Rxy Dy| git-apply -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Nx Cxy" \
+    'cat Nx Cxy | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Nx Rxy Dx Dy" \
+    'cat Nx Cxy Dx Dy | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Ny Ryx Px1 Px2 Cxy Px3 Px4 Dx" \
+    'cat Ny Ryx Px1 Px2 Cxy Px3 Px4 Dx | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Ny Ryx Px1 Px2 Cxy Px3 Px4 Dx Cyx" \
+    'cat Ny Ryx Px1 Px2 Cxy Px3 Px4 Dx Cyx | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Ny Cyx Px1 Px2 Px3 Px4 Dy Cxy Dx Cyx Dy Rxy Dy" \
+    'cat Ny Cyx Px1 Px2 Px3 Px4 Dy Cxy Dx Cyx Dy Rxy Dy | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_failure "F = Dx" \
+    'cat Dx | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_failure "F = Rxy" \
+    'cat Rxy | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_failure "F = Cxy" \
+    'cat Cxy | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_failure "F = Nx Dx Dx" \
+    'cat Nx Dx Dx | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_failure "F = Nx Ny Rxy" \
+    'cat Nx Ny Rxy | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_failure "F = Ny Rxy" \
+    'cat Ny Rxy | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_failure "F = Nx Ny Cxy" \
+    'cat Nx Ny Cxy | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_failure "F = Ny Cxy" \
+    'cat Ny Cxy | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_failure "F = Nx Cxy Cxy" \
+    'cat Nx Cxy Cxy | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_failure "F = Nx Cxy Cyx" \
+    'cat Nx Cxy Cyx | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_failure "F = Nx Rxy Rxy" \
+    'cat Nx Rxy Rxy | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_failure "F = Nx Rxy Cxy" \
+    'cat Nx Rxy Cxy | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_failure "F = Ny Ryx Px1 Px2 Px3 Dx Cyx Px2" \
+    'cat Ny Ryx Px1 Px2 Px3 Dx Cyx Px2 | git-apply -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Nx Cxy Dx Cyx Dy Rxy Dy Nx Ny Dx Ryx Cxy Dx Dy Nx Rxy Dy Nx Cxy Dy Dx (--check)" \
+    'cat Nx Cxy Dx Cyx Dy Rxy Dy Nx Ny Dx Ryx Cxy Dx Dy Nx Rxy Dy Nx Cxy Dy Dx | git-apply --check -'
+rm -f x.txt y.txt
+
+test_expect_success "S = Nx Cxy Dx Cyx Dy Rxy Dy Nx Ny Dx Ryx Cxy Dx Dy Nx Rxy Dy Nx Cxy Dy Dx" \
+    'cat Nx Cxy Dx Cyx Dy Rxy Dy Nx Ny Dx Ryx Cxy Dx Dy Nx Rxy Dy Nx Cxy Dy Dx | git-apply -'
+rm -f x.txt y.txt
+
+test_done
+

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] New option --ignore-applied for git-apply.
  2005-08-30  0:01 ` [PATCH 2/3] Fix the processing of multiple patch files with --check " Robert Fitzsmons
@ 2005-08-30  0:01   ` Robert Fitzsmons
       [not found]   ` <7vll2ccs4k.fsf@assigned-by-dhcp.cox.net>
  1 sibling, 0 replies; 4+ messages in thread
From: Robert Fitzsmons @ 2005-08-30  0:01 UTC (permalink / raw)
  To: git; +Cc: Robert Fitzsimons

Allow the user to allow a patch which has some hunks (fragments)
already applied to succeed.  Added test case and documentation.

Signed-off-by: Robert Fitzsimons <robfitz@273k.net>

---

 Documentation/git-apply.txt     |    7 ++-
 apply.c                         |   12 +++++
 t/t4108-apply-ignore-applied.sh |   94 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+), 2 deletions(-)
 create mode 100644 t/t4108-apply-ignore-applied.sh

e8f2ff89f44b0c4d35dea3d86331a5e00fadf27e
diff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt
--- a/Documentation/git-apply.txt
+++ b/Documentation/git-apply.txt
@@ -9,7 +9,9 @@ git-apply - Apply patch on a GIT index f
 
 SYNOPSIS
 --------
-'git-apply' [--no-merge] [--stat] [--summary] [--check] [--index] [--show-files] [--apply] [<patch>...]
+'git-apply' [--no-merge] [--stat] [--summary] [--check]
+		[--index] [--show-files] [--apply]
+		[--ignore-applied] [<patch>...]
 
 DESCRIPTION
 -----------
@@ -61,6 +63,9 @@ OPTIONS
 	patch.  Give this flag after those flags to also apply
 	the patch.
 
+--ignore-applied::
+	If a patch hunk (fragment) fails to apply, reverse the
+	hunk and check if the hunk has already been applied.
 
 Author
 ------
diff --git a/apply.c b/apply.c
--- a/apply.c
+++ b/apply.c
@@ -32,8 +32,9 @@ static int summary = 0;
 static int check = 0;
 static int apply = 1;
 static int show_files = 0;
+static int ignore_applied = 0;
 static const char apply_usage[] =
-"git-apply [--no-merge] [--stat] [--summary] [--check] [--index] [--apply] [--show-files] <patch>...";
+"git-apply [--no-merge] [--stat] [--summary] [--check] [--index] [--apply] [--show-files] [--ignore-applied] <patch>...";
 
 /*
  * For "diff-stat" like behaviour, we keep track of the biggest change
@@ -956,6 +957,11 @@ static int apply_one_fragment(struct buf
 		memmove(buf + offset + newsize, buf + offset + oldsize, size - offset - newsize);
 		memcpy(buf + offset, new, newsize);
 		offset = 0;
+	} else if (ignore_applied) {
+		offset = find_offset(buf, desc->size, new, newsize, frag->newpos);
+		if (offset >= 0) {
+			offset = 0;
+		}
 	}
 
 	free(old);
@@ -1567,6 +1573,10 @@ int main(int argc, char **argv)
 			show_files = 1;
 			continue;
 		}
+		if (!strcmp(arg, "--ignore-applied")) {
+			ignore_applied = 1;
+			continue;
+		}
 		fd = open(arg, O_RDONLY);
 		if (fd < 0)
 			usage(apply_usage);
diff --git a/t/t4108-apply-ignore-applied.sh b/t/t4108-apply-ignore-applied.sh
new file mode 100644
--- /dev/null
+++ b/t/t4108-apply-ignore-applied.sh
@@ -0,0 +1,94 @@
+#!/bin/sh
+#
+# Copyright (c) 2005 Junio C Hamano
+# Copyright (c) 2005 Robert Fitzsimons
+#
+
+test_description='git-apply --ignore-applied.
+
+'
+. ./test-lib.sh
+
+# setup
+
+cat > patch1.patch <<\EOF
+diff --git a/main.c b/main.c
+new file mode 100644
+--- /dev/null
++++ b/main.c
+@@ -0,0 +1,23 @@
++#include <stdio.h>
++
++void print_int(int num);
++int func(int num);
++
++int main() {
++	int i;
++
++	for (i = 0; i < 10; i++) {
++		print_int(func(i));
++	}
++
++	return 0;
++}
++
++int func(int num) {
++	return num * num;
++}
++
++void print_int(int num) {
++	printf("%d", num);
++}
++
+EOF
+cat > patch2.patch <<\EOF
+diff --git a/main.c b/main.c
+--- a/main.c
++++ b/main.c
+@@ -10,6 +10,8 @@
+ 		print_int(func(i));
+ 	}
+ 
++	printf("\n");
++
+ 	return 0;
+ }
+ 
+EOF
+cat > patch3.patch <<\EOF
+diff --git a/main.c b/main.c
+--- a/main.c
++++ b/main.c
+@@ -10,6 +10,8 @@
+ 		print_int(func(i));
+ 	}
+ 
++	printf("\n");
++
+ 	return 0;
+ }
+ 
+@@ -18,6 +20,6 @@
+ }
+ 
+ void print_int(int num) {
+-	printf("%d", num);
++	printf("%d ", num);
+ }
+ 
+EOF
+
+test_expect_failure "F = test 1" \
+    'cat patch1.patch patch2.patch patch2.patch | git-apply --check'
+
+test_expect_success "S = test 2 (--ignore-applied)" \
+    'cat patch1.patch patch2.patch patch2.patch | git-apply --check --ignore-applied'
+
+test_expect_failure "F = test 3" \
+    'cat patch1.patch patch3.patch patch3.patch | git-apply --check'
+
+test_expect_success "S = test 4 (--ignore-applied)" \
+    'cat patch1.patch patch2.patch patch3.patch | git-apply --check --ignore-applied'
+
+test_done
+

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/3] Fix the processing of multiple patch files with --check in git-apply.
       [not found]     ` <20050905123445.GA27107@localhost>
@ 2005-09-07  0:54       ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2005-09-07  0:54 UTC (permalink / raw)
  To: Robert Fitzsimons; +Cc: git

Robert Fitzsimons <robfitz@273k.net> writes:

> No problem I know it's a controversial change.

Not really controversial anymore, as long as --ignore-applied is
used only when appropriate.

>>> Yes my change has a bug with a copy patch which modifies the same file.
> I'll send on a fix now.

Here is another one that the patch seems to regress.

Unfortunately this turns out to be a death sentence to the
'multiple patch touching the same file' patch.

Note that patches from a single 'git-diff-*' run are supposed to
be independent, so the second one that copy-edits from frotz to
rezrov copies frotz _before_ it is modified and then makes its
modification.

On the other hand, we can have one 'git-diff-*' run that
modifies frotz in place, and then a separate 'git-diff-*' run
that copies frotz to rezrov and then modifies rezrov, and feed
the concatenation of the two to git-apply.  That would look very
similar to a single run that edits frotz and copy-edits rezrov,
but the pre-image to create rezrov would use the post-edit image
of frotz from the first patch.  Without an explicit "here an
output from the next git-diff-*' run begins" marker, we cannot
tell these two apart.

This means that applying multiple-patches concatenated in a
single file does not make much sense.  There is no guarantee
that we can detect where the first 'git-diff-*' output ends, at
which point we need to reset the status of 'frotz' to
post-modification image of the first patch.  And if we can
detect reliably where one 'git-diff-*' output ends and the next
one begins, we could just split the input there and run
git-apply independently.  So my conclusion is to just drop this
patch, and instead tell people not to feed overlapping outputs
from multiple git-diff-* runs to a single invocation of
git-apply.

I personally do not mind considering --ignore-applied
independently from the multiple-patch-files changes, though.

------------
echo frotz >frotz
git-apply --check <<\EOF
diff --git a/frotz b/frotz
--- a/frotz
+++ b/frotz
@@ -1 +1 @@
-frotz
+frottz
diff --git a/frotz b/rezrov
similarity index 64%
copy from frotz
copy to rezrov
--- a/frotz
+++ b/rezrov
@@ -1 +1 @@
-frotz
+frotttz
EOF

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-09-07  0:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-30  0:01 [PATCH 1/3] Fix the processing of a patch file which modifies the same file in git-apply Robert Fitzsmons
2005-08-30  0:01 ` [PATCH 2/3] Fix the processing of multiple patch files with --check " Robert Fitzsmons
2005-08-30  0:01   ` [PATCH 3/3] New option --ignore-applied for git-apply Robert Fitzsmons
     [not found]   ` <7vll2ccs4k.fsf@assigned-by-dhcp.cox.net>
     [not found]     ` <20050905123445.GA27107@localhost>
2005-09-07  0:54       ` [PATCH 2/3] Fix the processing of multiple patch files with --check in git-apply Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).