git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Trim ending whitespaces in exclude file if needed.

From
Vasyl' <vvavrychuk@gmail.com>
Date
Oct 17, 2010, 09:29 UTC
Message-ID
<AANLkTimrgGYXDtN_ukWuCpjGTibrMNLQvfpq8fe=VxS_@mail.gmail.com>
In-Reply-To
<20101017024133.GF26656@burratino>
Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 10 quoted lines
> (+cc: msysgit)
>
> Vasyl' wrote:
>
> > Hope this can save someone's time debugging git.
>
> It sounds like there's a story behind this one.  Could you tell it?
> That would help future readers of this code to easily determine
> why they shouldn't break it.
>

I modify either .git/info/exclude or .gitignore by copy-pasting `git status`. But unfortunetly this adds spacing to ends of lines and ignoring does not work...

Show 23 quoted lines
>
> > --- a/dir.c
> > +++ b/dir.c
> > @@ -171,7 +171,15 @@ void add_exclude(const char *string, const char
> *base,
> >               to_exclude = 0;
> >               string++;
> >       }
> > +
>
> Why?
>
> >       len = strlen(string);
> > +     if (len && isspace((unsigned char)string[len - 1])) {
>
> This cast is not needed (see git-compat-util.h).
>
> > +             struct strbuf trim_buf = STRBUF_INIT;
> > +             strbuf_add(&trim_buf, string, len);
> > +             strbuf_rtrim(&trim_buf);
>
> Missing free(string)?
>
I have misunderstood in the first iteration memory managment in the
add_exclude's function code
 struct exclude *x;
char *s;
x = xmalloc(sizeof(*x) + len);
s = (char *)(x+1);
memcpy(s, string, len - 1);
s[len - 1] = '\0';
string = s;
And fix of my patch needs more change and testing. I will do this later.
Show 8 quoted lines
>
> > +             string = strbuf_detach(&trim_buf, &len);
> > +     }
> > +
> >       if (len && string[len - 1] == '/') {
>
> Thanks for a clear and pleasant read.
>
Thanks for review.
> Jonathan
>
Previous: Jonathan NiederNext: Junio C Hamano
Message 3 of 4 in “Trim ending whitespaces in exclude file if needed.”
  1. Trim ending whitespaces in exclude file if needed.Vasyl', Oct 15, 2010
  2. Jonathan NiederOct 17, 2010
  3. Vasyl'Oct 17, 2010
  4. Junio C HamanoOct 18, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.