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

Re: [PATCH v2] correct verify_path for Windows

From
Dmitry Potapov <dpotapov@gmail.com>
Date
Oct 12, 2008, 13:50 UTC
Message-ID
<20081012135048.GC21650@dpotapov.dyndns.org>
In-Reply-To
<81b0412b0810111558vb69be00if4842fa91d777c3b@mail.gmail.com>
On Sun, Oct 12, 2008 at 12:58:52AM +0200, Alex Riesen wrote:
Show 14 quoted lines
> 2008/10/11 Dmitry Potapov <dpotapov@gmail.com>:
> >> > +   /* On Windows, file names are case-insensitive */
> >> > +   case 'G':
> >> > +           if ((rest[1]|0x20) != 'i')
> >> > +                   break;
> >> > +           if ((rest[2]|0x20) != 't')
> >> > +                   break;
> >>
> >> We have tolower().
> >
> > I am aware of that, but I am not sure what we gain by using it. It seems
> > it makes only code bigger and slow.
> 
> It does? Care to look into git-compat-util.h?
As a matter of fact, I did, and I see the following:
  #define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
  #define tolower(x) sane_case((unsigned char)(x), 0x20)
  static inline int sane_case(int x, int high)
  {
  	if (sane_istest(x, GIT_ALPHA))
  		x = (x & ~0x20) | high;
  	return x;
  }
So, it looks like an extra look up and an extra comparison here.
Show 9 quoted lines
> 
> > ... As to readability, I don't see much
> > improvement... Isn't obvious what this code does, especially with the
> > above comment?
> 
> You want to seriously argue that "a | 0x20" is as readable as "tolower(a)"?
> For the years to come? With a person who does not even know what ASCII is?
> Ok, I'm exaggerating. But the point is: it is not us who will be
> reading the code.
Obviously, for a person who don't know what ASCII is, tolower() will be
much easier to understand, but the question is what I can reasonable to
expect for a person reading this code later. A similar argument can be
made about adding extra parenthesis, i.e. instead of writing
  if (a == b || c == d)
you should always write
  if ((a == b) || (c == d))
because some people do not remember the priority of each operator.
(And I have seen such programmers who claim to have many experience of
writing in C, yet, they do not remember operator priority.)

For me, using tolower() does not make it more readable, but maybe I am too old-fashion assuming that people are supposed to know at least basic things about ASCII.

> BTW, is it such a critical path?

I am not sure whether it is critical or not. It is called for each name in path. So, if you have a long path, it may be called quite a few times per a single path. Also, some operation such 'git add' can call verify_path() more than once (IIRC, it was called thrice per each added file). But I have no numbers to tell whether it is noticeable or not.

> Can't the code be unified and do without #ifdef?

It will impose a extra restriction on what file names people can use, and I don't like extra restrictions for those who use sane file systems.

Dmitry
Previous: Alex RiesenNext: Alex Riesen
Message 15 of 19 in “Files with colons under Cygwin”
  1. Giovanni FunchalOct 2, 2008
  2. Dmitry PotapovOct 4, 2008
  3. Alex RiesenOct 5, 2008
  4. Alex RiesenOct 5, 2008
  5. Dmitry PotapovOct 5, 2008
  6. Giovanni FunchalOct 5, 2008
  7. Johannes SixtOct 6, 2008
  8. Dmitry PotapovOct 7, 2008
  9. Johannes SixtOct 7, 2008
  10. Joshua JuranOct 7, 2008
  11. correct verify_path for WindowsDmitry Potapov, Oct 7, 2008
  12. Johannes SixtOct 7, 2008
  13. Dmitry PotapovOct 11, 2008
  14. Alex RiesenOct 11, 2008
  15. Dmitry PotapovOct 12, 2008
  16. Alex RiesenOct 12, 2008
  17. Johannes SixtOct 13, 2008
  18. Alex RiesenOct 13, 2008
  19. Alex RiesenOct 7, 2008

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.