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

Re: [PATCH] Change "refs/" references to symbolic constants

From
APAndy Parkins <andyparkins@gmail.com>
Date
Feb 20, 2007, 10:57 UTC
Message-ID
<200702201057.21398.andyparkins@gmail.com>
In-Reply-To
<7vabz9w270.fsf@assigned-by-dhcp.cox.net>
On Tuesday 2007 February 20 10:30, Junio C Hamano wrote:
Show 6 quoted lines
> If we _were_ doing the inline function, I would actually prefer:
>
>         static inline ref_is_head(const char *ref)
>         {
> 		return !prefixcmp(ref, PATH_REFS_HEADS);
>         }
As you brought it up...

I've never really liked "!" on strcmp() lines (but I accept that that is the tradition in git) because it implies the the output of prefixcmp is boolean, but it's actually ternary. strcmp() (I think), should be thought of as outputting

enum {
 STRING1_LESS_THAN_STRING2,
 STRINGS_EQUAL,
 STRING1_GREATER_THAN_STRING2
}

Given that, it makes me uncomfortable to use !strcmp(). Of course in the case of strcmp(), that form is so well known that it makes very little difference to the reader.

I have similar feelings about
 if( !something )
being incorrect when you meant
 if( something == NULL )

While they are identical in what they generate, they send a different message to someone reading the code.

Regardless, I'm not so stubborn as to refuse to go with the flow...
Show 9 quoted lines
> But at least to me,
>
> 	if (!prefixcmp(head, PATH_REFS_HEADS))
> 		head += strlen(PATH_REFS_HEADS);
>
> is easier to follow than:
>
>         if (ref_is_head(head))
>                 head += STRLEN_PATH_REFS_HEADS;
Fine.  I don't really mind - and it's less work on my patch :-)

My argument in favour of the ref_is_head() method is that the prefixcmp() method requires knowledge from the caller about how you tell whether a given ref is a head - the second pushes that information further down the call tree, abstracting it out just a little more.

As I say though - it's not a problem for me.
Andy
-- 
Dr Andy Parkins, M Eng (hons), MIEE
andyparkins@gmail.com
Previous: Junio C HamanoNext: Johannes Schindelin
Message 15 of 30 in “Change "refs/" references to symbolic constants”
  1. Change "refs/" references to symbolic constantsAndy Parkins, Feb 19, 2007
  2. Bill LearFeb 19, 2007
  3. Replace literal STRLEN_ #defines in refs.h with compiler evaluated expressionsAndy Parkins, Feb 19, 2007
  4. Krzysztof HalasaFeb 19, 2007
  5. Shawn O. PearceFeb 19, 2007
  6. Junio C HamanoFeb 19, 2007
  7. Shawn O. PearceFeb 19, 2007
  8. Johannes SchindelinFeb 19, 2007
  9. Andy ParkinsFeb 20, 2007
  10. Junio C HamanoFeb 20, 2007
  11. Andy ParkinsFeb 20, 2007
  12. Junio C HamanoFeb 20, 2007
  13. Andy ParkinsFeb 20, 2007
  14. Junio C HamanoFeb 20, 2007
  15. Andy ParkinsFeb 20, 2007
  16. Johannes SchindelinFeb 20, 2007
  17. Simon 'corecode' SchubertFeb 20, 2007
  18. Johannes SchindelinFeb 20, 2007
  19. Andy ParkinsFeb 20, 2007
  20. Nicolas PitreFeb 20, 2007
  21. 1/4 Add prefixcmp()Junio C Hamano, Feb 20, 2007
  22. David KågedalFeb 20, 2007
  23. Junio C HamanoFeb 20, 2007
  24. 2/4 Mechanical conversion to use prefixcmp()Junio C Hamano, Feb 20, 2007
  25. Junio C HamanoFeb 20, 2007
  26. Johannes SchindelinFeb 20, 2007
  27. Junio C HamanoFeb 21, 2007
  28. Johannes SchindelinFeb 21, 2007
  29. 3/4 prefixcmp(): fix-up mechanical conversion.Junio C Hamano, Feb 20, 2007
  30. 4/4 prefixcmp(): fix-up leftover strncmp().Junio C Hamano, Feb 20, 2007

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.