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:21 UTC
Message-ID
<200702201021.58754.andyparkins@gmail.com>
In-Reply-To
<7vfy91ximy.fsf@assigned-by-dhcp.cox.net>
On Tuesday 2007 February 20 09:50, Junio C Hamano wrote:
> I'd send the prefixcmp() patches first, as yours would touch the
> same lines.
Okay.

Your prefixcmp() point about them being used so regularly made me wonder if the following would improve readability:

static inline ref_is_head(const char *a)
{
    return (prefixcmp(a, PATH_REFS_HEADS) == 0);
}
static inline ref_is_tag(const char *a)
{
    return (prefixcmp(a, PATH_REFS_TAGS) == 0);
}
static inline ref_is_remote(const char *a)
{
    return (prefixcmp(a, PATH_REFS_REMOTES) == 0);
}
which would in turn convert:
   if (!strncmp(head, "refs/heads/", 11))
       head += 11;
into
   if (ref_is_head(head))
       head += STRLEN_PATH_REFS_HEADS;
which expresses the intent of the code far more clearly.
Andy
-- 
Dr Andy Parkins, M Eng (hons), MIEE
andyparkins@gmail.com
Previous: Junio C HamanoNext: Junio C Hamano
Message 13 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.