On Sun, Apr 07, 2013 at 03:25:36PM +0200, Jason A. Donenfeld wrote:
> On Sun, Apr 7, 2013 at 11:30 AM, John Keeping <[email protected]> wrote:
> > +       if (prefixcmp(snapshot.buf, reponame) == 0) {
> > +               const char *new_start = snapshot.buf;
> > +               new_start += strlen(reponame);
> > +               while (new_start && (*new_start == '-' || *new_start == 
> > '_'))
> > +                       new_start++;
> > +               strbuf_splice(&snapshot, 0, new_start - snapshot.buf, "", 
> > 0);
> >         }
> 
> Something funky is happening here.

Care to be more specific?  I think this behaviour is the same as the
code it replaces - we're removing the leading reponame and any following
'-' or '_' characters from the start of snapshot:

-       if (prefixcmp(snapshot, reponame) == 0) {
-               snapshot += strlen(reponame);
-               while (snapshot && (*snapshot == '-' || *snapshot == '_'))
-                       snapshot++;
+       if (prefixcmp(snapshot.buf, reponame) == 0) {
+               const char *new_start = snapshot.buf;
+               new_start += strlen(reponame);
+               while (new_start && (*new_start == '-' || *new_start == '_'))
+                       new_start++;
+               strbuf_splice(&snapshot, 0, new_start - snapshot.buf, "", 0);
        }

The strbuf_splice ends up just shifting the start of snapshot left by
"new_start - snapshot.buf" bytes, which is precisely the same as
changing the pointer to point at new_start (except that we can continue
to perform strbuf operations).

Of course, the following code is completely bogus :-(

+       strbuf_reset(&snapshot);
+       strbuf_addf(&snapshot, "v%s", snapshot.buf);

I'll fix that.

_______________________________________________
cgit mailing list
[email protected]
http://hjemli.net/mailman/listinfo/cgit

Reply via email to