All of lore.kernel.org
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: "René Scharfe" <l.s.r@web.de>
Cc: git@vger.kernel.org,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Emily Shaffer <emilyshaffer@google.com>
Subject: Re: [PATCH v3 1/2] abspath: add a function to resolve paths with missing components
Date: Sat, 28 Nov 2020 18:41:22 +0000	[thread overview]
Message-ID: <X8KZ0gd85g7fhqm5@camp.crustytoothpaste.net> (raw)
In-Reply-To: <374553d7-6027-0152-bf56-9395e8268fa9@web.de>

[-- Attachment #1: Type: text/plain, Size: 2877 bytes --]

On 2020-11-28 at 10:08:09, René Scharfe wrote:
> Am 28.11.20 um 00:19 schrieb brian m. carlson:
> > We'd like to canonicalize paths such that we can preserve any number of
> > trailing components that may be missing.  Let's add a function to do
> > that, taking the number of components to canonicalize, and make
> > strbuf_realpath a wrapper around it that allows just one component.
> >
> > Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> > ---
> >  abspath.c | 33 ++++++++++++++++++++++++++++++++-
> >  cache.h   |  2 ++
> >  2 files changed, 34 insertions(+), 1 deletion(-)
> >
> > diff --git a/abspath.c b/abspath.c
> > index 6f15a418bb..1d8f3d007c 100644
> > --- a/abspath.c
> > +++ b/abspath.c
> > @@ -20,6 +20,7 @@ static void strip_last_component(struct strbuf *path)
> >  	/* Find start of the last component */
> >  	while (offset < len && !is_dir_sep(path->buf[len - 1]))
> >  		len--;
> > +
> >  	/* Skip sequences of multiple path-separators */
> >  	while (offset < len && is_dir_sep(path->buf[len - 1]))
> >  		len--;
> 
> Stray change?

Ah, yes.  I pulled out the old code from v2, but left the whitespace.
Will fix.

> Nitpicking: Do we need both empty lines?

No, we don't.

> >  /*
> >   * Return the real path (i.e., absolute path, with symlinks resolved
> >   * and extra slashes removed) equivalent to the specified path.  (If
> > @@ -80,6 +97,16 @@ static void get_root_part(struct strbuf *resolved, struct strbuf *remaining)
> >   */
> >  char *strbuf_realpath(struct strbuf *resolved, const char *path,
> >  		      int die_on_error)
> > +{
> > +	return strbuf_realpath_missing(resolved, path, 1, die_on_error);
> > +}
> > +
> > +/*
> > + * Just like strbuf_realpath, but allows specifying how many missing components
> > + * are permitted.  -1 may be specified to allow an unlimited number.
> > + */
> > +char *strbuf_realpath_missing(struct strbuf *resolved, const char *path,
> > +			      int missing_components, int die_on_error)
> >  {
> >  	struct strbuf remaining = STRBUF_INIT;
> >  	struct strbuf next = STRBUF_INIT;
> > @@ -128,8 +155,12 @@ char *strbuf_realpath(struct strbuf *resolved, const char *path,
> >  		strbuf_addbuf(resolved, &next);
> >
> >  		if (lstat(resolved->buf, &st)) {
> > +			int trailing_components = count_dir_separators(remaining.buf) +
> > +						  (remaining.len != 0);
> 
> Hmm, so you actually want to count path components, not separators.
> Perhaps like this?
> 
> 	static size_t count_components(const char *p)
> 	{
> 		size_t n = 0;
> 		while (*p) {
> 			while (*p && !is_dir_sep(*p))
> 				p++;
> 			while (is_dir_sep(*p))
> 				p++;
> 			n++;
> 		}
> 		return n;
> 	}

Yeah, I think that's nicer, and simpler, too.  Will reroll with that
fix.
-- 
brian m. carlson (he/him or they/them)
Houston, Texas, US

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

  reply	other threads:[~2020-11-28 22:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-27 23:19 [PATCH v3 0/2] rev-parse options for absolute or relative paths brian m. carlson
2020-11-27 23:19 ` [PATCH v3 1/2] abspath: add a function to resolve paths with missing components brian m. carlson
2020-11-28 10:08   ` René Scharfe
2020-11-28 18:41     ` brian m. carlson [this message]
2020-12-02 13:09   ` Johannes Schindelin
2020-12-02 23:54     ` brian m. carlson
2020-11-27 23:19 ` [PATCH v3 2/2] rev-parse: add option for absolute or relative path formatting brian m. carlson
2020-12-02 13:12 ` [PATCH v3 0/2] rev-parse options for absolute or relative paths Johannes Schindelin

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=X8KZ0gd85g7fhqm5@camp.crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=emilyshaffer@google.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    /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.