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

Re: [GSoC][PATCH 1/3] path.c: Add xdg_cache_home to get paths under XDG_CACHE_HOME

From
Jeff King <peff@peff.net>
Date
Mar 13, 2017, 18:48 UTC
Message-ID
<20170313184837.wnluuyflbx63cwlm@sigill.intra.peff.net>
In-Reply-To
<20170313172232.96678-2-lehmacdj@gmail.com>
On Mon, Mar 13, 2017 at 01:22:30PM -0400, Devin Lehmacher wrote:
> Subject: Re: [GSoC][PATCH 1/3] path.c: Add xdg_cache_home to get paths under XDG_CACHE_HOME

It's nice to keep subject lines succinct, as people will skim through them in "shortlog" or "log --oneline" output for years to come. Of course, you should not make them _too_ succinct, but I think there is a lot of extra detail here.

Probably:
  path.c: add xdg_cache_home

would suffice in this case (not also that we usually do not start with a capital letter).

> This is necessary to make it posible to use XDG_CACHE_HOME for caches in
> the XDG standard. I modeled this after the very similar xdg_config_home
> function for obtaining paths to functions under XDG_CONFIG_HOME

I think this covers what it needs to, which is good. I'd usually try to avoid starting the message with "this", as it it can be a bit vague (and assumes that the body is shown next to the subject, which is not always the case).

I'd have probably written it like:
  We already have xdg_config_home() to help us format paths in
  XDG_CONFIG_HOME. Let's provide a similar xdg_cache_home() to do the
  same thing for XDG_CACHE_HOME.

or something. I admit this is bikeshedding, but since you're new I feel like I get to spout off about commit message style. :)

Show 14 quoted lines
> +char *xdg_cache_home(const char *filename)
> +{
> +	const char *home, *cache_home;
> +
> +	assert(filename);
> +	cache_home = getenv("XDG_CACHE_HOME");
> +	if (cache_home && *cache_home)
> +		return mkpathdup("%s/git/%s", cache_home, filename);
> +
> +	home = getenv("HOME");
> +	if (home)
> +		return mkpathdup("%s/.cache/git/%s", home, filename);
> +	return NULL;
> +}

This looks fine, as it comes from xdg_config_home(). It does make me wonder if the two should be sharing a common implementation, with a signature like:

  char *xdg_generic_home(const char *env,
			 const char *fallback,
			 const char *filename);
and then the two functions do:
  return xdg_generic_home("XDG_CACHE_HOME", ".cache", filename);

For two the duplication is not so bad, but I wonder if there are other xdg paths we'd care about.

And one final note. I notice that we return NULL if the user has no HOME. But I'm not sure most callers are prepared to handle this. E.g., if you have no ident set and no HOME, then we will pass NULL to lstat(). On Linux at least that just gets you EFAULT, but I wouldn't be surprised if it's a segfault on other systems (probably at least Windows, where we have an lstat wrapper that calls strlen on the filename).

This is not at all a new thing with your patch, but it might be worth considering while we are thinking about expanding this interface. I'm not sure if the callers should be more careful, of it the function should promise to either die() or return a non-NULL value.

