All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: "brian m. carlson" <sandals@crustytoothpaste.net>
Cc: "Git List" <git@vger.kernel.org>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"René Scharfe" <l.s.r@web.de>
Subject: Re: [PATCH v4 2/2] rev-parse: add option for absolute or relative path formatting
Date: Sun, 6 Dec 2020 19:30:13 -0500	[thread overview]
Message-ID: <CAPig+cS-2Vw84rejMFAiDeF8dd5gtBOmQZUMpOy2ufA8nU7W7g@mail.gmail.com> (raw)
In-Reply-To: <20201206225349.3392790-3-sandals@crustytoothpaste.net>

On Sun, Dec 6, 2020 at 5:58 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
> [...]
> To help out the scripter, let's provide an option which turns most of
> the paths printed by git rev-parse to be either relative to the current
> working directory or absolute and canonical.  Document which options are
> affected and which are not so that users are not confused.
> [...]
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
> @@ -212,6 +212,15 @@ Options for Files
> +--path-format=(absolute|relative)::
> +       Controls the behavior of certain other options following it on the command
> +       line. If specified as absolute, the paths printed by those options will be
> +       absolute and canonical. If specified as relative, the paths will be relative
> +       to the current working directory if that is possible.  The default is option
> +       specific.

I read the commit message and looked at the implementation so I know
that this option can be specified multiple times, but this
documentation only vaguely hints at it by saying "options following
it". We could do a better job of imparting that knowledge to the
reader by saying so explicitly, perhaps like this:

    Controls the behavior of some path-printing options. If
    'absolute', [...]. If 'relative', [...]. May be specified multiple
    times, each time affecting the path-printing options which
    follow it. The default path format is option-specific.

Since this option can be specified multiple times, should it also
recognize `default` to request the default behavior in addition to
`absolute` and `relative`? (Genuine question. Maybe real-world
use-cases wouldn't need it, but it would be easy to support and make
it functionally complete.)

> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
> @@ -583,6 +583,73 @@ static void handle_ref_opt(const char *pattern, const char *prefix)
> +static void print_path(const char *path, const char *prefix, enum format_type format, enum default_type def)
> +{
> +               struct strbuf buf = STRBUF_INIT, realbuf = STRBUF_INIT, prefixbuf = STRBUF_INIT;
> +               if (!is_absolute_path(path)) {
> +                       strbuf_realpath_missing(&realbuf, path, 1, 1);
> +                       path = realbuf.buf;
> +               }
> +               if (!is_absolute_path(prefix)) {
> +                       strbuf_realpath_missing(&prefixbuf, prefix, 1, 1);
> +                       prefix = prefixbuf.buf;
> +               }
> +               puts(relative_path(path, prefix, &buf));
> +               strbuf_release(&buf);

Leaking `realbuf` and `prefixbuf` here.

  reply	other threads:[~2020-12-07  0:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-06 22:53 [PATCH v4 0/2] rev-parse options for absolute or relative paths brian m. carlson
2020-12-06 22:53 ` [PATCH v4 1/2] abspath: add a function to resolve paths with missing components brian m. carlson
2020-12-07  0:02   ` Eric Sunshine
2020-12-07  2:11     ` brian m. carlson
2020-12-07 17:19   ` René Scharfe
2020-12-08  2:51     ` brian m. carlson
2020-12-06 22:53 ` [PATCH v4 2/2] rev-parse: add option for absolute or relative path formatting brian m. carlson
2020-12-07  0:30   ` Eric Sunshine [this message]
2020-12-07  2:38     ` brian m. carlson

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=CAPig+cS-2Vw84rejMFAiDeF8dd5gtBOmQZUMpOy2ufA8nU7W7g@mail.gmail.com \
    --to=sunshine@sunshineco.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    --cc=sandals@crustytoothpaste.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.