提交 b8f80925 编写于 作者: J Junio C Hamano 提交者: Linus Torvalds

[PATCH] Optionally tell show-diff to show only named files

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: NJunio C Hamano <junkio@cox.net>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 0f2303f7
...@@ -55,6 +55,23 @@ static void show_diff_empty(struct cache_entry *ce) ...@@ -55,6 +55,23 @@ static void show_diff_empty(struct cache_entry *ce)
} }
} }
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 main(int argc, char **argv)
{ {
int silent = 0; int silent = 0;
...@@ -62,18 +79,19 @@ int main(int argc, char **argv) ...@@ -62,18 +79,19 @@ int main(int argc, char **argv)
int entries = read_cache(); int entries = read_cache();
int i; int i;
for (i = 1; i < argc; i++) { while (1 < argc && argv[1][0] == '-') {
if (!strcmp(argv[i], "-s")) { if (!strcmp(argv[1], "-s"))
silent_on_nonexisting_files = silent = 1; silent_on_nonexisting_files = silent = 1;
continue; else if (!strcmp(argv[1], "-q"))
}
if (!strcmp(argv[i], "-q")) {
silent_on_nonexisting_files = 1; silent_on_nonexisting_files = 1;
continue; else
} usage(show_diff_usage);
usage("show-diff [-s] [-q]"); 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) { if (entries < 0) {
perror("read_cache"); perror("read_cache");
exit(1); exit(1);
...@@ -86,6 +104,10 @@ int main(int argc, char **argv) ...@@ -86,6 +104,10 @@ int main(int argc, char **argv)
char type[20]; char type[20];
void *new; void *new;
if (1 <argc &&
! matches_pathspec(ce, argv+1, argc-1))
continue;
if (stat(ce->name, &st) < 0) { if (stat(ce->name, &st) < 0) {
if (errno == ENOENT && silent_on_nonexisting_files) if (errno == ENOENT && silent_on_nonexisting_files)
continue; continue;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册