From: John Keeping <john@keeping.me.uk>
To: Ramkumar Ramachandra <artagnon@gmail.com>
Cc: Git List <git@vger.kernel.org>,
Jonathan Nieder <jrnieder@gmail.com>,
Jens Lehmann <Jens.Lehmann@web.de>,
Heiko Voigt <hvoigt@hvoigt.net>,
Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v3 1/2] rev-parse: add --prefix option
Date: Fri, 19 Apr 2013 11:22:07 +0100 [thread overview]
Message-ID: <20130419102207.GF2278@serenity.lan> (raw)
In-Reply-To: <1366365217-17674-1-git-send-email-artagnon@gmail.com>
On Fri, Apr 19, 2013 at 03:23:37PM +0530, Ramkumar Ramachandra wrote:
> John Keeping wrote:
> > Changes since v2:
> > - Rewrite commit message
> > - Add a new test for 'prefix ignored with HEAD:top'
> > - Use '<<-\EOF' where appropriate in t1513
>
> Thanks for the re-roll.
>
> In the previous iteration, I wasn't sure this was the right approach
> because I thought it would be better to pass RUN_SETUP and let
> run_builtin_command() take care of the prefix-setting. Unfortunately,
> as 5410a02 (git-rev-parse --parseopt, 2007-11-06) indicates, we have
> to run setup_git_directory() in cmd_rev_parse() after parsing
> --parseopt, as 'git rev-parse --parseopt' can be run outside a git
> repository. You might want to include this note in your commit
> message for the benefit of other readers.
>
> Other than that, I just have one small suggestion: it's possible to
> avoid passing output_prefix around, and simplify show_file() a bit if
> we acknowledge that printing "--" is not the same as printing a file
> (although the condition is the same). Would you like to squash this
> in?
I'm not actually sure this is better. I'm more afraid of the condition
for outputting files changing in the future than of passing
output_prefix around, so I'd much rather keep that condition in one
place.
If you really feel strongly about it, I'd prefer to extract the if
condition to a function and use that directly when deciding whether to
print "--".
[Also, you introduce a potential segfault via passing a NULL prefix to
strlen.]
> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
> -- 8< --
> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
> index de894c7..7e69b3f 100644
> --- a/builtin/rev-parse.c
> +++ b/builtin/rev-parse.c
> @@ -29,6 +29,7 @@ static int abbrev;
> static int abbrev_ref;
> static int abbrev_ref_strict;
> static int output_sq;
> +static int output_prefix;
>
> /*
> * Some arguments are relevant "revision" arguments,
> @@ -212,15 +213,13 @@ static void show_datestring(const char *flag, const char *datestr)
> show(buffer);
> }
>
> -static int show_file(const char *arg, int output_prefix)
> +static int show_file(const char *arg)
> {
> show_default();
> if ((filter & (DO_NONFLAGS|DO_NOREV)) == (DO_NONFLAGS|DO_NOREV)) {
> if (output_prefix) {
> const char *prefix = startup_info->prefix;
> - show(prefix_filename(prefix,
> - prefix ? strlen(prefix) : 0,
> - arg));
> + show(prefix_filename(prefix, strlen(prefix), arg));
> } else
> show(arg);
> return 1;
> @@ -228,6 +227,16 @@ static int show_file(const char *arg, int output_prefix)
> return 0;
> }
>
> +static int show_dashdash()
> +{
> + show_default();
> + if ((filter & (DO_NONFLAGS | DO_NOREV)) == (DO_NONFLAGS | DO_NOREV)) {
> + show("--");
> + return 1;
> + }
> + return 0;
> +}
> +
> static int try_difference(const char *arg)
> {
> char *dotdot;
> @@ -476,7 +485,6 @@ N_("git rev-parse --parseopt [options] -- [<args>...]\n"
> int cmd_rev_parse(int argc, const char **argv, const char *prefix)
> {
> int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0;
> - int output_prefix = 0;
> unsigned char sha1[20];
> const char *name = NULL;
>
> @@ -510,7 +518,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
> const char *arg = argv[i];
>
> if (as_is) {
> - if (show_file(arg, output_prefix) && as_is < 2)
> + if (show_file(arg) && as_is < 2)
> verify_filename(prefix, arg, 0);
> continue;
> }
> @@ -534,7 +542,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
> as_is = 2;
> /* Pass on the "--" if we show anything but files.. */
> if (filter & (DO_FLAGS | DO_REVS))
> - show_file(arg, 0);
> + show_dashdash();
> continue;
> }
> if (!strcmp(arg, "--default")) {
> @@ -543,7 +551,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
> continue;
> }
> if (!strcmp(arg, "--prefix")) {
> - prefix = argv[i+1];
> + prefix = argv[i + 1];
> startup_info->prefix = prefix;
> output_prefix = 1;
> i++;
> @@ -768,7 +776,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
> if (verify)
> die_no_single_rev(quiet);
> as_is = 1;
> - if (!show_file(arg, output_prefix))
> + if (!show_file(arg))
> continue;
> verify_filename(prefix, arg, 1);
> }
next prev parent reply other threads:[~2013-04-19 10:22 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-07 19:55 [RFC/PATCH 0/2] submodule: drop the top-level requirement John Keeping
2013-04-07 19:55 ` [PATCH 1/2] rev-parse: add --filename-prefix option John Keeping
2013-04-07 22:14 ` Jonathan Nieder
2013-04-08 8:31 ` John Keeping
2013-04-08 15:07 ` Junio C Hamano
2013-04-08 17:36 ` John Keeping
2013-04-08 18:11 ` Junio C Hamano
2013-04-07 19:55 ` [PATCH 2/2] submodule: drop the top-level requirement John Keeping
2013-04-07 20:15 ` [RFC/PATCH 0/2] " Jens Lehmann
2013-04-09 20:29 ` [PATCH v2 " John Keeping
2013-04-09 20:29 ` [PATCH v2 1/2] rev-parse: add --filename-prefix option John Keeping
2013-04-09 20:57 ` Junio C Hamano
2013-04-09 21:28 ` John Keeping
2013-04-09 21:33 ` Junio C Hamano
2013-04-18 14:28 ` Ramkumar Ramachandra
2013-04-18 14:42 ` John Keeping
2013-04-09 20:29 ` [PATCH v2 2/2] submodule: drop the top-level requirement John Keeping
2013-04-09 21:00 ` Junio C Hamano
2013-04-09 21:29 ` John Keeping
2013-04-18 14:46 ` Ramkumar Ramachandra
2013-04-18 14:56 ` John Keeping
2013-04-18 19:50 ` [PATCH v3 0/2] " John Keeping
2013-04-18 19:50 ` [PATCH v3 1/2] rev-parse: add --prefix option John Keeping
2013-04-19 9:53 ` Ramkumar Ramachandra
2013-04-19 10:22 ` John Keeping [this message]
2013-04-19 11:15 ` Ramkumar Ramachandra
2013-04-19 11:25 ` John Keeping
2013-04-19 11:29 ` Ramkumar Ramachandra
2013-04-18 19:50 ` [PATCH v3 2/2] submodule: drop the top-level requirement John Keeping
2013-04-18 22:40 ` Junio C Hamano
2013-04-19 7:46 ` John Keeping
2013-04-19 16:45 ` Junio C Hamano
2013-04-19 19:23 ` Johannes Sixt
2013-04-19 21:03 ` Junio C Hamano
2013-04-24 8:15 ` [PATCH] submodule: fix quoting in relative_path() John Keeping
2013-04-24 16:21 ` Junio C Hamano
2013-04-24 16:28 ` John Keeping
2013-04-24 19:12 ` Johannes Sixt
2013-04-18 23:54 ` [PATCH v3 2/2] submodule: drop the top-level requirement Eric Sunshine
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=20130419102207.GF2278@serenity.lan \
--to=john@keeping.me.uk \
--cc=Jens.Lehmann@web.de \
--cc=artagnon@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hvoigt@hvoigt.net \
--cc=jrnieder@gmail.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).