From: Jeff King <peff@peff.net>
To: Christian Jaeger <christian@pflanze.mine.nu>
Cc: Michael J Gruber <git@drmicha.warpmail.net>,
Erik Hahn <erik_hahn@gmx.de>,
git@vger.kernel.org
Subject: Re: Excluding files from git-diff
Date: Sat, 18 Oct 2008 12:58:34 -0400 [thread overview]
Message-ID: <20081018165834.GA28364@coredump.intra.peff.net> (raw)
In-Reply-To: <20081018161424.GC20185@coredump.intra.peff.net>
On Sat, Oct 18, 2008 at 12:14:24PM -0400, Jeff King wrote:
> The most flexible thing would be the ability to say "I want these paths
> (or all paths), and exclude these paths" (sort of like we already do for
> commits). But defining a good command-line syntax for that would
> probably be painful, and I really think the only sane use case is "I
> want all paths except for these". In which case your "--invert-match"
> seems like a good route.
I looked at this a little, so here's as far as I got, in case it helps
you in writing a patch.
There are actually two ways the limiter is used:
1. diff will show only a subset of the paths, as contained in a
diff_options.paths variable
2. the revision walker will prune based based on changes in particular
paths (e.g., "git log --invert-path -- .gitignore" should show only
commits that touch something besides .gitignore)
The code to handle '1' might look something like the patch below, but
this doesn't deal at all with revision pruning.
---
diff --git a/diff.c b/diff.c
index 1c6be89..a72f593 100644
--- a/diff.c
+++ b/diff.c
@@ -2646,6 +2646,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
DIFF_OPT_CLR(options, ALLOW_EXTERNAL);
else if (!strcmp(arg, "--ignore-submodules"))
DIFF_OPT_SET(options, IGNORE_SUBMODULES);
+ else if (!strcmp(arg, "--invert-path"))
+ DIFF_OPT_SET(options, INVERT_PATH);
/* misc options */
else if (!strcmp(arg, "-z"))
diff --git a/diff.h b/diff.h
index a49d865..43f3bff 100644
--- a/diff.h
+++ b/diff.h
@@ -65,6 +65,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
#define DIFF_OPT_IGNORE_SUBMODULES (1 << 18)
#define DIFF_OPT_DIRSTAT_CUMULATIVE (1 << 19)
#define DIFF_OPT_DIRSTAT_BY_FILE (1 << 20)
+#define DIFF_OPT_INVERT_PATH (1 << 21)
#define DIFF_OPT_TST(opts, flag) ((opts)->flags & DIFF_OPT_##flag)
#define DIFF_OPT_SET(opts, flag) ((opts)->flags |= DIFF_OPT_##flag)
#define DIFF_OPT_CLR(opts, flag) ((opts)->flags &= ~DIFF_OPT_##flag)
diff --git a/tree-diff.c b/tree-diff.c
index 9f67af6..ef78d91 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -91,7 +91,7 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, const
* - zero for no
* - negative for "no, and no subsequent entries will be either"
*/
-static int tree_entry_interesting(struct tree_desc *desc, const char *base, int baselen, struct diff_options *opt)
+static int tree_entry_interesting_internal(struct tree_desc *desc, const char *base, int baselen, struct diff_options *opt)
{
const char *path;
const unsigned char *sha1;
@@ -190,6 +190,17 @@ static int tree_entry_interesting(struct tree_desc *desc, const char *base, int
return never_interesting; /* No matches */
}
+static int tree_entry_interesting(struct tree_desc *desc, const char *base, int baselen, struct diff_options *opt)
+{
+ int r = tree_entry_interesting_internal(desc, base, baselen, opt);
+ if (!DIFF_OPT_TST(opt, INVERT_PATH))
+ return r;
+ return r < 0 ? 2 :
+ r == 0 ? 1 :
+ r == 1 ? 0 :
+ /* r > 1 */ -1;
+}
+
/* A whole sub-tree went away or appeared */
static void show_tree(struct diff_options *opt, const char *prefix, struct tree_desc *desc, const char *base, int baselen)
{
next prev parent reply other threads:[~2008-10-18 16:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-17 14:53 Excluding files from git-diff Erik Hahn
2008-10-17 15:08 ` Raphael Zimmerer
2008-10-17 15:08 ` Johannes Schindelin
2008-10-17 15:18 ` Michael J Gruber
2008-10-17 16:30 ` Christian Jaeger
2008-10-17 17:33 ` Eric Raible
2008-10-18 3:50 ` Christian Jaeger
2008-10-18 15:59 ` Jeff King
2008-10-18 16:08 ` Christian Jaeger
2008-10-18 16:14 ` Jeff King
2008-10-18 16:58 ` Jeff King [this message]
2008-10-17 23:38 ` Anders Melchiorsen
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=20081018165834.GA28364@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=christian@pflanze.mine.nu \
--cc=erik_hahn@gmx.de \
--cc=git@drmicha.warpmail.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).