From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH/RFC 3/3] diff.c: add --relative-names to be used with --name-only
Date: Sun, 26 Jun 2016 19:16:16 +0200 [thread overview]
Message-ID: <20160626171616.27948-4-pclouds@gmail.com> (raw)
In-Reply-To: <20160626171616.27948-1-pclouds@gmail.com>
The difference with --relative option is, this option does not filter
paths outside cwd. You can add two more chars " ." on your command
line for that.
This serves two purposes
- user friendlier to copy/paste. When full paths are shown, you can
still use ":/" magic to get around it, but unless you're a lefty
you need to move your right hand between the keyboard and mouse for
each path. Not very efficient.
- script friendly. Strictly speaking a very light form of scripting
from command line prompt when you just pipe paths to the next
command. Paths relative to cwd would be much easier to pip this
way.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
It would be great if --relative could be used for this (and it feels
weird that the option performs both actions at once, stripping _and_
filtering where filtering could easily be done with pathspec). But
it's too late to change --relative behavior now.
Documentation/diff-options.txt | 4 ++++
diff.c | 21 ++++++++++++++++++---
diff.h | 1 +
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index d9ae681..1554008 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -481,6 +481,10 @@ ifndef::git-format-patch[]
not in a subdirectory (e.g. in a bare repository), you
can name which subdirectory to make the output relative
to by giving a <path> as an argument.
+
+--relative-names::
+ When used with `--name-only`, paths are shown relative to
+ current working directory.
endif::git-format-patch[]
-a::
diff --git a/diff.c b/diff.c
index bd5d190..3a938ac 100644
--- a/diff.c
+++ b/diff.c
@@ -3335,6 +3335,13 @@ void diff_setup_done(struct diff_options *options)
if (DIFF_OPT_TST(options, FIND_COPIES_HARDER))
options->detect_rename = DIFF_DETECT_COPY;
+ /*
+ * --relative can change "prefix", which may cause unintended
+ * consequences for --relative-names
+ */
+ if (DIFF_OPT_TST(options, RELATIVE_NAME) && options->relative_names)
+ die(_("--relative and --relative-names are mutually exclusive"));
+
if (options->prefix)
options->prefix_length = strlen(options->prefix);
else
@@ -3792,7 +3799,8 @@ int diff_opt_parse(struct diff_options *options,
else if (skip_prefix(arg, "--relative=", &arg)) {
DIFF_OPT_SET(options, RELATIVE_NAME);
options->prefix = arg;
- }
+ } else if (!strcmp(arg, "--relative-names"))
+ options->relative_names = 1;
/* xdiff options */
else if (!strcmp(arg, "--minimal"))
@@ -4347,8 +4355,15 @@ static void flush_one_pair(struct diff_filepair *p, struct diff_options *opt)
const char *name_a, *name_b;
name_a = p->two->path;
name_b = NULL;
- strip_prefix(opt, &name_a, &name_b);
- write_name_quoted(name_a, opt->file, opt->line_termination);
+ if (opt->relative_names)
+ write_name_quoted_relative(name_a,
+ opt->prefix, opt->file,
+ opt->line_termination);
+ else {
+ strip_prefix(opt, &name_a, &name_b);
+ write_name_quoted(name_a, opt->file,
+ opt->line_termination);
+ }
}
}
diff --git a/diff.h b/diff.h
index 125447b..ad6423d 100644
--- a/diff.h
+++ b/diff.h
@@ -139,6 +139,7 @@ struct diff_options {
int dirstat_permille;
int setup;
int abbrev;
+ int relative_names;
/* white-space error highlighting */
#define WSEH_NEW 1
#define WSEH_CONTEXT 2
--
2.8.2.531.gd073806
next prev parent reply other threads:[~2016-06-26 17:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-26 17:16 [PATCH 0/3] diff: add --relative-names Nguyễn Thái Ngọc Duy
2016-06-26 17:16 ` [PATCH 1/3] diff.c: refactor strip_prefix() Nguyễn Thái Ngọc Duy
2016-06-26 17:16 ` [PATCH 2/3] diff.c: separate "prefix" from RELATIVE_NAME (aka --relative) Nguyễn Thái Ngọc Duy
2016-06-26 17:16 ` Nguyễn Thái Ngọc Duy [this message]
2016-06-26 23:05 ` [PATCH/RFC 3/3] diff.c: add --relative-names to be used with --name-only Eric Sunshine
2016-06-27 19:24 ` Jeff King
2016-06-27 19:33 ` Duy Nguyen
2016-06-27 19:35 ` Jeff King
2016-06-27 19:39 ` Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160626171616.27948-4-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).