summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0f2303f)
raw | patch | inline | side by side (parent: 0f2303f)
author | Junio C Hamano <junkio@cox.net> | |
Sun, 17 Apr 2005 04:29:45 +0000 (21:29 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Sun, 17 Apr 2005 04:29:45 +0000 (21:29 -0700) |
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>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
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>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
show-diff.c | patch | blob | history |
diff --git a/show-diff.c b/show-diff.c
index 6f343c56bd52ec180f0e22283a2d053bb1f6737e..f9e8c12f90e793bc039a6181a6b6424b3725f6dc 100644 (file)
--- a/show-diff.c
+++ b/show-diff.c
}
}
+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;
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);
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;