From: David Aguilar <davvid@gmail.com>
To: Jeff King <peff@peff.net>
Cc: gitster@pobox.com, git@vger.kernel.org, markus.heidelberg@web.de,
jnareb@gmail.com, j.sixt@viscovery.net
Subject: Re: [PATCH v4 2/2] diff: generate pretty filenames in prep_temp_blob()
Date: Fri, 29 May 2009 18:22:05 -0700 [thread overview]
Message-ID: <20090530012204.GA26210@gmail.com> (raw)
In-Reply-To: <20090529195537.GA13961@coredump.intra.peff.net>
On Fri, May 29, 2009 at 03:55:37PM -0400, Jeff King wrote:
> On Thu, May 28, 2009 at 05:49:24PM -0700, David Aguilar wrote:
>
> > @@ -1964,8 +1964,24 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
> > {
> > int fd;
> > struct strbuf buf = STRBUF_INIT;
> > + struct strbuf template = STRBUF_INIT;
> > + char *basename = ((char*)path) + strlen(path) - 1;
>
> Why do you drop constness in this assignment?
That was a mistake.
> > + /* Windows lacks basename() */
> > + while(*basename && basename > path) {
> > + basename--;
> > + if (is_dir_sep(*basename)) {
> > + basename++;
> > + break;
> > + }
> > + }
>
> This is such an easily-factorable bit, maybe it makes sense to add as
> basename() in compat/?
I would feel a little better calling it
git_basename(const char *) and keeping it in path.c
(or another name if basename is no good)
The reason is from the manpage for basename:
"Both dirname() and basename() may modify the
contents of path, so it may be desirable to
pass a copy when calling one of these functions."
The above snippet is much simpler and does not have
that restriction since we can guarantee const-ness.
All this version cares about is being able to find the
last dir_sep and returning a pointer.
What do you think?
--
David
next prev parent reply other threads:[~2009-05-30 1:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-29 0:49 [PATCH v4 1/2] compat: add a mkstemps() compatibility function David Aguilar
2009-05-29 0:49 ` [PATCH v4 2/2] diff: generate pretty filenames in prep_temp_blob() David Aguilar
2009-05-29 19:55 ` Jeff King
2009-05-30 1:22 ` David Aguilar [this message]
2009-05-30 1:47 ` Jeff King
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=20090530012204.GA26210@gmail.com \
--to=davvid@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j.sixt@viscovery.net \
--cc=jnareb@gmail.com \
--cc=markus.heidelberg@web.de \
--cc=peff@peff.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.