git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Fitzsimons <robfitz@273k.net>
To: git@vger.kernel.org
Cc: Robert Fitzsimons <robfitz@273k.net>
Subject: [PATCH 7/9] New option --ignore-applied for git-apply.
Date: Sun, 28 Aug 2005 15:24:56 +0000	[thread overview]
Message-ID: <11252426961236-git-send-email-robfitz@273k.net> (raw)
In-Reply-To: <1125242692932-git-send-email-robfitz@273k.net>

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     |    6 ++
 apply.c                         |   12 +++++
 t/t4108-apply-ignore-applied.sh |   94 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 110 insertions(+), 2 deletions(-)
 create mode 100644 t/t4108-apply-ignore-applied.sh

5e36f3b7c8ca0710096552ce3f20f16da04e601b
diff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt
--- a/Documentation/git-apply.txt
+++ b/Documentation/git-apply.txt
@@ -12,7 +12,7 @@ SYNOPSIS
 'git-apply' [--no-merge] [--stat] [--summary] [--check]
 		[--index] [--show-files] [--apply]
 		[--force-delete] [--ignore-whitespace]
-		[<patch>...]
+		[--ignore-applied] [<patch>...]
 
 DESCRIPTION
 -----------
@@ -73,6 +73,10 @@ OPTIONS
 	When matching the patch to the file contents ignore
 	sequences of tabs or spaces.
 
+--ignore-applied::
+	If a patch hunk (fragment) fails to apply, reverse the
+	hunk and check if the hunk has already been applied.
+
 Author
 ------
 Written by Linus Torvalds <torvalds@osdl.org>
diff --git a/apply.c b/apply.c
--- a/apply.c
+++ b/apply.c
@@ -34,8 +34,9 @@ static int apply = 1;
 static int show_files = 0;
 static int force_delete = 0;
 static int ignore_whitespace = 0;
+static int ignore_applied = 0;
 static const char apply_usage[] =
-"git-apply [--no-merge] [--stat] [--summary] [--check] [--index] [--apply] [--show-files] [--force-delete] [--ignore-whitespace] <patch>...";
+"git-apply [--no-merge] [--stat] [--summary] [--check] [--index] [--apply] [--show-files] [--force-delete] [--ignore-whitespace] [--ignore-applied] <patch>...";
 
 /*
  * For "diff-stat" like behaviour, we keep track of the biggest change
@@ -985,6 +986,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);
@@ -1607,6 +1613,10 @@ int main(int argc, char **argv)
 			ignore_whitespace = 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" \
+    '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" \
+    'cat patch1.patch patch2.patch patch3.patch | git-apply --check --ignore-applied'
+
+test_done
+

  reply	other threads:[~2005-08-28 15:23 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-28 15:24 [PATCH 1/9] Fix git patch header processing in git-apply Robert Fitzsimons
2005-08-28 15:24 ` [PATCH 2/9] Fix detection of files with only one line " Robert Fitzsimons
2005-08-28 15:24   ` [PATCH 3/9] Fix processing of a patch file which modifies the same file " Robert Fitzsimons
2005-08-28 15:24     ` [PATCH 4/9] Fix the procssing of multiple patch files with --check " Robert Fitzsimons
2005-08-28 15:24       ` [PATCH 5/9] New option --force-delete for git-apply Robert Fitzsimons
2005-08-28 15:24         ` [PATCH 6/9] New option --ignore-whitespace " Robert Fitzsimons
2005-08-28 15:24           ` Robert Fitzsimons [this message]
2005-08-28 15:25             ` [PATCH 8/9] New git-apply test cases for patches with mulitple fragments Robert Fitzsimons
2005-08-28 15:25               ` [PATCH 9/9] New git-apply test cases for scanning forwards and backwards Robert Fitzsimons
2005-08-28 16:58           ` [PATCH 6/9] New option --ignore-whitespace for git-apply Linus Torvalds
2005-08-28 20:49             ` A Large Angry SCM
2005-08-28 21:06           ` Junio C Hamano
2005-08-28 21:06         ` [PATCH 5/9] New option --force-delete " Junio C Hamano
2005-08-28 21:06     ` [PATCH 3/9] Fix processing of a patch file which modifies the same file in git-apply Junio C Hamano
2005-08-28 16:55   ` [PATCH 2/9] Fix detection of files with only one line " Linus Torvalds
2005-08-28 23:39 ` [PATCH 1/9] Fix git patch header processing " Junio C Hamano
2005-08-29 23:58   ` Robert Fitzsimons
2005-08-30  0:47     ` Linus Torvalds
2005-08-30  1:09       ` Junio C Hamano
2005-08-30  1:24         ` Linus Torvalds
2005-08-30  1:34           ` Junio C Hamano
2005-08-30  2:00             ` Linus Torvalds
2005-08-30  7:36               ` Martin Langhoff

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

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

  git send-email \
    --in-reply-to=11252426961236-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.
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 NNTP newsgroup(s).