git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Robert Fitzsmons <robfitz@273k.net>
To: git@vger.kernel.org
Cc: Robert Fitzsimons <robfitz@273k.net>
Subject: [PATCH 2/3] Fix the processing of multiple patch files with --check in git-apply.
Date: Tue, 30 Aug 2005 00:01:51 +0000	[thread overview]
Message-ID: <11253601111257-git-send-email-robfitz@273k.net> (raw)
In-Reply-To: <1125360111916-git-send-email-robfitz@273k.net>

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
+

  reply	other threads:[~2005-08-30  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11253601111257-git-send-email-robfitz@273k.net \
    --to=robfitz@273k.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).