[PATCH] Make "git diff" work inside relative subdirectories
We always show the diff as an absolute path, but pathnames to diff are taken relative to the current working directory (and if no pathnames are given, the default ends up being all of the current working directory). Note that "../xyz" also works, so you can do cd linux/drivers/char git diff ../block and it will generate a diff of the linux/drivers/block changes. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:

committed by
Junio C Hamano

parent
83db04ff87
commit
d288a70030
12
diff-cache.c
12
diff-cache.c
@ -168,10 +168,11 @@ static const char diff_cache_usage[] =
|
||||
"[<common diff options>] <tree-ish> [<path>...]"
|
||||
COMMON_DIFF_OPTIONS_HELP;
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *tree_name = NULL;
|
||||
unsigned char sha1[20];
|
||||
const char *prefix = setup_git_directory();
|
||||
const char **pathspec = NULL;
|
||||
void *tree;
|
||||
unsigned long size;
|
||||
@ -179,15 +180,12 @@ int main(int argc, const char **argv)
|
||||
int allow_options = 1;
|
||||
int i;
|
||||
|
||||
read_cache();
|
||||
for (i = 1; i < argc; i++) {
|
||||
const char *arg = argv[i];
|
||||
|
||||
if (!allow_options || *arg != '-') {
|
||||
if (tree_name) {
|
||||
pathspec = argv + i;
|
||||
if (tree_name)
|
||||
break;
|
||||
}
|
||||
tree_name = arg;
|
||||
continue;
|
||||
}
|
||||
@ -265,12 +263,16 @@ int main(int argc, const char **argv)
|
||||
usage(diff_cache_usage);
|
||||
}
|
||||
|
||||
pathspec = get_pathspec(prefix, argv + i);
|
||||
|
||||
if (find_copies_harder && detect_rename != DIFF_DETECT_COPY)
|
||||
usage(diff_cache_usage);
|
||||
|
||||
if (!tree_name || get_sha1(tree_name, sha1))
|
||||
usage(diff_cache_usage);
|
||||
|
||||
read_cache();
|
||||
|
||||
/* The rest is for paths restriction. */
|
||||
diff_setup(diff_setup_opt);
|
||||
|
||||
|
Reference in New Issue
Block a user