From: Joe Perches <joe@perches.com>
To: git@vger.kernel.org
Subject: [PATCH] git-apply - Add --include=PATH
Date: Sat, 23 Aug 2008 13:37:49 -0700 [thread overview]
Message-ID: <1219523869.18365.106.camel@localhost> (raw)
Add similar capability to --exclude=
Allows selection of files to patch from a
large patchset.
Signed-off-by: Joe Perches <joe@perches.com>
Documentation/git-apply.txt | 8 +++++++-
builtin-apply.c | 27 +++++++++++++++++++++++++--
2 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt
index feb51f1..2467e62 100644
--- a/Documentation/git-apply.txt
+++ b/Documentation/git-apply.txt
@@ -14,7 +14,8 @@ SYNOPSIS
[--allow-binary-replacement | --binary] [--reject] [-z]
[-pNUM] [-CNUM] [--inaccurate-eof] [--recount] [--cached]
[--whitespace=<nowarn|warn|fix|error|error-all>]
- [--exclude=PATH] [--directory=<root>] [--verbose] [<patch>...]
+ [--exclude=PATH] [--include=PATH] [--directory=<root>]
+ [--verbose] [<patch>...]
DESCRIPTION
-----------
@@ -137,6 +138,11 @@ discouraged.
be useful when importing patchsets, where you want to exclude certain
files or directories.
+--include=<path-pattern>::
+ Apply changes to files matching the given path pattern. This can
+ be useful when importing patchsets, where you want to include certain
+ files or directories.
+
--whitespace=<action>::
When applying a patch, detect a new or modified line that has
whitespace errors. What are considered whitespace errors is
diff --git a/builtin-apply.c b/builtin-apply.c
index 2216a0b..121a6d0 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -46,7 +46,7 @@ static const char *fake_ancestor;
static int line_termination = '\n';
static unsigned long p_context = ULONG_MAX;
static const char apply_usage[] =
-"git apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [--reverse] [--reject] [--verbose] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|fix|error|error-all>] <patch>...";
+"git apply [--stat] [--numstat] [--summary] [--check] [--index] [--cached] [--apply] [--no-add] [--index-info] [--allow-binary-replacement] [--reverse] [--reject] [--verbose] [-z] [-pNUM] [-CNUM] [--whitespace=<nowarn|warn|fix|error|error-all>] [--exclude=PATH] [--include=PATH] <patch>...";
static enum ws_error_action {
nowarn_ws_error,
@@ -2996,10 +2996,16 @@ static struct excludes {
const char *path;
} *excludes;
+static struct includes {
+ struct includes *next;
+ const char *path;
+} *includes;
+
static int use_patch(struct patch *p)
{
const char *pathname = p->new_name ? p->new_name : p->old_name;
struct excludes *x = excludes;
+ struct includes *y = includes;
while (x) {
if (fnmatch(x->path, pathname, 0) == 0)
return 0;
@@ -3011,7 +3017,17 @@ static int use_patch(struct patch *p)
memcmp(prefix, pathname, prefix_length))
return 0;
}
- return 1;
+
+ if (!y || !y->path)
+ return 1;
+
+ while (y && y->path) {
+ if (fnmatch(y->path, pathname, 0) == 0)
+ return 1;
+ y = y->next;
+ }
+
+ return 0;
}
static void prefix_one(char **name)
@@ -3160,6 +3176,13 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
excludes = x;
continue;
}
+ if (!prefixcmp(arg, "--include=")) {
+ struct includes *y = xmalloc(sizeof(*y));
+ y->path = arg + 10;
+ y->next = includes;
+ includes = y;
+ continue;
+ }
if (!prefixcmp(arg, "-p")) {
p_value = atoi(arg + 2);
p_value_known = 1;
next reply other threads:[~2008-08-23 20:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-23 20:37 Joe Perches [this message]
2008-08-24 0:54 ` [PATCH] git-apply - Add --include=PATH Junio C Hamano
2008-08-24 21:57 ` Joe Perches
2008-08-25 8:05 ` 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1219523869.18365.106.camel@localhost \
--to=joe@perches.com \
--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).