-Peff
Previous: Devin LehmacherNext: Devin Lehmacher
Message 3 of 54 in “Move ~/.git-credential-cache to ~/.cache/git”
  1. Devin LehmacherMar 13, 2017
  2. [GSoC][PATCH 1/3] path.c: Add xdg_cache_home to get paths under XDG_CACHE_HOMEDevin Lehmacher, Mar 13, 2017
  3. Jeff KingMar 13, 2017
  4. Devin LehmacherMar 13, 2017
  5. [GSoC][PATCH 3/3] Update documentation to reflect new socket locationDevin Lehmacher, Mar 13, 2017
  6. Junio C HamanoMar 13, 2017
  7. [GSoC][PATCH v2 2/2] credential-cache: use XDG_CACHE_HOME for socketDevin Lehmacher, Mar 13, 2017
  8. [GSoC][PATCH v2 1/2] path.c: add xdg_cache_homeDevin Lehmacher, Mar 13, 2017
  9. [GSoC][PATCH v2 2/2] credential-cache: use XDG_CACHE_HOME for socketDevin Lehmacher, Mar 13, 2017
  10. Junio C HamanoMar 13, 2017
  11. [GSoC][PATCH/RFC v3 0/3] Fix commit messages, check if socket is socketDevin Lehmacher, Mar 14, 2017
  12. [GSoC][PATCH/RFC v3 3/3] credential-cache: only use user_socket if a socketDevin Lehmacher, Mar 14, 2017
  13. Devin LehmacherMar 14, 2017
  14. Brandon WilliamsMar 14, 2017
  15. Devin LehmacherMar 14, 2017
  16. Brandon WilliamsMar 14, 2017
  17. Junio C HamanoMar 14, 2017
  18. Junio C HamanoMar 14, 2017
  19. Devin LehmacherMar 14, 2017
  20. [GSoC][PATCH v4 0/4] Moving credential-cache socket to xdg pathDevin Lehmacher, Mar 16, 2017
  21. [GSoC][PATCH v4 1/4] path.c: add xdg_cache_homeDevin Lehmacher, Mar 16, 2017
  22. [GSoC][PATCH v4 4/4] credential-cache: add tests for XDG functionalityDevin Lehmacher, Mar 16, 2017
  23. Junio C HamanoMar 16, 2017
  24. Jeff KingMar 16, 2017
  25. [GSoC][PATCH v5 1/3] path.c: add xdg_cache_homeDevin Lehmacher, Mar 17, 2017
  26. [GSoC][PATCH v5 2/3] credential-cache: use XDG_CACHE_HOME for socketDevin Lehmacher, Mar 17, 2017
  27. Ramsay JonesMar 17, 2017
  28. Devin LehmacherMar 17, 2017
  29. [GSoC][PATCH v5 3/3] credential-cache: add tests for XDG functionalityDevin Lehmacher, Mar 17, 2017
  30. Junio C HamanoMar 17, 2017
  31. [GSoC][PATCH v6 1/3] path.c: add xdg_cache_homeDevin Lehmacher, Mar 17, 2017
  32. [GSoC][PATCH v6 2/3] credential-cache: use XDG_CACHE_HOME for socketDevin Lehmacher, Mar 17, 2017
  33. Jeff KingMar 17, 2017
  34. [GSoC][PATCH v6 3/3] credential-cache: add tests for XDG functionalityDevin Lehmacher, Mar 17, 2017
  35. Jeff KingMar 17, 2017
  36. Jeff KingMar 17, 2017
  37. [GSoC][PATCH v4 2/4] dir: add directory_existsDevin Lehmacher, Mar 16, 2017
  38. Junio C HamanoMar 16, 2017
  39. Junio C HamanoMar 16, 2017
  40. [GSoC][PATCH v4 3/4] credential-cache: use XDG_CACHE_HOME for socketDevin Lehmacher, Mar 16, 2017
  41. Junio C HamanoMar 16, 2017
  42. Jeff KingMar 16, 2017
  43. [GSoC][PATCH/RFC v3 2/3] credential-cache: use XDG_CACHE_HOME for socketDevin Lehmacher, Mar 14, 2017
  44. Junio C HamanoMar 14, 2017
  45. [GSoC][PATCH/RFC v3 1/3] path.c: add xdg_cache_homeDevin Lehmacher, Mar 14, 2017
  46. Junio C HamanoMar 13, 2017
  47. [GSoC][PATCH 2/3] credential-cache.c: Make git use XDG_CACHE_HOME for credentialsDevin Lehmacher, Mar 13, 2017
  48. Junio C HamanoMar 13, 2017
  49. Jeff KingMar 13, 2017
  50. Junio C HamanoMar 13, 2017
  51. Devin LehmacherMar 13, 2017
  52. Devin LehmacherMar 13, 2017
  53. Junio C HamanoMar 13, 2017
  54. Jeff KingMar 13, 2017

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.