From: Junio C Hamano <junkio@cox.net>
To: Linus Torvalds <torvalds@osdl.org>
Cc: git@vger.kernel.org
Subject: [PATCH] Optionally tell show-diff to show only named files
Date: Sat, 16 Apr 2005 16:15:00 -0700 [thread overview]
Message-ID: <7vy8bi48ln.fsf@assigned-by-dhcp.cox.net> (raw)
SCMs have ways to say "I want diff only this particular file",
or "I want diff files under this directory". This patch teaches
show-diff to do something similar. Without command line
arguments, it still examines everything in the dircache as
before.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
show-diff.c | 38 ++++++++++++++++++++++++++++++--------
1 files changed, 30 insertions(+), 8 deletions(-)
show-diff.c: 5f3d4699566843a5448260e5da286ed65d90e397
--- show-diff.c
+++ show-diff.c 2005-04-16 16:07:07.000000000 -0700
@@ -55,6 +55,23 @@
}
}
+static const char *show_diff_usage = "show-diff [-s] [-q] [paths...]";
+
+static int matches_pathspec(struct cache_entry *ce, char **spec, int cnt)
+{
+ int i;
+ int namelen = ce_namelen(ce);
+ for (i = 0; i < cnt; i++) {
+ int speclen = strlen(spec[i]);
+ if (! strncmp(spec[i], ce->name, speclen) &&
+ speclen <= namelen &&
+ (ce->name[speclen] == 0 ||
+ ce->name[speclen] == '/'))
+ return 1;
+ }
+ return 0;
+}
+
int main(int argc, char **argv)
{
int silent = 0;
@@ -62,18 +79,19 @@
int entries = read_cache();
int i;
- for (i = 1; i < argc; i++) {
- if (!strcmp(argv[i], "-s")) {
+ while (1 < argc && argv[1][0] == '-') {
+ if (!strcmp(argv[1], "-s"))
silent_on_nonexisting_files = silent = 1;
- continue;
- }
- if (!strcmp(argv[i], "-q")) {
+ else if (!strcmp(argv[1], "-q"))
silent_on_nonexisting_files = 1;
- continue;
- }
- usage("show-diff [-s] [-q]");
+ else
+ usage(show_diff_usage);
+ argv++; argc--;
}
+ /* At this point, if argc == 1, then we are doing everything.
+ * Otherwise argv[1] .. argv[argc-1] have the explicit paths.
+ */
if (entries < 0) {
perror("read_cache");
exit(1);
@@ -86,6 +104,10 @@
char type[20];
void *new;
+ if (1 <argc &&
+ ! matches_pathspec(ce, argv+1, argc-1))
+ continue;
+
if (stat(ce->name, &st) < 0) {
if (errno == ENOENT && silent_on_nonexisting_files)
continue;
reply other threads:[~2005-04-16 23:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=7vy8bi48ln.fsf@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=git@vger.kernel.org \
--cc=torvalds@osdl.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