summaryrefslogtreecommitdiff
path: root/diff-cache.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@osdl.org>2005-08-17 01:06:34 (GMT)
committerJunio C Hamano <junkio@cox.net>2005-08-17 01:47:22 (GMT)
commitd288a70030eaa5c205a72b4548635e17f8e523c0 (patch)
treee446e859256bd90a9eefd1cb2406707ea5b9d555 /diff-cache.c
parent83db04ff878f40146952ee5d3d2d113568455f5b (diff)
downloadgit-d288a70030eaa5c205a72b4548635e17f8e523c0.zip
git-d288a70030eaa5c205a72b4548635e17f8e523c0.tar.gz
git-d288a70030eaa5c205a72b4548635e17f8e523c0.tar.bz2
[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>
Diffstat (limited to 'diff-cache.c')
-rw-r--r--diff-cache.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/diff-cache.c b/diff-cache.c
index 47a4e09..400a4cb 100644
--- a/diff-cache.c
+++ b/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);