From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 5/5] diff: support --exclude
Date: Thu, 10 Mar 2011 10:13:39 +0700 [thread overview]
Message-ID: <1299726819-5576-6-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1299726819-5576-1-git-send-email-pclouds@gmail.com>
diff_setup_done() will update diff_options.pathspec, so if you give
--exclude '*.h' -- src/
then the final pathspec looks like
- src/
- *.h (negated)
The code is protected against multiple call because setup_revisions()
may call it once, then the outer code calls it again. I'm not sure if
doing it this way is correct though.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
diff.c | 41 ++++++++++++++++++++++++++++++++++++++++-
diff.h | 1 +
2 files changed, 41 insertions(+), 1 deletions(-)
diff --git a/diff.c b/diff.c
index 6f206a9..14f1cfc 100644
--- a/diff.c
+++ b/diff.c
@@ -2973,6 +2973,34 @@ int diff_setup_done(struct diff_options *options)
DIFF_OPT_SET(options, EXIT_WITH_STATUS);
}
+ /*
+ * Adjust options->pathspec. All --exclude will be appended to
+ * options->pathspec with to_exclude set.
+ */
+ if (options->paths &&
+ options->pathspec.raw != options->paths) { /* avoid being called twice */
+ int i, nr, new_nr, exc;
+
+ nr = options->pathspec.nr ? options->pathspec.nr : 1;
+ for (exc = 0; options->paths[exc]; exc++)
+ ; /* nothing */
+ new_nr = nr + exc;
+
+ options->paths = xrealloc(options->paths, sizeof(char*) * (new_nr + 1));
+ memmove(options->paths + nr, options->paths, sizeof(char*) * (exc + 1));
+ if (options->pathspec.nr)
+ memcpy(options->paths, options->pathspec.raw, sizeof(char*) * nr);
+ else
+ options->paths[0] = "";
+
+ free_pathspec(&options->pathspec);
+ init_pathspec(&options->pathspec, options->paths);
+ for (i = nr; i < new_nr; i++) {
+ struct pathspec_item *item = options->pathspec.items + i;
+ item->to_exclude = 1;
+ }
+ }
+
return 0;
}
@@ -2980,6 +3008,7 @@ int diff_setup_done(struct diff_options *options)
void release_diff(struct diff_options *o)
{
free_pathspec(&o->pathspec);
+ free(o->paths);
}
static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val)
@@ -3347,7 +3376,17 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
die_errno("Could not open '%s'", optarg);
options->close_file = 1;
return argcount;
- } else
+ }
+ else if ((argcount = parse_long_opt("exclude", av, &optarg))) {
+ int i = 1;
+ while (options->paths && options->paths[i])
+ i++;
+ options->paths = xrealloc(options->paths, sizeof(char*) * (i + 1));
+ options->paths[i - 1] = optarg;
+ options->paths[i] = 0;
+ return argcount;
+ }
+ else
return 0;
return 1;
}
diff --git a/diff.h b/diff.h
index 12a9907..b60057c 100644
--- a/diff.h
+++ b/diff.h
@@ -134,6 +134,7 @@ struct diff_options {
int close_file;
struct pathspec pathspec;
+ const char **paths;
change_fn_t change;
add_remove_fn_t add_remove;
diff_format_fn_t format_callback;
--
1.7.3.1.256.g2539c.dirty
next prev parent reply other threads:[~2011-03-10 3:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-10 3:13 [WIP PATCH 0/5] support --exclude for diff/log commands Nguyễn Thái Ngọc Duy
2011-03-10 3:13 ` [PATCH 1/5] tree-walk: support negative pathspec Nguyễn Thái Ngọc Duy
2011-03-10 3:13 ` [PATCH 2/5] match_pathspec_depth: " Nguyễn Thái Ngọc Duy
2011-03-10 3:13 ` [PATCH 3/5] revision.c: get rid of struct rev_info.prune_data Nguyễn Thái Ngọc Duy
2011-03-10 6:20 ` Junio C Hamano
2011-03-10 6:52 ` Nguyen Thai Ngoc Duy
2011-03-10 3:13 ` [PATCH 4/5] diff: refactor init/release API Nguyễn Thái Ngọc Duy
2011-03-10 3:13 ` Nguyễn Thái Ngọc Duy [this message]
2011-03-10 6:11 ` [WIP PATCH 0/5] support --exclude for diff/log commands Junio C Hamano
2011-03-10 7:03 ` Nguyen Thai Ngoc Duy
2011-03-10 8:41 ` Junio C Hamano
2011-03-10 10:05 ` Nguyen Thai Ngoc Duy
2011-03-21 4:02 ` Nguyen Thai Ngoc Duy
2011-03-21 9:45 ` Michael J Gruber
2011-03-21 10:02 ` Nguyen Thai Ngoc Duy
2011-03-22 23:59 ` Junio C Hamano
2011-03-23 12:10 ` Nguyen Thai Ngoc Duy
2011-03-23 12:18 ` Nguyen Thai Ngoc Duy
2011-03-23 12:51 ` Michael J Gruber
2011-03-23 13:34 ` Nguyen Thai Ngoc Duy
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=1299726819-5576-6-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.