From c0cb4a067972700f0682fbab13768bcc7dc7a3c3 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 13 Feb 2008 00:34:39 -0800 Subject: [PATCH] diff --relative: help working in a bare repository This allows the --relative option to say which subdirectory to pretend to be in, so that in a bare repository, you can say: $ git log --relative=drivers/ v2.6.20..v2.6.22 -- drivers/scsi/ Signed-off-by: Junio C Hamano --- Documentation/diff-options.txt | 7 +++++-- diff.c | 4 ++++ revision.c | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index 286c30c01..8dc5b001c 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -170,10 +170,13 @@ endif::git-format-patch[] Swap two inputs; that is, show differences from index or on-disk file to tree contents. ---relative:: +--relative[=]:: When run from a subdirectory of the project, it can be told to exclude changes outside the directory and show - pathnames relative to it with this option. + pathnames relative to it with this option. When you are + not in a subdirectory (e.g. in a bare repository), you + can name which subdirectory to make the output relative + to by giving a as an argument. --text:: Treat all files as text. diff --git a/diff.c b/diff.c index db4bd557b..2b89b1600 100644 --- a/diff.c +++ b/diff.c @@ -2302,6 +2302,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) options->detect_rename = 0; else if (!strcmp(arg, "--relative")) DIFF_OPT_SET(options, RELATIVE_NAME); + else if (!prefixcmp(arg, "--relative=")) { + DIFF_OPT_SET(options, RELATIVE_NAME); + options->prefix = arg + 11; + } /* xdiff options */ else if (!strcmp(arg, "-w") || !strcmp(arg, "--ignore-all-space")) diff --git a/revision.c b/revision.c index 6d9188b6c..4d6f57b64 100644 --- a/revision.c +++ b/revision.c @@ -720,7 +720,7 @@ void init_revisions(struct rev_info *revs, const char *prefix) revs->commit_format = CMIT_FMT_DEFAULT; diff_setup(&revs->diffopt); - if (prefix) { + if (prefix && !revs->diffopt.prefix) { revs->diffopt.prefix = prefix; revs->diffopt.prefix_length = strlen(prefix); } -- 2.26.2