git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Git List <git@vger.kernel.org>, "Kyle J. McKay" <mackyle@gmail.com>
Subject: Re: [PATCH 6/9] http: update base URLs when we see redirects
Date: Sun, 29 Sep 2013 15:32:45 -0400	[thread overview]
Message-ID: <20130929193245.GB17644@sigill.intra.peff.net> (raw)
In-Reply-To: <CAPig+cQVQ6iY8onvb--88W0XHofC815NZHTb=L744hANtT8mVQ@mail.gmail.com>

On Sun, Sep 29, 2013 at 03:26:45PM -0400, Eric Sunshine wrote:

> On Sat, Sep 28, 2013 at 4:34 AM, Jeff King <peff@peff.net> wrote:
> > diff --git a/http.c b/http.c
> > index 65a0048..8775b5c 100644
> > --- a/http.c
> > +++ b/http.c
> > @@ -921,11 +921,71 @@ static int http_request_reauth(const char *url,
> > +static int update_url_from_redirect(struct strbuf *base,
> > +                                   const char *asked,
> > +                                   const struct strbuf *got)
> > +{
> > +       const char *tail;
> > +       size_t tail_len;
> > +
> > +       if (!strcmp(asked, got->buf))
> > +               return 0;
> > +
> > +       if (strncmp(asked, base->buf, base->len))
> > +               die("BUG: update_url_from_redirect: %s is not a superset of %s",
> > +                   asked, base->buf);
> 
> Is there something non-obvious going on here? die(...,base->buf) takes
> advantage of the terminating NUL promised by strbuf, but then
> strncmp(...,base->buf,base->len) is used rather than the simpler
> strcmp(...,base->buf).

Yes, we are not checking for equality, but rather making sure that
"asked" begins with "base->buf". It might be more clearly written as:

  if (prefixcmp(asked, base->buf))

I was trying to take advantage of the fact that we know base->len
already, but this it not a particularly performance-critical code path.
We can afford the extra strlen that prefixcmp will do.

-Peff

  reply	other threads:[~2013-09-29 19:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-28  8:29 [PATCH 0/9] following http redirects Jeff King
2013-09-28  8:31 ` [PATCH 1/9] http_get_file: style fixes Jeff King
2013-09-28  8:31 ` [PATCH 2/9] http_request: factor out curlinfo_strbuf Jeff King
2013-09-28  8:31 ` [PATCH 3/9] http: refactor options to http_get_* Jeff King
2013-09-28  8:31 ` [PATCH 4/9] http: hoist credential request out of handle_curl_result Jeff King
2013-09-28  8:32 ` [PATCH 5/9] http: provide effective url to callers Jeff King
2013-09-28  8:34 ` [PATCH 6/9] http: update base URLs when we see redirects Jeff King
2013-09-29 18:54   ` brian m. carlson
2013-09-29 19:26   ` Eric Sunshine
2013-09-29 19:32     ` Jeff King [this message]
2013-09-29 19:50       ` Eric Sunshine
2013-10-18 18:25   ` Junio C Hamano
2013-10-18 18:42     ` Jeff King
2013-10-18 19:20       ` Junio C Hamano
2013-09-28  8:35 ` [PATCH 7/9] remote-curl: make refs_url a strbuf Jeff King
2013-09-28  8:35 ` [PATCH 8/9] remote-curl: store url as " Jeff King
2013-09-28  8:35 ` [PATCH 9/9] remote-curl: rewrite base url from info/refs redirects 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=20130929193245.GB17644@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=mackyle@gmail.com \
    --cc=sunshine@sunshineco.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).