{"thread":{"id":"45367","subject":"[GSoC][PATCH 0/3] Move ~/.git-credential-cache to ~/.cache/git","startedAt":"2017-03-13T17:22:56Z","lastAt":"2017-03-17T19:32:28Z","messageCount":54,"participants":["Devin Lehmacher","Junio C Hamano","Jeff King","Brandon Williams","Ramsay Jones"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"313901","messageId":"20170313172232.96678-1-lehmacdj@gmail.com","threadId":"45367","inReplyTo":null,"subject":"[GSoC][PATCH 0/3] Move ~/.git-credential-cache to ~/.cache/git","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-13T17:22:29Z","receivedAt":"2017-03-13T17:22:56Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"Patches for my Microproject. I took into consideration the feedback I\nrecieved on an earlier email thread and now look for a socket at the old\ndefault location before creating a new socket in $XDG_CACHE_HOME.\n\nDocumentation/git-credential-cache.txt |  3 ++-\ncache.h                                |  7 +++++++\ncredential-cache.c                     | 15 ++++++++++++++-\npath.c                                 | 15 +++++++++++++++\n4 files changed, 38 insertions(+), 2 deletions(-)\n\n"},{"id":"313902","messageId":"20170313172232.96678-2-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170313172232.96678-1-lehmacdj@gmail.com","subject":"[GSoC][PATCH 1/3] path.c: Add xdg_cache_home to get paths under XDG_CACHE_HOME","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-13T17:22:30Z","receivedAt":"2017-03-13T17:22:59Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"This is necessary to make it posible to use XDG_CACHE_HOME for caches in\nthe XDG standard. I modeled this after the very similar xdg_config_home\nfunction for obtaining paths to functions under XDG_CONFIG_HOME\n\nSigned-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n cache.h |  7 +++++++\n path.c  | 15 +++++++++++++++\n 2 files changed, 22 insertions(+)\n\ndiff --git a/cache.h b/cache.h\nindex 8c0e64420..378a636e1 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1169,6 +1169,13 @@ extern int is_ntfs_dotgit(const char *name);\n  */\n extern char *xdg_config_home(const char *filename);\n \n+/**\n+ * Return a newly allocated string with the evaluation of\n+ * \"$XDG_CACHE_HOME/git/$filename\" if $XDG_CONFIG_HOME is non-empty, otherwise\n+ * \"$HOME/.config/git/$filename\". Return NULL upon error.\n+ */\n+extern char *xdg_cache_home(const char *filename);\n+\n /* object replacement */\n #define LOOKUP_REPLACE_OBJECT 1\n #define LOOKUP_UNKNOWN_OBJECT 2\ndiff --git a/path.c b/path.c\nindex efcedafba..22248436b 100644\n--- a/path.c\n+++ b/path.c\n@@ -1272,6 +1272,21 @@ char *xdg_config_home(const char *filename)\n \treturn NULL;\n }\n \n+char *xdg_cache_home(const char *filename)\n+{\n+\tconst char *home, *cache_home;\n+\n+\tassert(filename);\n+\tcache_home = getenv(\"XDG_CACHE_HOME\");\n+\tif (cache_home && *cache_home)\n+\t\treturn mkpathdup(\"%s/git/%s\", cache_home, filename);\n+\n+\thome = getenv(\"HOME\");\n+\tif (home)\n+\t\treturn mkpathdup(\"%s/.cache/git/%s\", home, filename);\n+\treturn NULL;\n+}\n+\n GIT_PATH_FUNC(git_path_cherry_pick_head, \"CHERRY_PICK_HEAD\")\n GIT_PATH_FUNC(git_path_revert_head, \"REVERT_HEAD\")\n GIT_PATH_FUNC(git_path_squash_msg, \"SQUASH_MSG\")\n-- \n2.11.0\n\n"},{"id":"313903","messageId":"20170313172232.96678-4-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170313172232.96678-1-lehmacdj@gmail.com","subject":"[GSoC][PATCH 3/3] Update documentation to reflect new socket location","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-13T17:22:32Z","receivedAt":"2017-03-13T17:23:01Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"Signed-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n Documentation/git-credential-cache.txt | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-credential-cache.txt b/Documentation/git-credential-cache.txt\nindex 96208f822..4b9db3856 100644\n--- a/Documentation/git-credential-cache.txt\n+++ b/Documentation/git-credential-cache.txt\n@@ -34,7 +34,8 @@ OPTIONS\n \n \tUse `<path>` to contact a running cache daemon (or start a new\n \tcache daemon if one is not started). Defaults to\n-\t`~/.git-credential-cache/socket`. If your home directory is on a\n+\t`~/.git-credential-cache/socket` if it exists and otherwise\n+    `$XDG_CACHE_HOME/git/credential/socket`. If your home directory is on a\n \tnetwork-mounted filesystem, you may need to change this to a\n \tlocal filesystem. You must specify an absolute path.\n \n-- \n2.11.0\n\n"},{"id":"313904","messageId":"20170313172232.96678-3-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170313172232.96678-1-lehmacdj@gmail.com","subject":"[GSoC][PATCH 2/3] credential-cache.c: Make git use XDG_CACHE_HOME for credentials","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-13T17:22:31Z","receivedAt":"2017-03-13T17:23:05Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"git-credential-cache will now use the socket\n$XDG_CACHE_HOME/git/credential/socket if there is not already a socket\nat ~/.git-credential-cache/socket. This ensures that if another process\nalready created a socket at the old location it will be used over the\nnew one if it exists.\n\nSigned-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n credential-cache.c | 15 ++++++++++++++-\n 1 file changed, 14 insertions(+), 1 deletion(-)\n\ndiff --git a/credential-cache.c b/credential-cache.c\nindex cc8a6ee19..75c917de7 100644\n--- a/credential-cache.c\n+++ b/credential-cache.c\n@@ -83,6 +83,19 @@ static void do_cache(const char *socket, const char *action, int timeout,\n \tstrbuf_release(&buf);\n }\n \n+static char* get_socket_path(void) {\n+\tchar *home_socket;\n+\n+\thome_socket = expand_user_path(\"~/.git_credential_cache/socket\");\n+\tif (home_socket)\n+\t\tif (file_exists(home_socket))\n+\t\t\treturn home_socket;\n+\t\telse\n+\t\t\tfree(home_socket);\n+\n+\treturn xdg_cache_home(\"credential/socket\");\n+}\n+\n int cmd_main(int argc, const char **argv)\n {\n \tchar *socket_path = NULL;\n@@ -106,7 +119,7 @@ int cmd_main(int argc, const char **argv)\n \top = argv[0];\n \n \tif (!socket_path)\n-\t\tsocket_path = expand_user_path(\"~/.git-credential-cache/socket\");\n+\t\tsocket_path = get_socket_path();\n \tif (!socket_path)\n \t\tdie(\"unable to find a suitable socket path; use --socket\");\n \n-- \n2.11.0\n\n"},{"id":"313912","messageId":"xmqqy3w9rr33.fsf@gitster.mtv.corp.google.com","threadId":"45367","inReplyTo":"20170313172232.96678-4-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH 3/3] Update documentation to reflect new socket location","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-13T18:04:16Z","receivedAt":"2017-03-13T18:04:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Devin Lehmacher <lehmacdj@gmail.com> writes:\n\n> Subject: Re: [GSoC][PATCH 3/3] Update documentation to reflect new socket location\n\nRead the above single line and nothing else, while pretending you do\nnot know what this patch is about at all.  That is what readers of\n\"git shortlog\" will see.\n\nIt may be obvious for you, but can you tell whose socket the series\nhas updated in 6 months after forgetting what you worked on?  The\ntitle does not give any hint that this is about the credential cache\ndaemon.\n\n> Signed-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n> ---\n>  Documentation/git-credential-cache.txt | 3 ++-\n>  1 file changed, 2 insertions(+), 1 deletion(-)\n>\n> diff --git a/Documentation/git-credential-cache.txt b/Documentation/git-credential-cache.txt\n> index 96208f822..4b9db3856 100644\n> --- a/Documentation/git-credential-cache.txt\n> +++ b/Documentation/git-credential-cache.txt\n> @@ -34,7 +34,8 @@ OPTIONS\n>  \n>  \tUse `<path>` to contact a running cache daemon (or start a new\n>  \tcache daemon if one is not started). Defaults to\n> -\t`~/.git-credential-cache/socket`. If your home directory is on a\n> +\t`~/.git-credential-cache/socket` if it exists and otherwise\n> +    `$XDG_CACHE_HOME/git/credential/socket`. If your home directory is on a\n>  \tnetwork-mounted filesystem, you may need to change this to a\n>  \tlocal filesystem. You must specify an absolute path.\n"},{"id":"313913","messageId":"xmqqtw6xrquw.fsf@gitster.mtv.corp.google.com","threadId":"45367","inReplyTo":"20170313172232.96678-3-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH 2/3] credential-cache.c: Make git use XDG_CACHE_HOME for credentials","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-13T18:09:11Z","receivedAt":"2017-03-13T18:10:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Devin Lehmacher <lehmacdj@gmail.com> writes:\n\n> +static char* get_socket_path(void) {\n> +\tchar *home_socket;\n> +\n> +\thome_socket = expand_user_path(\"~/.git_credential_cache/socket\");\n\nThe typo on this line guarantees that nobody will retain the current\nlocation and will be migrated forcibly to the new xdg place ;-)\n\n> +\tif (home_socket)\n> +\t\tif (file_exists(home_socket))\n> +\t\t\treturn home_socket;\n> +\t\telse\n> +\t\t\tfree(home_socket);\n> +\n> +\treturn xdg_cache_home(\"credential/socket\");\n> +}\n\nI somehow feel that the order of precedence should be the other way\naround, though.  \n\nIf somebody really wants to use the xdg location and has a socket\nalready there, using that existing socket would be the right thing\nto do.  However, when neither ~/.git-credential-cache/socket nor\n~/.cache/git/socket exists, why should we prefer the latter over the\nformer?\n\n>  int cmd_main(int argc, const char **argv)\n>  {\n>  \tchar *socket_path = NULL;\n> @@ -106,7 +119,7 @@ int cmd_main(int argc, const char **argv)\n>  \top = argv[0];\n>  \n>  \tif (!socket_path)\n> -\t\tsocket_path = expand_user_path(\"~/.git-credential-cache/socket\");\n> +\t\tsocket_path = get_socket_path();\n>  \tif (!socket_path)\n>  \t\tdie(\"unable to find a suitable socket path; use --socket\");\n"},{"id":"313914","messageId":"xmqqpohlrqrm.fsf@gitster.mtv.corp.google.com","threadId":"45367","inReplyTo":"20170313172232.96678-3-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH 2/3] credential-cache.c: Make git use XDG_CACHE_HOME for credentials","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-13T18:11:09Z","receivedAt":"2017-03-13T18:11:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Devin Lehmacher <lehmacdj@gmail.com> writes:\n\n> +static char* get_socket_path(void) {\n\nBy the way, in our codebase (which is C not C++), the asterisk does\nnot stick to the type, i.e. the above should be:\n\n\tstatic char *get_socket_path(void)\n\t{\n\n"},{"id":"313923","messageId":"20170313184837.wnluuyflbx63cwlm@sigill.intra.peff.net","threadId":"45367","inReplyTo":"20170313172232.96678-2-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH 1/3] path.c: Add xdg_cache_home to get paths under XDG_CACHE_HOME","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-03-13T18:48:37Z","receivedAt":"2017-03-13T18:48:46Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Mar 13, 2017 at 01:22:30PM -0400, Devin Lehmacher wrote:\n\n> Subject: Re: [GSoC][PATCH 1/3] path.c: Add xdg_cache_home to get paths under XDG_CACHE_HOME\n\nIt's nice to keep subject lines succinct, as people will skim through\nthem in \"shortlog\" or \"log --oneline\" output for years to come. Of\ncourse, you should not make them _too_ succinct, but I think there is a\nlot of extra detail here.\n\nProbably:\n\n  path.c: add xdg_cache_home\n\nwould suffice in this case (not also that we usually do not start\nwith a capital letter).\n\n> This is necessary to make it posible to use XDG_CACHE_HOME for caches in\n> the XDG standard. I modeled this after the very similar xdg_config_home\n> function for obtaining paths to functions under XDG_CONFIG_HOME\n\nI think this covers what it needs to, which is good. I'd usually try to\navoid starting the message with \"this\", as it it can be a bit vague (and\nassumes that the body is shown next to the subject, which is not always\nthe case).\n\nI'd have probably written it like:\n\n  We already have xdg_config_home() to help us format paths in\n  XDG_CONFIG_HOME. Let's provide a similar xdg_cache_home() to do the\n  same thing for XDG_CACHE_HOME.\n\nor something. I admit this is bikeshedding, but since you're new I feel\nlike I get to spout off about commit message style. :)\n\n> +char *xdg_cache_home(const char *filename)\n> +{\n> +\tconst char *home, *cache_home;\n> +\n> +\tassert(filename);\n> +\tcache_home = getenv(\"XDG_CACHE_HOME\");\n> +\tif (cache_home && *cache_home)\n> +\t\treturn mkpathdup(\"%s/git/%s\", cache_home, filename);\n> +\n> +\thome = getenv(\"HOME\");\n> +\tif (home)\n> +\t\treturn mkpathdup(\"%s/.cache/git/%s\", home, filename);\n> +\treturn NULL;\n> +}\n\nThis looks fine, as it comes from xdg_config_home(). It does make me\nwonder if the two should be sharing a common implementation, with a\nsignature like:\n\n  char *xdg_generic_home(const char *env,\n\t\t\t const char *fallback,\n\t\t\t const char *filename);\n\nand then the two functions do:\n\n  return xdg_generic_home(\"XDG_CACHE_HOME\", \".cache\", filename);\n\nFor two the duplication is not so bad, but I wonder if there are other\nxdg paths we'd care about.\n\nAnd one final note. I notice that we return NULL if the user has no\nHOME. But I'm not sure most callers are prepared to handle this. E.g.,\nif you have no ident set and no HOME, then we will pass NULL to lstat().\nOn Linux at least that just gets you EFAULT, but I wouldn't be surprised\nif it's a segfault on other systems (probably at least Windows, where we\nhave an lstat wrapper that calls strlen on the filename).\n\nThis is not at all a new thing with your patch, but it might be worth\nconsidering while we are thinking about expanding this interface. I'm\nnot sure if the callers should be more careful, of it the function\nshould promise to either die() or return a non-NULL value.\n\n-Peff\n"},{"id":"313925","messageId":"20170313190111.64vzo7v3b3aty2dt@sigill.intra.peff.net","threadId":"45367","inReplyTo":"20170313172232.96678-3-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH 2/3] credential-cache.c: Make git use XDG_CACHE_HOME for credentials","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-03-13T19:01:11Z","receivedAt":"2017-03-13T19:01:19Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Mar 13, 2017 at 01:22:31PM -0400, Devin Lehmacher wrote:\n\n> Subject: Re: [GSoC][PATCH 2/3] credential-cache.c: Make git use XDG_CACHE_HOME for credentials\n\nAnother subject nitpick. :)\n\nSaying \"Make git\" is just extraneous. All commits make git do something.\n\nLikewise \"for credentials\" doesn't say much. Perhaps \"for socket\" would\nbe more descriptive.\n\nI'm not sure we are entirely consistent here, but I'd probably say just\n\"credential-cache\" (not \"credential-cache.c\"). My rule of thumb is to\nmention the C file if it's an internal thing: a cleanup, a new\nfunction, etc. And use the command-name if it's something user-visible.\n\nSo all together:\n\n  Subject: credential-cache: use XDG_CACHE_HOME for socket\n\nis shorter and more descriptive (IMHO).\n\n> git-credential-cache will now use the socket\n> $XDG_CACHE_HOME/git/credential/socket if there is not already a socket\n> at ~/.git-credential-cache/socket. This ensures that if another process\n> already created a socket at the old location it will be used over the\n> new one if it exists.\n\nThis tells us what, but not much about \"why\". Probably the reason is\nsomething simple, like \"using standards is better than not\". But the\ncommit message should say that.\n\n> +static char* get_socket_path(void) {\n> +\tchar *home_socket;\n> +\n> +\thome_socket = expand_user_path(\"~/.git_credential_cache/socket\");\n> +\tif (home_socket)\n> +\t\tif (file_exists(home_socket))\n> +\t\t\treturn home_socket;\n> +\t\telse\n> +\t\t\tfree(home_socket);\n\nPlease use braces for nested ifs. I know that C resolves a dangling-else\nlike this as you've indented it (as opposed to attaching the else to the\nouter \"if\"), but it is unnecessarily confusing. Just one set of braces:\n\n  if (home_socket) {\n\tif (file_exists(home_socket);\n\t\treturn home_socket;\n\telse\n\t\tfree(home_socket);\n  }\n\nis sufficient.\n\n-Peff\n"},{"id":"313927","messageId":"20170313190349.wbg7nfmrxvvzc5zv@sigill.intra.peff.net","threadId":"45367","inReplyTo":"xmqqtw6xrquw.fsf@gitster.mtv.corp.google.com","subject":"Re: [GSoC][PATCH 2/3] credential-cache.c: Make git use XDG_CACHE_HOME for credentials","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-03-13T19:03:49Z","receivedAt":"2017-03-13T19:04:00Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Mar 13, 2017 at 11:09:11AM -0700, Junio C Hamano wrote:\n\n> > +\tif (home_socket)\n> > +\t\tif (file_exists(home_socket))\n> > +\t\t\treturn home_socket;\n> > +\t\telse\n> > +\t\t\tfree(home_socket);\n> > +\n> > +\treturn xdg_cache_home(\"credential/socket\");\n> > +}\n> \n> I somehow feel that the order of precedence should be the other way\n> around, though.  \n> \n> If somebody really wants to use the xdg location and has a socket\n> already there, using that existing socket would be the right thing\n> to do.  However, when neither ~/.git-credential-cache/socket nor\n> ~/.cache/git/socket exists, why should we prefer the latter over the\n> former?\n\nHow would they get a socket in the xdg location if we never create one?\n\nI think the point of this commit is that we should generally prefer the\nxdg locations to ones that were simply made up by Git.\n\nAs an aside, I also wondered if stale socket files might cause us to\nkeep picking the \"old\" location forever. But it looks like\ncredential-cache--daemon does use a tempfile handler to make sure it\ncleans up the socket afterwards (and we are checking for the actual\nsocket, not just the presence of the outer directory, which is good).\n\n-Peff\n"},{"id":"313928","messageId":"xmqqd1dlro8p.fsf@gitster.mtv.corp.google.com","threadId":"45367","inReplyTo":"20170313190349.wbg7nfmrxvvzc5zv@sigill.intra.peff.net","subject":"Re: [GSoC][PATCH 2/3] credential-cache.c: Make git use XDG_CACHE_HOME for credentials","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-13T19:05:42Z","receivedAt":"2017-03-13T19:05:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Mon, Mar 13, 2017 at 11:09:11AM -0700, Junio C Hamano wrote:\n>\n>> > +\tif (home_socket)\n>> > +\t\tif (file_exists(home_socket))\n>> > +\t\t\treturn home_socket;\n>> > +\t\telse\n>> > +\t\t\tfree(home_socket);\n>> > +\n>> > +\treturn xdg_cache_home(\"credential/socket\");\n>> > +}\n>> \n>> I somehow feel that the order of precedence should be the other way\n>> around, though.  \n>> \n>> If somebody really wants to use the xdg location and has a socket\n>> already there, using that existing socket would be the right thing\n>> to do.  However, when neither ~/.git-credential-cache/socket nor\n>> ~/.cache/git/socket exists, why should we prefer the latter over the\n>> former?\n>\n> How would they get a socket in the xdg location if we never create one?\n\nThey wouldn't.  It was my oblique way to say \"it is unclear from the\npatch description and the code why this is a good idea---it needs to\nbe explained better\" ;-).\n"},{"id":"313933","messageId":"520738BD-E3D4-46C5-8A6A-A8D2AE6CD233@gmail.com","threadId":"45367","inReplyTo":"xmqqtw6xrquw.fsf@gitster.mtv.corp.google.com","subject":"Re: [GSoC][PATCH 2/3] credential-cache.c: Make git use XDG_CACHE_HOME for credentials","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-13T19:22:24Z","receivedAt":"2017-03-13T19:22:57Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":">  I somehow feel that the order of precedence should be the other way\n>  around, though.\n>\n>  If somebody really wants to use the xdg location and has a socket\n>  already there, using that existing socket would be the right thing\n>  to do.  However, when neither ~/.git-credential-cache/socket nor\n>  ~/.cache/git/socket exists, why should we prefer the latter over the\n>  former?\n\nAt least to me the latter feels superior. It keeps clutter out of the\nhome directory putting it in a directory with all other cache files from\nother programs. If we continue to put the socket at\n~/.git-credential-cache/socket by default then checking\n~/.cache/git/credential/socket seems useless since the daemon will check\nsocket locations provided with —-socket anyways and there is no other\nway to create the socket at the new location.\n\nTo me it would make sense to check the old location and if it is not \nthere then use the XDG location to follow that standard. \n\nI guess that this is not the same behavior that git config —-global \n(it will only put its configuration file there if .gitconfig is unreadable)\nhas right now though so we should stay consistent and reverse the precedence\nhere.\n\nThanks for the feedback,\nDevin\n"},{"id":"313934","messageId":"E6DDA0B8-D062-45E7-97E1-D233A9BE1865@gmail.com","threadId":"45367","inReplyTo":"xmqqd1dlro8p.fsf@gitster.mtv.corp.google.com","subject":"Re: [GSoC][PATCH 2/3] credential-cache.c: Make git use XDG_CACHE_HOME for credentials","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-13T19:24:08Z","receivedAt":"2017-03-13T19:24:38Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"\n> They wouldn't.  It was my oblique way to say \"it is unclear from the\n> patch description and the code why this is a good idea---it needs to\n> be explained better\" ;-).\n\nOk, I will submit a new patch with a better explanation.\n\nDevin\n\n"},{"id":"313936","messageId":"96F783CD-F784-4B40-81A9-5AD48A9395AA@gmail.com","threadId":"45367","inReplyTo":"20170313184837.wnluuyflbx63cwlm@sigill.intra.peff.net","subject":"Re: [GSoC][PATCH 1/3] path.c: Add xdg_cache_home to get paths under XDG_CACHE_HOME","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-13T19:44:58Z","receivedAt":"2017-03-13T19:45:05Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"> And one final note. I notice that we return NULL if the user has no\n> HOME. But I'm not sure most callers are prepared to handle this. E.g.,\n> if you have no ident set and no HOME, then we will pass NULL to lstat().\n> On Linux at least that just gets you EFAULT, but I wouldn't be surprised\n> if it's a segfault on other systems (probably at least Windows, where we\n> have an lstat wrapper that calls strlen on the filename).\n\nRight now we check the return value from these two functions and if it\nis NULL we instead use some other configuration location.\n\nThat said I agree that this could lead to unexpected behavior in some\nscenarios.\n\nDevin\n"},{"id":"313961","messageId":"20170313204256.56438-2-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170313172232.96678-4-lehmacdj@gmail.com","subject":"[GSoC][PATCH v2 2/2] credential-cache: use XDG_CACHE_HOME for socket","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-13T20:42:56Z","receivedAt":"2017-03-13T20:43:20Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"git-credential-cache will now use a socket following the XDG base path\nspecification by default. This increases consistency with other\napplications and helps keep clutter out of users' home directories.\n\nWe still check the old socket location, ~/.git-credential-cache/socket\nfirst in case the user already has a socket at that location. This\nensures that a socket previously created will be used over forcibly\nswitching to the new socket location.\n\nIf there is not a socket at that location we create a new one at\n$XDG_CACHE_HOME/git/credential/socket. This complies with the XDG\nstandard and good for the reasons previously mentioned. We use the\nsubdirectory credential/ in case we later want to store other files\nunder $XDG_CACHE_HOME/git/ and to make the purpose of the socket clear.\n\nI also change to documentation to reflect the new default socket\nlocation.\n---\n Documentation/git-credential-cache.txt |  3 ++-\n credential-cache.c                     | 16 +++++++++++++++-\n 2 files changed, 17 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-credential-cache.txt b/Documentation/git-credential-cache.txt\nindex 96208f822..4b9db3856 100644\n--- a/Documentation/git-credential-cache.txt\n+++ b/Documentation/git-credential-cache.txt\n@@ -34,7 +34,8 @@ OPTIONS\n \n \tUse `<path>` to contact a running cache daemon (or start a new\n \tcache daemon if one is not started). Defaults to\n-\t`~/.git-credential-cache/socket`. If your home directory is on a\n+\t`~/.git-credential-cache/socket` if it exists and otherwise\n+    `$XDG_CACHE_HOME/git/credential/socket`. If your home directory is on a\n \tnetwork-mounted filesystem, you may need to change this to a\n \tlocal filesystem. You must specify an absolute path.\n \ndiff --git a/credential-cache.c b/credential-cache.c\nindex cc8a6ee19..db1343b46 100644\n--- a/credential-cache.c\n+++ b/credential-cache.c\n@@ -83,6 +83,20 @@ static void do_cache(const char *socket, const char *action, int timeout,\n \tstrbuf_release(&buf);\n }\n \n+static char *get_socket_path(void) {\n+\tchar *home_socket;\n+\n+\thome_socket = expand_user_path(\"~/.git-credential-cache/socket\");\n+\tif (home_socket) {\n+\t\tif (file_exists(home_socket))\n+\t\t\treturn home_socket;\n+\t\telse\n+\t\t\tfree(home_socket);\n+\t}\n+\n+\treturn xdg_cache_home(\"credential/socket\");\n+}\n+\n int cmd_main(int argc, const char **argv)\n {\n \tchar *socket_path = NULL;\n@@ -106,7 +120,7 @@ int cmd_main(int argc, const char **argv)\n \top = argv[0];\n \n \tif (!socket_path)\n-\t\tsocket_path = expand_user_path(\"~/.git-credential-cache/socket\");\n+\t\tsocket_path = get_socket_path();\n \tif (!socket_path)\n \t\tdie(\"unable to find a suitable socket path; use --socket\");\n \n-- \n2.11.0\n\n"},{"id":"313962","messageId":"20170313204355.56559-1-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170313172232.96678-4-lehmacdj@gmail.com","subject":"[GSoC][PATCH v2 1/2] path.c: add xdg_cache_home","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-13T20:43:54Z","receivedAt":"2017-03-13T20:44:07Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"We already have xdg_config_home to format paths relative to\nXDG_CONFIG_HOME. Let's provide a similar function xdg_cache_home to do\nthe same for paths relative to XDG_CACHE_HOME.\n\nSigned-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n cache.h |  7 +++++++\n path.c  | 15 +++++++++++++++\n 2 files changed, 22 insertions(+)\n\ndiff --git a/cache.h b/cache.h\nindex 8c0e64420..378a636e1 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1169,6 +1169,13 @@ extern int is_ntfs_dotgit(const char *name);\n  */\n extern char *xdg_config_home(const char *filename);\n \n+/**\n+ * Return a newly allocated string with the evaluation of\n+ * \"$XDG_CACHE_HOME/git/$filename\" if $XDG_CONFIG_HOME is non-empty, otherwise\n+ * \"$HOME/.config/git/$filename\". Return NULL upon error.\n+ */\n+extern char *xdg_cache_home(const char *filename);\n+\n /* object replacement */\n #define LOOKUP_REPLACE_OBJECT 1\n #define LOOKUP_UNKNOWN_OBJECT 2\ndiff --git a/path.c b/path.c\nindex efcedafba..22248436b 100644\n--- a/path.c\n+++ b/path.c\n@@ -1272,6 +1272,21 @@ char *xdg_config_home(const char *filename)\n \treturn NULL;\n }\n \n+char *xdg_cache_home(const char *filename)\n+{\n+\tconst char *home, *cache_home;\n+\n+\tassert(filename);\n+\tcache_home = getenv(\"XDG_CACHE_HOME\");\n+\tif (cache_home && *cache_home)\n+\t\treturn mkpathdup(\"%s/git/%s\", cache_home, filename);\n+\n+\thome = getenv(\"HOME\");\n+\tif (home)\n+\t\treturn mkpathdup(\"%s/.cache/git/%s\", home, filename);\n+\treturn NULL;\n+}\n+\n GIT_PATH_FUNC(git_path_cherry_pick_head, \"CHERRY_PICK_HEAD\")\n GIT_PATH_FUNC(git_path_revert_head, \"REVERT_HEAD\")\n GIT_PATH_FUNC(git_path_squash_msg, \"SQUASH_MSG\")\n-- \n2.11.0\n\n"},{"id":"313963","messageId":"20170313204355.56559-2-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170313204355.56559-1-lehmacdj@gmail.com","subject":"[GSoC][PATCH v2 2/2] credential-cache: use XDG_CACHE_HOME for socket","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-13T20:43:55Z","receivedAt":"2017-03-13T20:44:08Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"git-credential-cache will now use a socket following the XDG base path\nspecification by default. This increases consistency with other\napplications and helps keep clutter out of users' home directories.\n\nWe still check the old socket location, ~/.git-credential-cache/socket\nfirst in case the user already has a socket at that location. This\nensures that a socket previously created will be used over forcibly\nswitching to the new socket location.\n\nIf there is not a socket at that location we create a new one at\n$XDG_CACHE_HOME/git/credential/socket. This complies with the XDG\nstandard and good for the reasons previously mentioned. We use the\nsubdirectory credential/ in case we later want to store other files\nunder $XDG_CACHE_HOME/git/ and to make the purpose of the socket clear.\n\nI also change to documentation to reflect the new default socket\nlocation.\n---\n Documentation/git-credential-cache.txt |  3 ++-\n credential-cache.c                     | 16 +++++++++++++++-\n 2 files changed, 17 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-credential-cache.txt b/Documentation/git-credential-cache.txt\nindex 96208f822..4b9db3856 100644\n--- a/Documentation/git-credential-cache.txt\n+++ b/Documentation/git-credential-cache.txt\n@@ -34,7 +34,8 @@ OPTIONS\n \n \tUse `<path>` to contact a running cache daemon (or start a new\n \tcache daemon if one is not started). Defaults to\n-\t`~/.git-credential-cache/socket`. If your home directory is on a\n+\t`~/.git-credential-cache/socket` if it exists and otherwise\n+    `$XDG_CACHE_HOME/git/credential/socket`. If your home directory is on a\n \tnetwork-mounted filesystem, you may need to change this to a\n \tlocal filesystem. You must specify an absolute path.\n \ndiff --git a/credential-cache.c b/credential-cache.c\nindex cc8a6ee19..db1343b46 100644\n--- a/credential-cache.c\n+++ b/credential-cache.c\n@@ -83,6 +83,20 @@ static void do_cache(const char *socket, const char *action, int timeout,\n \tstrbuf_release(&buf);\n }\n \n+static char *get_socket_path(void) {\n+\tchar *home_socket;\n+\n+\thome_socket = expand_user_path(\"~/.git-credential-cache/socket\");\n+\tif (home_socket) {\n+\t\tif (file_exists(home_socket))\n+\t\t\treturn home_socket;\n+\t\telse\n+\t\t\tfree(home_socket);\n+\t}\n+\n+\treturn xdg_cache_home(\"credential/socket\");\n+}\n+\n int cmd_main(int argc, const char **argv)\n {\n \tchar *socket_path = NULL;\n@@ -106,7 +120,7 @@ int cmd_main(int argc, const char **argv)\n \top = argv[0];\n \n \tif (!socket_path)\n-\t\tsocket_path = expand_user_path(\"~/.git-credential-cache/socket\");\n+\t\tsocket_path = get_socket_path();\n \tif (!socket_path)\n \t\tdie(\"unable to find a suitable socket path; use --socket\");\n \n-- \n2.11.0\n\n"},{"id":"313977","messageId":"xmqqefy0rh4h.fsf@gitster.mtv.corp.google.com","threadId":"45367","inReplyTo":"20170313204355.56559-1-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH v2 1/2] path.c: add xdg_cache_home","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-13T21:39:26Z","receivedAt":"2017-03-13T21:39:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Devin Lehmacher <lehmacdj@gmail.com> writes:\n\n> We already have xdg_config_home to format paths relative to\n> XDG_CONFIG_HOME. Let's provide a similar function xdg_cache_home to do\n> the same for paths relative to XDG_CACHE_HOME.\n\nNicely explained.\n\n> +/**\n> + * Return a newly allocated string with the evaluation of\n> + * \"$XDG_CACHE_HOME/git/$filename\" if $XDG_CONFIG_HOME is non-empty, otherwise\n> + * \"$HOME/.config/git/$filename\". Return NULL upon error.\n\ns|CONFIG|CACHE| and s|.config|.cache| are needed, methinks.\n\nWill fix while queuing, so no need to resend only to fix this typo.\n"},{"id":"313992","messageId":"xmqqa88orgjd.fsf@gitster.mtv.corp.google.com","threadId":"45367","inReplyTo":"20170313204355.56559-2-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH v2 2/2] credential-cache: use XDG_CACHE_HOME for socket","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-13T21:52:06Z","receivedAt":"2017-03-13T21:52:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Devin Lehmacher <lehmacdj@gmail.com> writes:\n\n> git-credential-cache will now use a socket following the XDG base path\n> specification by default. This increases consistency with other\n> applications and helps keep clutter out of users' home directories.\n\nWe tend to write our log messages in imperative mood, as if you are\ngiving an order to the codebase to \"be like so\" (alternatively, you\ncan read them as if you are giving an order to the maintainer of the\ncode to \"make these changes\").\n\n\tWe have been using ~/.git-credential-cache/socket as the\n\tlocation to store the UNIX socket to communicate with the\n\tcredential daemon process.  In order to make it more\n\tconsistent with other applications and reduce clutter in the\n\thome directory, move it to $XDG_CACHE_HOME/git/credential/socket,\n\twhich matches what XDG base path specification suggests.\n\nSimilarly for the other two paragraphs.  Instead of \"We still\ncheck the old location ...\", just \"Check the old location ...\", etc.\n\n> If there is not a socket at that location we create a new one at\n> $XDG_CACHE_HOME/git/credential/socket. This complies with the XDG\n> standard and good for the reasons previously mentioned. \n\nAnd the second sentence can go; you already said why you think\nXDG_CACHE_HOME is a good idea.\n\n> We use the\n> subdirectory credential/ in case we later want to store other files\n> under $XDG_CACHE_HOME/git/ and to make the purpose of the socket clear.\n\nAnd this probably can disappear (or rolled into the first paragraph,\nif we really want; personally I think it is obvious why we want the\nextra \"credential\" directory under \"git\" there).\n\n> I also change to documentation to reflect the new default socket\n> location.\n\nThis probably does not have to be said, as it is obvious from the\ndiffstat.\n\nMissing sign-off.\n\n> ---\n>  Documentation/git-credential-cache.txt |  3 ++-\n>  credential-cache.c                     | 16 +++++++++++++++-\n>  2 files changed, 17 insertions(+), 2 deletions(-)\n>\n> diff --git a/Documentation/git-credential-cache.txt b/Documentation/git-credential-cache.txt\n> index 96208f822..4b9db3856 100644\n> --- a/Documentation/git-credential-cache.txt\n> +++ b/Documentation/git-credential-cache.txt\n> @@ -34,7 +34,8 @@ OPTIONS\n>  \n>  \tUse `<path>` to contact a running cache daemon (or start a new\n>  \tcache daemon if one is not started). Defaults to\n> -\t`~/.git-credential-cache/socket`. If your home directory is on a\n> +\t`~/.git-credential-cache/socket` if it exists and otherwise\n> +    `$XDG_CACHE_HOME/git/credential/socket`. If your home directory is on a\n\nThere is a funny indentation here.\n\n>  \tnetwork-mounted filesystem, you may need to change this to a\n>  \tlocal filesystem. You must specify an absolute path.\n>  \n> diff --git a/credential-cache.c b/credential-cache.c\n> index cc8a6ee19..db1343b46 100644\n> --- a/credential-cache.c\n> +++ b/credential-cache.c\n> @@ -83,6 +83,20 @@ static void do_cache(const char *socket, const char *action, int timeout,\n>  \tstrbuf_release(&buf);\n>  }\n>  \n> +static char *get_socket_path(void) {\n> +\tchar *home_socket;\n> +\n> +\thome_socket = expand_user_path(\"~/.git-credential-cache/socket\");\n> +\tif (home_socket) {\n> +\t\tif (file_exists(home_socket))\n\nDon't we want to make sure that this path _is_ a socket?  In general\nI think file_exists() is a poor choice to use here (the existing use\nare all about having a regular file there, and its definition may be\nlater tightened from \"does lstat() succeed?\" to something a bit more\nsensible, and FIFO may start failing the updated test.\n\nThanks.\n"},{"id":"314012","messageId":"20170314003246.71586-1-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"xmqqa88orgjd.fsf@gitster.mtv.corp.google.com","subject":"[GSoC][PATCH/RFC v3 0/3] Fix commit messages, check if socket is socket","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-14T00:32:43Z","receivedAt":"2017-03-14T00:33:16Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"I fixed all of the commit messages and the weird indentation.\nI also now check that the socket is actually a socket.\n\nWhat do you think of the function is_socket? Is it general enough to be put\nin dir.h or unix_socket.h for use in other files? Or should it be left as is?\n\n- Devin\n"},{"id":"314013","messageId":"20170314003246.71586-4-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170314003246.71586-1-lehmacdj@gmail.com","subject":"[GSoC][PATCH/RFC v3 3/3] credential-cache: only use user_socket if a socket","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-14T00:32:46Z","receivedAt":"2017-03-14T00:33:18Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"Create function is_socket.\nMake get_socket_path return check if ~/.git-credential-cache/socket is a\nsocket and not just a file. If file_exists behavior could change in an\nunexpected way. Additionally a file at ~/.git-credential-cache/socket\ncould cause false positives which would otherwise lead to crashes.\n\nSigned-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n credential-cache.c | 8 +++++++-\n 1 file changed, 7 insertions(+), 1 deletion(-)\n\ndiff --git a/credential-cache.c b/credential-cache.c\nindex db1343b46..63236adc2 100644\n--- a/credential-cache.c\n+++ b/credential-cache.c\n@@ -83,12 +83,18 @@ static void do_cache(const char *socket, const char *action, int timeout,\n \tstrbuf_release(&buf);\n }\n \n+static int is_socket(char *path) {\n+\tstruct stat sb;\n+\tint ret = lstat(path, &sb);\n+\treturn ret && S_IFSOCK(sb.st_mode);\n+}\n+\n static char *get_socket_path(void) {\n \tchar *home_socket;\n \n \thome_socket = expand_user_path(\"~/.git-credential-cache/socket\");\n \tif (home_socket) {\n-\t\tif (file_exists(home_socket))\n+\t\tif (is_socket(home_socket))\n \t\t\treturn home_socket;\n \t\telse\n \t\t\tfree(home_socket);\n-- \n2.11.0\n\n"},{"id":"314014","messageId":"20170314003246.71586-3-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170314003246.71586-1-lehmacdj@gmail.com","subject":"[GSoC][PATCH/RFC v3 2/3] credential-cache: use XDG_CACHE_HOME for socket","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-14T00:32:45Z","receivedAt":"2017-03-14T00:33:19Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"Make git-credential-cache follow the XDG base path specification by\ndefault. This increases consistency with other applications and helps\nkeep clutter out of users' home directories.\n\nCheck the old socket location, ~/.git-credential-cache/socket and use it\ninstead if there is already a socket at that location rather than\nforcibly creating a new socket at the new location.\nIf there is not a socket at that location create a new one at\n$XDG_CACHE_HOME/git/credential/socket following XDG base path\nspecification. Use the subdirectory credential/ in case other files are\nstored under $XDG_CACHE_HOME/git/ in the future and to make the socket's\npurpose clear.\n\nSigned-off-by: Devin Lehmacher <lehmacdj@gmail.com>\nReviewed-by: Junio C Hamano, Jeff King\n---\n Documentation/git-credential-cache.txt | 10 ++++++----\n credential-cache.c                     | 16 +++++++++++++++-\n 2 files changed, 21 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-credential-cache.txt b/Documentation/git-credential-cache.txt\nindex 96208f822..fce6319e8 100644\n--- a/Documentation/git-credential-cache.txt\n+++ b/Documentation/git-credential-cache.txt\n@@ -33,10 +33,12 @@ OPTIONS\n --socket <path>::\n \n \tUse `<path>` to contact a running cache daemon (or start a new\n-\tcache daemon if one is not started). Defaults to\n-\t`~/.git-credential-cache/socket`. If your home directory is on a\n-\tnetwork-mounted filesystem, you may need to change this to a\n-\tlocal filesystem. You must specify an absolute path.\n+\tcache daemon if one is not started).\n+\tDefaults to `~/.git-credential-cache/socket` if it exists and\n+\t`$XDG_CACHE_HOME/git/credential/socket` otherwise.\n+\tIf your home directory is on a network-mounted filesystem, you\n+\tmay need to change this to a local filesystem. You must specify\n+\tan absolute path.\n \n CONTROLLING THE DAEMON\n ----------------------\ndiff --git a/credential-cache.c b/credential-cache.c\nindex cc8a6ee19..db1343b46 100644\n--- a/credential-cache.c\n+++ b/credential-cache.c\n@@ -83,6 +83,20 @@ static void do_cache(const char *socket, const char *action, int timeout,\n \tstrbuf_release(&buf);\n }\n \n+static char *get_socket_path(void) {\n+\tchar *home_socket;\n+\n+\thome_socket = expand_user_path(\"~/.git-credential-cache/socket\");\n+\tif (home_socket) {\n+\t\tif (file_exists(home_socket))\n+\t\t\treturn home_socket;\n+\t\telse\n+\t\t\tfree(home_socket);\n+\t}\n+\n+\treturn xdg_cache_home(\"credential/socket\");\n+}\n+\n int cmd_main(int argc, const char **argv)\n {\n \tchar *socket_path = NULL;\n@@ -106,7 +120,7 @@ int cmd_main(int argc, const char **argv)\n \top = argv[0];\n \n \tif (!socket_path)\n-\t\tsocket_path = expand_user_path(\"~/.git-credential-cache/socket\");\n+\t\tsocket_path = get_socket_path();\n \tif (!socket_path)\n \t\tdie(\"unable to find a suitable socket path; use --socket\");\n \n-- \n2.11.0\n\n"},{"id":"314015","messageId":"20170314003246.71586-2-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170314003246.71586-1-lehmacdj@gmail.com","subject":"[GSoC][PATCH/RFC v3 1/3] path.c: add xdg_cache_home","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-14T00:32:44Z","receivedAt":"2017-03-14T00:33:21Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"We already have xdg_config_home to format paths relative to\nXDG_CONFIG_HOME. Let's provide a similar function xdg_cache_home to do\nthe same for paths relative to XDG_CACHE_HOME.\n\nSigned-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n cache.h |  7 +++++++\n path.c  | 15 +++++++++++++++\n 2 files changed, 22 insertions(+)\n\ndiff --git a/cache.h b/cache.h\nindex 8c0e64420..5db29a945 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1169,6 +1169,13 @@ extern int is_ntfs_dotgit(const char *name);\n  */\n extern char *xdg_config_home(const char *filename);\n \n+/**\n+ * Return a newly allocated string with the evaluation of\n+ * \"$XDG_CACHE_HOME/git/$filename\" if $XDG_CACHE_HOME is non-empty, otherwise\n+ * \"$HOME/.cache/git/$filename\". Return NULL upon error.\n+ */\n+extern char *xdg_cache_home(const char *filename);\n+\n /* object replacement */\n #define LOOKUP_REPLACE_OBJECT 1\n #define LOOKUP_UNKNOWN_OBJECT 2\ndiff --git a/path.c b/path.c\nindex efcedafba..22248436b 100644\n--- a/path.c\n+++ b/path.c\n@@ -1272,6 +1272,21 @@ char *xdg_config_home(const char *filename)\n \treturn NULL;\n }\n \n+char *xdg_cache_home(const char *filename)\n+{\n+\tconst char *home, *cache_home;\n+\n+\tassert(filename);\n+\tcache_home = getenv(\"XDG_CACHE_HOME\");\n+\tif (cache_home && *cache_home)\n+\t\treturn mkpathdup(\"%s/git/%s\", cache_home, filename);\n+\n+\thome = getenv(\"HOME\");\n+\tif (home)\n+\t\treturn mkpathdup(\"%s/.cache/git/%s\", home, filename);\n+\treturn NULL;\n+}\n+\n GIT_PATH_FUNC(git_path_cherry_pick_head, \"CHERRY_PICK_HEAD\")\n GIT_PATH_FUNC(git_path_revert_head, \"REVERT_HEAD\")\n GIT_PATH_FUNC(git_path_squash_msg, \"SQUASH_MSG\")\n-- \n2.11.0\n\n"},{"id":"314016","messageId":"2ACF39EA-B76A-462E-993C-ACBB143A1581@gmail.com","threadId":"45367","inReplyTo":"20170314003246.71586-4-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH/RFC v3 3/3] credential-cache: only use user_socket if a socket","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-14T00:40:27Z","receivedAt":"2017-03-14T00:40:33Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"> +static int is_socket(char *path) {\n> +\tstruct stat sb;\n> +\tint ret = lstat(path, &sb);\n> +\treturn ret && S_IFSOCK(sb.st_mode);\n> +}\n\nThis patch won’t even compile. S_IFSOCK(sb.st_mode) should have been S_IFSOCK & sb.st_mode.\n\n(I guess I should have compiled first)\n\nAfter making that change this patch compiles (currently running tests).\n\n-Devin"},{"id":"314017","messageId":"20170314004420.GC66601@google.com","threadId":"45367","inReplyTo":"2ACF39EA-B76A-462E-993C-ACBB143A1581@gmail.com","subject":"Re: [GSoC][PATCH/RFC v3 3/3] credential-cache: only use user_socket if a socket","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-03-14T00:44:20Z","receivedAt":"2017-03-14T00:44:31Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"On 03/13, Devin Lehmacher wrote:\n> > +static int is_socket(char *path) {\n> > +\tstruct stat sb;\n> > +\tint ret = lstat(path, &sb);\n> > +\treturn ret && S_IFSOCK(sb.st_mode);\n> > +}\n> \n> This patch won’t even compile. S_IFSOCK(sb.st_mode) should have been S_IFSOCK & sb.st_mode.\n> \n> (I guess I should have compiled first)\n> \n> After making that change this patch compiles (currently running tests).\n\nBest practice for submitting patches would be to ensure that each patch\ncompiles without errors (with the DEVELOPER=1 flag set) and that the\nentire test suite passes with no errors; this is to maintain\nbisect-ability.  Only after you've done this should you send your\npatches to the mailing list.\n\n-- \nBrandon Williams\n"},{"id":"314018","messageId":"D11DDB6C-7B6A-43BF-86A3-6DA48109C07C@gmail.com","threadId":"45367","inReplyTo":"20170314004420.GC66601@google.com","subject":"Re: [GSoC][PATCH/RFC v3 3/3] credential-cache: only use user_socket if a socket","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-14T01:30:28Z","receivedAt":"2017-03-14T01:30:36Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"> Best practice for submitting patches would be to ensure that each patch\n> compiles without errors (with the DEVELOPER=1 flag set) and that the\n> entire test suite passes with no errors; this is to maintain\n> bisect-ability.  Only after you've done this should you send your\n> patches to the mailing list.\n\nThanks for the advice. I will be more careful in the future.\n\n-Devin\n\n"},{"id":"314019","messageId":"xmqqd1dklj8u.fsf@gitster.mtv.corp.google.com","threadId":"45367","inReplyTo":"20170314003246.71586-3-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH/RFC v3 2/3] credential-cache: use XDG_CACHE_HOME for socket","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-14T01:50:09Z","receivedAt":"2017-03-14T01:50:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Devin Lehmacher <lehmacdj@gmail.com> writes:\n\n> Signed-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n> Reviewed-by: Junio C Hamano, Jeff King\n\nThe last line is premature; neither of us reviewed this exact\nversion and haven't checked if all the issues we mentioned in the\nprevious review have been addressed.\n\n\n> +static char *get_socket_path(void) {\n\nCompare ths line with how cmd_main() below is declared.  Notice\nany difference?  We begin our functions like this:\n\n\tstatic char *get_socket_path(void)\n\t{\n\n"},{"id":"314020","messageId":"xmqq8to8lj59.fsf@gitster.mtv.corp.google.com","threadId":"45367","inReplyTo":"20170314003246.71586-4-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH/RFC v3 3/3] credential-cache: only use user_socket if a socket","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-14T01:52:18Z","receivedAt":"2017-03-14T01:52:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Devin Lehmacher <lehmacdj@gmail.com> writes:\n\n> diff --git a/credential-cache.c b/credential-cache.c\n> index db1343b46..63236adc2 100644\n> --- a/credential-cache.c\n> +++ b/credential-cache.c\n> @@ -83,12 +83,18 @@ static void do_cache(const char *socket, const char *action, int timeout,\n>  \tstrbuf_release(&buf);\n>  }\n>  \n> +static int is_socket(char *path) {\n> +\tstruct stat sb;\n> +\tint ret = lstat(path, &sb);\n> +\treturn ret && S_IFSOCK(sb.st_mode);\n> +}\n> +\n>  static char *get_socket_path(void) {\n>  \tchar *home_socket;\n>  \n>  \thome_socket = expand_user_path(\"~/.git-credential-cache/socket\");\n>  \tif (home_socket) {\n> -\t\tif (file_exists(home_socket))\n> +\t\tif (is_socket(home_socket))\n\nThis should be done as part of 2/3, no?  It does not make sense to\nadd 2/3 and then immediately say \"oops, the check in 2/3 is wrong,\nand let's update it like so\".\n"},{"id":"314027","messageId":"xmqqo9x4jsmi.fsf@gitster.mtv.corp.google.com","threadId":"45367","inReplyTo":"xmqq8to8lj59.fsf@gitster.mtv.corp.google.com","subject":"Re: [GSoC][PATCH/RFC v3 3/3] credential-cache: only use user_socket if a socket","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-14T06:10:29Z","receivedAt":"2017-03-14T06:10:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Devin Lehmacher <lehmacdj@gmail.com> writes:\n>\n>> diff --git a/credential-cache.c b/credential-cache.c\n>> index db1343b46..63236adc2 100644\n>> --- a/credential-cache.c\n>> +++ b/credential-cache.c\n>> @@ -83,12 +83,18 @@ static void do_cache(const char *socket, const char *action, int timeout,\n>>  \tstrbuf_release(&buf);\n>>  }\n>>  \n>> +static int is_socket(char *path) {\n>> +\tstruct stat sb;\n>> +\tint ret = lstat(path, &sb);\n>> +\treturn ret && S_IFSOCK(sb.st_mode);\n>> +}\n>> +\n>>  static char *get_socket_path(void) {\n>>  \tchar *home_socket;\n>>  \n>>  \thome_socket = expand_user_path(\"~/.git-credential-cache/socket\");\n>>  \tif (home_socket) {\n>> -\t\tif (file_exists(home_socket))\n>> +\t\tif (is_socket(home_socket))\n>\n> This should be done as part of 2/3, no?  It does not make sense to\n> add 2/3 and then immediately say \"oops, the check in 2/3 is wrong,\n> and let's update it like so\".\n\nAlso I think you would want to use S_ISFIFO() and/or S_ISSOCK()\nmacros (I do not offhand recall which one credential cache daemon\nuses), not the S_IFxxx constant.\n\nPerhaps \n\n   1/3 - add xdg_cache similar to xdg_config\n\n   2/3 - add is_socket()\n\n   3/3 - use xdg_cache location for socket if traditional location\n         is not in use\n\nwould be a better logical ordering of the patches.\n\nHaving said that, I do not think ~/.git-credential-cache/socket is\nthe right thing to test.  If the ~/.git-credential-cache directory\nalready exists, it is likely that the user has a set-up that works\nwell with \"socket\" inside it, and it is safer to keep using that\nlocation.  \n\nOn the other hand, if that directory does not exist, we know it is\nsafe to use whatever new location---after all, the lack of the\ndirectory tells us that the user has never used the traditional\nlocation successfully ;-)\n\nSo is_socket() may not even be needed, in which case this will be a\ntwo-patch series:\n\n   1/2 - add xdg_cache similar to xdg_config\n   2/2 - use xdg_cache location if ~/.git-credential-cache/ is not there\n\n"},{"id":"314028","messageId":"AAFF0938-E7F7-4EEE-9338-CD9049E51AE2@gmail.com","threadId":"45367","inReplyTo":"xmqqo9x4jsmi.fsf@gitster.mtv.corp.google.com","subject":"Re: [GSoC][PATCH/RFC v3 3/3] credential-cache: only use user_socket if a socket","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-14T06:17:54Z","receivedAt":"2017-03-14T06:18:03Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"> Also I think you would want to use S_ISFIFO() and/or S_ISSOCK()\n> macros (I do not offhand recall which one credential cache daemon\n> uses), not the S_IFxxx constant.\n\nHuh. These macros are not on the man page for lstat.\n\n> Having said that, I do not think ~/.git-credential-cache/socket is\n> the right thing to test.  If the ~/.git-credential-cache directory\n> already exists, it is likely that the user has a set-up that works\n> well with \"socket\" inside it, and it is safer to keep using that\n> location.\n>\n> On the other hand, if that directory does not exist, we know it is\n> safe to use whatever new location---after all, the lack of the\n> directory tells us that the user has never used the traditional\n> location successfully ;-)\n\nThat makes sense\n\n-Devin\n"},{"id":"314036","messageId":"20170314170333.GD66601@google.com","threadId":"45367","inReplyTo":"D11DDB6C-7B6A-43BF-86A3-6DA48109C07C@gmail.com","subject":"Re: [GSoC][PATCH/RFC v3 3/3] credential-cache: only use user_socket if a socket","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-03-14T17:03:33Z","receivedAt":"2017-03-14T17:03:45Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"On 03/13, Devin Lehmacher wrote:\n> > Best practice for submitting patches would be to ensure that each patch\n> > compiles without errors (with the DEVELOPER=1 flag set) and that the\n> > entire test suite passes with no errors; this is to maintain\n> > bisect-ability.  Only after you've done this should you send your\n> > patches to the mailing list.\n> \n> Thanks for the advice. I will be more careful in the future.\n\nOf course! And no worries, I just wanted you to be aware of the\nconventions so that you have an easier time contributing :)\n\n-- \nBrandon Williams\n"},{"id":"314208","messageId":"20170316051827.97198-1-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170314003246.71586-4-lehmacdj@gmail.com","subject":"[GSoC][PATCH v4 0/4] Moving credential-cache socket to xdg path","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-16T05:18:23Z","receivedAt":"2017-03-16T05:20:16Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"I implemented all changes from the previous reviews and also wrote a few\ntests.\n\n-Devin\n\n"},{"id":"314209","messageId":"20170316051827.97198-2-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170316051827.97198-1-lehmacdj@gmail.com","subject":"[GSoC][PATCH v4 1/4] path.c: add xdg_cache_home","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-16T05:18:24Z","receivedAt":"2017-03-16T05:20:28Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"We already have xdg_config_home to format paths relative to\nXDG_CONFIG_HOME. Let's provide a similar function xdg_cache_home to do\nthe same for paths relative to XDG_CACHE_HOME.\n\nSigned-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n cache.h |  7 +++++++\n path.c  | 15 +++++++++++++++\n 2 files changed, 22 insertions(+)\n\ndiff --git a/cache.h b/cache.h\nindex c95826971..66761bc56 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1169,6 +1169,13 @@ extern int is_ntfs_dotgit(const char *name);\n  */\n extern char *xdg_config_home(const char *filename);\n \n+/**\n+ * Return a newly allocated string with the evaluation of\n+ * \"$XDG_CACHE_HOME/git/$filename\" if $XDG_CACHE_HOME is non-empty, otherwise\n+ * \"$HOME/.cache/git/$filename\". Return NULL upon error.\n+ */\n+extern char *xdg_cache_home(const char *filename);\n+\n /* object replacement */\n #define LOOKUP_REPLACE_OBJECT 1\n #define LOOKUP_UNKNOWN_OBJECT 2\ndiff --git a/path.c b/path.c\nindex efcedafba..22248436b 100644\n--- a/path.c\n+++ b/path.c\n@@ -1272,6 +1272,21 @@ char *xdg_config_home(const char *filename)\n \treturn NULL;\n }\n \n+char *xdg_cache_home(const char *filename)\n+{\n+\tconst char *home, *cache_home;\n+\n+\tassert(filename);\n+\tcache_home = getenv(\"XDG_CACHE_HOME\");\n+\tif (cache_home && *cache_home)\n+\t\treturn mkpathdup(\"%s/git/%s\", cache_home, filename);\n+\n+\thome = getenv(\"HOME\");\n+\tif (home)\n+\t\treturn mkpathdup(\"%s/.cache/git/%s\", home, filename);\n+\treturn NULL;\n+}\n+\n GIT_PATH_FUNC(git_path_cherry_pick_head, \"CHERRY_PICK_HEAD\")\n GIT_PATH_FUNC(git_path_revert_head, \"REVERT_HEAD\")\n GIT_PATH_FUNC(git_path_squash_msg, \"SQUASH_MSG\")\n-- \n2.11.0\n\n"},{"id":"314210","messageId":"20170316051827.97198-5-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170316051827.97198-1-lehmacdj@gmail.com","subject":"[GSoC][PATCH v4 4/4] credential-cache: add tests for XDG functionality","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-16T05:18:27Z","receivedAt":"2017-03-16T05:20:33Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"Signed-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n t/t0301-credential-cache.sh | 64 +++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 64 insertions(+)\n\ndiff --git a/t/t0301-credential-cache.sh b/t/t0301-credential-cache.sh\nindex 82c841121..664c6dda1 100755\n--- a/t/t0301-credential-cache.sh\n+++ b/t/t0301-credential-cache.sh\n@@ -12,6 +12,7 @@ test -z \"$NO_UNIX_SOCKETS\" || {\n # don't leave a stale daemon running\n trap 'code=$?; git credential-cache exit; (exit $code); die' EXIT\n \n+# test that the daemon works with no special setup\n helper_test cache\n helper_test_timeout cache --timeout=1\n \n@@ -20,4 +21,67 @@ helper_test_timeout cache --timeout=1\n # our socket, leaving us with no way to access the daemon.\n git credential-cache exit\n \n+# we need to use rm -rf here since sometimes the daemon hasn't finished\n+# cleaning up after itself and rmdir fails\n+test_expect_success 'credential-cache --socket option overrides default location' '\n+\ttest_when_finished \"rm -rf \\\"$HOME\\\"/dir/\" &&\n+\tcheck approve \"cache --socket \\\"$HOME/dir/socket\\\"\" <<-\\EOF &&\n+\tprotocol=https\n+\thost=example.com\n+\tusername=store-user\n+\tpassword=store-pass\n+\tEOF\n+\ttest -S \"$HOME/dir/socket\" &&\n+\tgit credential-cache exit\n+'\n+\n+XDG_CACHE_HOME=\"$HOME/xdg\"\n+export XDG_CACHE_HOME\n+# test behavior when XDG_CACHE_HOME is set\n+helper_test cache\n+\n+test_expect_success \"use custom XDG_CACHE_HOME if set and default sockets are not created\" '\n+\ttest -S \"$XDG_CACHE_HOME/git/credential/socket\" &&\n+\ttest_path_is_missing \"$HOME/.git-credential-cache/socket\" &&\n+\ttest_path_is_missing \"$HOME/.cache/git/credential/socket\" &&\n+\tgit credential-cache exit\n+'\n+unset XDG_CACHE_HOME\n+\n+test_expect_success \"use custom XDG_CACHE_HOME even if xdg socket exists\" '\n+\tcheck approve cache <<-\\EOF &&\n+\tprotocol=https\n+\thost=example.com\n+\tusername=store-user\n+\tpassword=store-pass\n+\tEOF\n+\ttest -S \"$HOME/.cache/git/credential/socket\" &&\n+\tXDG_CACHE_HOME=\"$HOME/xdg\" &&\n+\texport XDG_CACHE_HOME &&\n+\tcheck approve cache <<-\\EOF &&\n+\tprotocol=https\n+\thost=example.com\n+\tusername=store-user\n+\tpassword=store-pass\n+\tEOF\n+\ttest -S \"$HOME/xdg/git/credential/socket\" &&\n+\tgit credential-cache exit &&\n+\tunset XDG_CACHE_HOME\n+'\n+\n+# we need to use rm -rf here since sometimes the daemon hasn't finished\n+# cleaning up after itself and rmdir fails\n+test_expect_success 'use user socket if user directory exists' '\n+\ttest_when_finished \"rm -rf \\\"$HOME/.git-credential-cache/\\\"\" &&\n+\tmkdir -p -m 700 \"$HOME/.git-credential-cache/\" &&\n+\tcheck approve cache <<-\\EOF &&\n+\tprotocol=https\n+\thost=example.com\n+\tusername=store-user\n+\tpassword=store-pass\n+\tEOF\n+\ttest -S \"$HOME/.git-credential-cache/socket\" &&\n+\tgit credential-cache exit\n+'\n+\n test_done\n-- \n2.11.0\n\n"},{"id":"314211","messageId":"20170316051827.97198-3-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170316051827.97198-1-lehmacdj@gmail.com","subject":"[GSoC][PATCH v4 2/4] dir: add directory_exists","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-16T05:18:25Z","receivedAt":"2017-03-16T05:20:40Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"file_exists currently only does an lstat to see if anything is at the\npath. For some purposes it would be better to ensure that a path\nis a certain type of file. Add function directory_exists that checks if\na path exists and is a directory.\n\nSigned-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n dir.c | 7 +++++++\n dir.h | 1 +\n 2 files changed, 8 insertions(+)\n\ndiff --git a/dir.c b/dir.c\nindex aeeb5ce10..f6c23ecd2 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -2055,6 +2055,13 @@ int file_exists(const char *f)\n \treturn lstat(f, &sb) == 0;\n }\n \n+int directory_exists(const char *path)\n+{\n+\tstruct stat sb;\n+\tint ret = lstat(path, &sb);\n+\treturn ret == 0 && S_ISDIR(sb.st_mode);\n+}\n+\n static int cmp_icase(char a, char b)\n {\n \tif (a == b)\ndiff --git a/dir.h b/dir.h\nindex bf23a470a..9f8278795 100644\n--- a/dir.h\n+++ b/dir.h\n@@ -247,6 +247,7 @@ extern void add_exclude(const char *string, const char *base,\n extern void clear_exclude_list(struct exclude_list *el);\n extern void clear_directory(struct dir_struct *dir);\n extern int file_exists(const char *);\n+extern int directory_exists(const char *);\n \n extern int is_inside_dir(const char *dir);\n extern int dir_inside_of(const char *subdir, const char *dir);\n-- \n2.11.0\n\n"},{"id":"314212","messageId":"20170316051827.97198-4-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170316051827.97198-1-lehmacdj@gmail.com","subject":"[GSoC][PATCH v4 3/4] credential-cache: use XDG_CACHE_HOME for socket","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-16T05:18:26Z","receivedAt":"2017-03-16T05:20:41Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"Make git-credential-cache follow the XDG base path specification by\ndefault. This increases consistency with other applications and helps\nkeep clutter out of users' home directories.\n\nCheck the old socket location, ~/.git-credential-cache/, and use\n~/.git-credential-cache/socket if that directory exists rather than\nforcing users who have used `git credential-cache` before to migrate to\nthe new XDG compliant location.\nOtherwise use the socket $XDG_CACHE_HOME/git/credential/socket following\nXDG base path specification. Use the subdirectory credential/ in case\nother files are cached under $XDG_CACHE_HOME/git/ in the future and to\nmake the socket's purpose clear.\n\nSigned-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n Documentation/git-credential-cache.txt | 11 +++++++----\n credential-cache.c                     | 15 ++++++++++++++-\n 2 files changed, 21 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-credential-cache.txt b/Documentation/git-credential-cache.txt\nindex 96208f822..2b8582639 100644\n--- a/Documentation/git-credential-cache.txt\n+++ b/Documentation/git-credential-cache.txt\n@@ -33,10 +33,13 @@ OPTIONS\n --socket <path>::\n \n \tUse `<path>` to contact a running cache daemon (or start a new\n-\tcache daemon if one is not started). Defaults to\n-\t`~/.git-credential-cache/socket`. If your home directory is on a\n-\tnetwork-mounted filesystem, you may need to change this to a\n-\tlocal filesystem. You must specify an absolute path.\n+\tcache daemon if one is not started).\n+\tDefaults to `$XDG_CACHE_HOME/git/credential/socket` unless\n+\t`~/.git-credential-cache/` exists in which case\n+\t`~/.git-credential-cache/socket` is used instead.\n+\tIf your home directory is on a network-mounted filesystem, you\n+\tmay need to change this to a local filesystem. You must specify\n+\tan absolute path.\n \n CONTROLLING THE DAEMON\n ----------------------\ndiff --git a/credential-cache.c b/credential-cache.c\nindex cc8a6ee19..1fd800775 100644\n--- a/credential-cache.c\n+++ b/credential-cache.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"credential.h\"\n+#include \"dir.h\"\n #include \"string-list.h\"\n #include \"parse-options.h\"\n #include \"unix-socket.h\"\n@@ -83,6 +84,18 @@ static void do_cache(const char *socket, const char *action, int timeout,\n \tstrbuf_release(&buf);\n }\n \n+static char *get_socket_path(void)\n+{\n+\tchar *old_credential_dir, *socket;\n+\told_credential_dir = expand_user_path(\"~/.git-credential-cache\");\n+\tif (old_credential_dir && directory_exists(old_credential_dir))\n+\t\tsocket = expand_user_path(\"~/.git-credential-cache/socket\");\n+\telse\n+\t\tsocket = xdg_cache_home(\"credential/socket\");\n+\tfree(old_credential_dir);\n+\treturn socket;\n+}\n+\n int cmd_main(int argc, const char **argv)\n {\n \tchar *socket_path = NULL;\n@@ -106,7 +119,7 @@ int cmd_main(int argc, const char **argv)\n \top = argv[0];\n \n \tif (!socket_path)\n-\t\tsocket_path = expand_user_path(\"~/.git-credential-cache/socket\");\n+\t\tsocket_path = get_socket_path();\n \tif (!socket_path)\n \t\tdie(\"unable to find a suitable socket path; use --socket\");\n \n-- \n2.11.0\n\n"},{"id":"314227","messageId":"xmqqlgs5cify.fsf@gitster.mtv.corp.google.com","threadId":"45367","inReplyTo":"20170316051827.97198-3-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH v4 2/4] dir: add directory_exists","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-16T16:09:05Z","receivedAt":"2017-03-16T16:09:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Devin Lehmacher <lehmacdj@gmail.com> writes:\n\n> +int directory_exists(const char *path)\n> +{\n> +\tstruct stat sb;\n> +\tint ret = lstat(path, &sb);\n> +\treturn ret == 0 && S_ISDIR(sb.st_mode);\n> +}\n\nI am not a great fan of using file_exists() [*1*] on anything other\nthan paths in the working tree (i.e. in preparation for checking\nthings out of or into the index), as paths inside .git/ and paths\noutside have different requirements.  One of the difference is if it\nmakes sense to use stat(2) or lstat(2) for a check like this\nfunction does.  For working tree entities, which file_exists() and\nfriends are designed for, we absolutely should use lstat(2).  The\n\"RelNotes\" symbolic link at the top level of the project must be\nknown as a symbolic link and a question \"is this a directory?\" on it\nmust be answered \"no\", for example.\n\nBut there is no fundamental reason ~/.git-credential-cache (or\nanything outside the working tree) must be S_ISDIR().  If the user\nwanted to have the real directory elsewhere and point at it with\na symbolic link ~/.git-credential-cache, we should allow it.\n\nIf we need a helper function to see if a path in the working tree is\na directory, adding this new helper function to dir.c (which is\nabout the paths in the working tree) and use lstat(2) in it is the\nright thing to do.  But I do not think it should be used to check if\n~/.git-credential-cache directory, which is not a filesystem entity\nin a working tree, exists.\n\nIOW, I do not think this patch helps the topic of this series.  Drop\nthis patch from the series and have a similar code (but use stat(2)\ninstead of lstat(2)) directly inside get_socket_path()'s in the next\npatch, perhaps?\n\n\n[Footnote]\n\n*1* ... and friends, like safe_create_leading_directories().\n\n"},{"id":"314228","messageId":"xmqqd1dhchwy.fsf@gitster.mtv.corp.google.com","threadId":"45367","inReplyTo":"20170316051827.97198-4-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH v4 3/4] credential-cache: use XDG_CACHE_HOME for socket","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-16T16:20:29Z","receivedAt":"2017-03-16T16:20:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Devin Lehmacher <lehmacdj@gmail.com> writes:\n\n> +\tIf your home directory is on a network-mounted filesystem, you\n> +\tmay need to change this to a local filesystem. You must specify\n> +\tan absolute path.\n\nNicely explained. \n\nIf a socket cannot be created in \"~/.git-credential-cache\", existing\nusers would have created a symbolic link that points at a local\ndirectory.  With XDG_CACHE_HOME mechanism, they would just set the\nvariable to directly point at a local directory and there is no need\nfor symlink trick, on the other hand.\n\nWhich points us back to the observation I made in my review on the\nprevious step.\n\n> +static char *get_socket_path(void)\n> +{\n> +\tchar *old_credential_dir, *socket;\n> +\told_credential_dir = expand_user_path(\"~/.git-credential-cache\");\n> +\tif (old_credential_dir && directory_exists(old_credential_dir))\n> +\t\tsocket = expand_user_path(\"~/.git-credential-cache/socket\");\n> +\telse\n> +\t\tsocket = xdg_cache_home(\"credential/socket\");\n> +\tfree(old_credential_dir);\n> +\treturn socket;\n> +}\n\nAs we do not want to use the dir.c::directory_exists(), which is\nmeant to be used for working tree files, we can do something like\nthis instead:\n\nstatic char *get_socket_path(void)\n{\n\tstruct stat st;\n\tchar *path;\n\n\tpath = expand_user_path(\"~/.git-credential-cache\");\n\tif (path && !stat(path, &st) && S_ISDIR(st.st_mode))) {\n\t\tfree(path);\n\t\tpath = expand_user_path(\"~/.git-credential-cache/socket\");\n\t} else {\n\t\tpath = xdg_cache_home(\"credential/socket\");\n\t}                \n\treturn path;\n}\n\nThe duplication of \"~/.git-credential-cache\" bothers me somewhat and\nperhaps people can suggest better ways to get rid of the dup.\n\nOther than that, makes sense to me.\n\nThanks.\n"},{"id":"314229","messageId":"xmqq8to5chh5.fsf@gitster.mtv.corp.google.com","threadId":"45367","inReplyTo":"20170316051827.97198-5-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH v4 4/4] credential-cache: add tests for XDG functionality","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-16T16:29:58Z","receivedAt":"2017-03-16T16:30:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Devin Lehmacher <lehmacdj@gmail.com> writes:\n\n> @@ -20,4 +21,67 @@ helper_test_timeout cache --timeout=1\n>  # our socket, leaving us with no way to access the daemon.\n>  git credential-cache exit\n>  \n> +# we need to use rm -rf here since sometimes the daemon hasn't finished\n> +# cleaning up after itself and rmdir fails\n\nHmmmm.  Peff, do you have ideas on better ways to do this (or\nexplanation why this is the best we could do)?\n\n> +test_expect_success 'credential-cache --socket option overrides default location' '\n> +\ttest_when_finished \"rm -rf \\\"$HOME\\\"/dir/\" &&\n> +\tcheck approve \"cache --socket \\\"$HOME/dir/socket\\\"\" <<-\\EOF &&\n> +\tprotocol=https\n> +\thost=example.com\n> +\tusername=store-user\n> +\tpassword=store-pass\n> +\tEOF\n> +\ttest -S \"$HOME/dir/socket\" &&\n> +\tgit credential-cache exit\n> +'\n> +\n> +XDG_CACHE_HOME=\"$HOME/xdg\"\n> +export XDG_CACHE_HOME\n> +# test behavior when XDG_CACHE_HOME is set\n> +helper_test cache\n> +\n> +test_expect_success \"use custom XDG_CACHE_HOME if set and default sockets are not created\" '\n> +\ttest -S \"$XDG_CACHE_HOME/git/credential/socket\" &&\n> +\ttest_path_is_missing \"$HOME/.git-credential-cache/socket\" &&\n> +\ttest_path_is_missing \"$HOME/.cache/git/credential/socket\" &&\n> +\tgit credential-cache exit\n> +'\n> +unset XDG_CACHE_HOME\n> +\n> +test_expect_success \"use custom XDG_CACHE_HOME even if xdg socket exists\" '\n> +\tcheck approve cache <<-\\EOF &&\n> +\tprotocol=https\n> +\thost=example.com\n> +\tusername=store-user\n> +\tpassword=store-pass\n> +\tEOF\n> +\ttest -S \"$HOME/.cache/git/credential/socket\" &&\n> +\tXDG_CACHE_HOME=\"$HOME/xdg\" &&\n> +\texport XDG_CACHE_HOME &&\n> +\tcheck approve cache <<-\\EOF &&\n> +\tprotocol=https\n> +\thost=example.com\n> +\tusername=store-user\n> +\tpassword=store-pass\n> +\tEOF\n> +\ttest -S \"$HOME/xdg/git/credential/socket\" &&\n> +\tgit credential-cache exit &&\n> +\tunset XDG_CACHE_HOME\n\nThis unset will not run if any of the above steps since it was set\nand exported fails.  It probably should be in test_when_finished and\nshould use safe_unset shell function instead.\n\n> +'\n> +\n> +# we need to use rm -rf here since sometimes the daemon hasn't finished\n> +# cleaning up after itself and rmdir fails\n> +test_expect_success 'use user socket if user directory exists' '\n> +\ttest_when_finished \"rm -rf \\\"$HOME/.git-credential-cache/\\\"\" &&\n> +\tmkdir -p -m 700 \"$HOME/.git-credential-cache/\" &&\n> +\tcheck approve cache <<-\\EOF &&\n> +\tprotocol=https\n> +\thost=example.com\n> +\tusername=store-user\n> +\tpassword=store-pass\n> +\tEOF\n> +\ttest -S \"$HOME/.git-credential-cache/socket\" &&\n\nWe should also test that the XDG location is not touched at the same\ntime that the traditional directory was used for the socket.\n\n> +\tgit credential-cache exit\n> +'\n\nThis last test should be replicated to also check the case where we\nhave a symbolic link at ~/.git-credential-cache that points at a\ndirectory.\n\n>  test_done\n\nThanks.\n"},{"id":"314235","messageId":"20170316175857.77tftld54gqqm22c@sigill.intra.peff.net","threadId":"45367","inReplyTo":"xmqq8to5chh5.fsf@gitster.mtv.corp.google.com","subject":"Re: [GSoC][PATCH v4 4/4] credential-cache: add tests for XDG functionality","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-03-16T17:58:57Z","receivedAt":"2017-03-16T17:59:07Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 16, 2017 at 09:29:58AM -0700, Junio C Hamano wrote:\n\n> Devin Lehmacher <lehmacdj@gmail.com> writes:\n> \n> > @@ -20,4 +21,67 @@ helper_test_timeout cache --timeout=1\n> >  # our socket, leaving us with no way to access the daemon.\n> >  git credential-cache exit\n> >  \n> > +# we need to use rm -rf here since sometimes the daemon hasn't finished\n> > +# cleaning up after itself and rmdir fails\n> \n> Hmmmm.  Peff, do you have ideas on better ways to do this (or\n> explanation why this is the best we could do)?\n\nIf you call \"git credential-cache exit\", that should be deterministic.\nThe client program won't exit until the other side closes the\ndescriptor, which it won't do until it has cleaned up the socket. See\nthe comment at line 130 of credential-cache--daemon.c.\n\nSo here:\n\n> > +test_expect_success 'credential-cache --socket option overrides default location' '\n> > +\ttest_when_finished \"rm -rf \\\"$HOME\\\"/dir/\" &&\n> > +\tcheck approve \"cache --socket \\\"$HOME/dir/socket\\\"\" <<-\\EOF &&\n> > +\tprotocol=https\n> > +\thost=example.com\n> > +\tusername=store-user\n> > +\tpassword=store-pass\n> > +\tEOF\n> > +\ttest -S \"$HOME/dir/socket\" &&\n> > +\tgit credential-cache exit\n> > +'\n\nThis is almost right, except:\n\n  - the \"exit\" needs to be told which socket to use\n\n  - we should do the \"exit\" even when the test fails early (so in\n    test_when_finished)\n\n  - the test_when_finished block will interpolate $HOME when setting up\n    the block, which will break if it contains double-quotes or other\n    special characters. It should use \\$HOME.\n\n    I suspect the \"check\" invocation needs to do so as well, though it\n    is even trickier (we shove it into a single-quoted \"-c\" argument).\n\n    I think you could get by in both cases with relative paths.\n\nSo all together, probably:\n\n  test_when_finished \"\n\tgit credential-cache --socket dir/socket &&\n\trmdir dir\n  \" &&\n  check approve \"cache --socket dir/socket\" <<-\\EOF &&\n  ...\n  EOF\n  test -S dir/socket\n\nThe final \"test -S\" should be OK in practice. We're assuming that the\ncache-daemon is still running, but it has a 900 second timeout by\ndefault (and besides, all the other tests have exact same race).\n\n-Peff\n"},{"id":"314236","messageId":"20170316180227.2ka4fsyigwr33cks@sigill.intra.peff.net","threadId":"45367","inReplyTo":"xmqqd1dhchwy.fsf@gitster.mtv.corp.google.com","subject":"Re: [GSoC][PATCH v4 3/4] credential-cache: use XDG_CACHE_HOME for socket","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-03-16T18:02:27Z","receivedAt":"2017-03-16T18:02:51Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Mar 16, 2017 at 09:20:29AM -0700, Junio C Hamano wrote:\n\n> static char *get_socket_path(void)\n> {\n> \tstruct stat st;\n> \tchar *path;\n> \n> \tpath = expand_user_path(\"~/.git-credential-cache\");\n> \tif (path && !stat(path, &st) && S_ISDIR(st.st_mode))) {\n> \t\tfree(path);\n> \t\tpath = expand_user_path(\"~/.git-credential-cache/socket\");\n> \t} else {\n> \t\tpath = xdg_cache_home(\"credential/socket\");\n> \t}                \n> \treturn path;\n> }\n> \n> The duplication of \"~/.git-credential-cache\" bothers me somewhat and\n> perhaps people can suggest better ways to get rid of the dup.\n\nMaybe:\n\n  path = expand_user_path(\"~/.git-credential-cache\");\n  if (path && !stat(path, &st) && S_ISDIR(st.st_mode))) {\n\tchar *new_path = xstrfmt(\"%s/socket\", path);\n\tfree(path);\n\tpath = new_path;\n  } else ...\n\n-Peff\n"},{"id":"314237","messageId":"xmqqziglaxj4.fsf@gitster.mtv.corp.google.com","threadId":"45367","inReplyTo":"xmqqlgs5cify.fsf@gitster.mtv.corp.google.com","subject":"Re: [GSoC][PATCH v4 2/4] dir: add directory_exists","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-16T18:26:07Z","receivedAt":"2017-03-16T18:26:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Devin Lehmacher <lehmacdj@gmail.com> writes:\n>\n>> +int directory_exists(const char *path)\n>> +{\n>> +\tstruct stat sb;\n>> +\tint ret = lstat(path, &sb);\n>> +\treturn ret == 0 && S_ISDIR(sb.st_mode);\n>> +}\n>\n> I am not a great fan of using file_exists() [*1*] on anything other\n> than paths in the working tree (i.e. in preparation for checking\n> things out of or into the index), as ...\n> ...\n> [Footnote]\n>\n> *1* ... and friends, like safe_create_leading_directories().\n\nI actually got things mixed up.  safe-create-leading-directories is\nto be used only for paths inside .git/ (i.e. not for working tree\nfiles, but for things like \".git/refs/heads/foo\" when creating a\nbranch called foo/bar).\n\n"},{"id":"314298","messageId":"20170317025315.84548-1-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170316051827.97198-5-lehmacdj@gmail.com","subject":"[GSoC][PATCH v5 1/3] path.c: add xdg_cache_home","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-17T02:53:13Z","receivedAt":"2017-03-17T02:54:19Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"We already have xdg_config_home to format paths relative to\nXDG_CONFIG_HOME. Let's provide a similar function xdg_cache_home to do\nthe same for paths relative to XDG_CACHE_HOME.\n\nSigned-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n cache.h |  7 +++++++\n path.c  | 15 +++++++++++++++\n 2 files changed, 22 insertions(+)\n\ndiff --git a/cache.h b/cache.h\nindex c95826971..66761bc56 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1169,6 +1169,13 @@ extern int is_ntfs_dotgit(const char *name);\n  */\n extern char *xdg_config_home(const char *filename);\n \n+/**\n+ * Return a newly allocated string with the evaluation of\n+ * \"$XDG_CACHE_HOME/git/$filename\" if $XDG_CACHE_HOME is non-empty, otherwise\n+ * \"$HOME/.cache/git/$filename\". Return NULL upon error.\n+ */\n+extern char *xdg_cache_home(const char *filename);\n+\n /* object replacement */\n #define LOOKUP_REPLACE_OBJECT 1\n #define LOOKUP_UNKNOWN_OBJECT 2\ndiff --git a/path.c b/path.c\nindex efcedafba..22248436b 100644\n--- a/path.c\n+++ b/path.c\n@@ -1272,6 +1272,21 @@ char *xdg_config_home(const char *filename)\n \treturn NULL;\n }\n \n+char *xdg_cache_home(const char *filename)\n+{\n+\tconst char *home, *cache_home;\n+\n+\tassert(filename);\n+\tcache_home = getenv(\"XDG_CACHE_HOME\");\n+\tif (cache_home && *cache_home)\n+\t\treturn mkpathdup(\"%s/git/%s\", cache_home, filename);\n+\n+\thome = getenv(\"HOME\");\n+\tif (home)\n+\t\treturn mkpathdup(\"%s/.cache/git/%s\", home, filename);\n+\treturn NULL;\n+}\n+\n GIT_PATH_FUNC(git_path_cherry_pick_head, \"CHERRY_PICK_HEAD\")\n GIT_PATH_FUNC(git_path_revert_head, \"REVERT_HEAD\")\n GIT_PATH_FUNC(git_path_squash_msg, \"SQUASH_MSG\")\n-- \n2.11.0\n\n"},{"id":"314299","messageId":"20170317025315.84548-2-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170317025315.84548-1-lehmacdj@gmail.com","subject":"[GSoC][PATCH v5 2/3] credential-cache: use XDG_CACHE_HOME for socket","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-17T02:53:14Z","receivedAt":"2017-03-17T02:54:28Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"Make git-credential-cache follow the XDG base path specification by\ndefault. This increases consistency with other applications and helps\nkeep clutter out of users' home directories.\n\nCheck the old socket location, ~/.git-credential-cache/, and use\n~/.git-credential-cache/socket if that directory exists rather than\nforcing users who have used `git credential-cache` before to migrate to\nthe new XDG compliant location.\nOtherwise use the socket $XDG_CACHE_HOME/git/credential/socket following\nXDG base path specification. Use the subdirectory credential/ in case\nother files are cached under $XDG_CACHE_HOME/git/ in the future and to\nmake the socket's purpose clear.\n\nSigned-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n Documentation/git-credential-cache.txt | 11 +++++++----\n credential-cache.c                     | 15 ++++++++++++++-\n 2 files changed, 21 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-credential-cache.txt b/Documentation/git-credential-cache.txt\nindex 96208f822..2b8582639 100644\n--- a/Documentation/git-credential-cache.txt\n+++ b/Documentation/git-credential-cache.txt\n@@ -33,10 +33,13 @@ OPTIONS\n --socket <path>::\n \n \tUse `<path>` to contact a running cache daemon (or start a new\n-\tcache daemon if one is not started). Defaults to\n-\t`~/.git-credential-cache/socket`. If your home directory is on a\n-\tnetwork-mounted filesystem, you may need to change this to a\n-\tlocal filesystem. You must specify an absolute path.\n+\tcache daemon if one is not started).\n+\tDefaults to `$XDG_CACHE_HOME/git/credential/socket` unless\n+\t`~/.git-credential-cache/` exists in which case\n+\t`~/.git-credential-cache/socket` is used instead.\n+\tIf your home directory is on a network-mounted filesystem, you\n+\tmay need to change this to a local filesystem. You must specify\n+\tan absolute path.\n \n CONTROLLING THE DAEMON\n ----------------------\ndiff --git a/credential-cache.c b/credential-cache.c\nindex cc8a6ee19..3cbd42001 100644\n--- a/credential-cache.c\n+++ b/credential-cache.c\n@@ -83,6 +83,19 @@ static void do_cache(const char *socket, const char *action, int timeout,\n \tstrbuf_release(&buf);\n }\n \n+static char *get_socket_path(void)\n+{\n+\tstruct stat sb;\n+\tchar *old_dir, *socket;\n+\told_dir = expand_user_path(\"~/.git-credential-cache\");\n+\tif (old_dir && !stat(old_dir, &sb) && S_ISDIR(sb.st_mode))\n+\t\tsocket = xstrfmt(\"%s/socket\", old_dir);\n+\telse\n+\t\tsocket = xdg_cache_home(\"credential/socket\");\n+\tfree(old_dir);\n+\treturn socket;\n+}\n+\n int cmd_main(int argc, const char **argv)\n {\n \tchar *socket_path = NULL;\n@@ -106,7 +119,7 @@ int cmd_main(int argc, const char **argv)\n \top = argv[0];\n \n \tif (!socket_path)\n-\t\tsocket_path = expand_user_path(\"~/.git-credential-cache/socket\");\n+\t\tsocket_path = get_socket_path();\n \tif (!socket_path)\n \t\tdie(\"unable to find a suitable socket path; use --socket\");\n \n-- \n2.11.0\n\n"},{"id":"314300","messageId":"20170317025315.84548-3-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170317025315.84548-1-lehmacdj@gmail.com","subject":"[GSoC][PATCH v5 3/3] credential-cache: add tests for XDG functionality","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-17T02:53:15Z","receivedAt":"2017-03-17T02:54:31Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"Signed-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n t/t0301-credential-cache.sh | 94 +++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 94 insertions(+)\n\ndiff --git a/t/t0301-credential-cache.sh b/t/t0301-credential-cache.sh\nindex 82c841121..82c4dfa07 100755\n--- a/t/t0301-credential-cache.sh\n+++ b/t/t0301-credential-cache.sh\n@@ -12,7 +12,101 @@ test -z \"$NO_UNIX_SOCKETS\" || {\n # don't leave a stale daemon running\n trap 'code=$?; git credential-cache exit; (exit $code); die' EXIT\n \n+# test that the daemon works with no special setup\n helper_test cache\n+\n+test_expect_success 'socket defaults to ~/.cache/git/credential/socket' '\n+\ttest_when_finished \"\n+\t\tgit credential-cache exit &&\n+\t\trmdir -p .cache/git/credential/\n+\t\" &&\n+\ttest_path_is_missing \"$HOME/.git-credential-cache\" &&\n+\ttest -S \"$HOME/.cache/git/credential/socket\"\n+'\n+\n+XDG_CACHE_HOME=\"$HOME/xdg\"\n+export XDG_CACHE_HOME\n+# test behavior when XDG_CACHE_HOME is set\n+helper_test cache\n+\n+test_expect_success \"use custom XDG_CACHE_HOME if set and default sockets are not created\" '\n+\ttest_when_finished \"git credential-cache exit\" &&\n+\ttest -S \"$XDG_CACHE_HOME/git/credential/socket\" &&\n+\ttest_path_is_missing \"$HOME/.git-credential-cache/socket\" &&\n+\ttest_path_is_missing \"$HOME/.cache/git/credential/socket\"\n+'\n+unset XDG_CACHE_HOME\n+\n+test_expect_success 'credential-cache --socket option overrides default location' '\n+\ttest_when_finished \"\n+\t\tgit credential-cache exit --socket \\\"\\$HOME/dir/socket\\\" &&\n+\t\trmdir \\\"\\$HOME/dir\\\"\n+\t\" &&\n+\tcheck approve \"cache --socket \\\"\\$HOME/dir/socket\\\"\" <<-\\EOF &&\n+\tprotocol=https\n+\thost=example.com\n+\tusername=store-user\n+\tpassword=store-pass\n+\tEOF\n+\ttest -S \"$HOME/dir/socket\"\n+'\n+\n+test_expect_success \"use custom XDG_CACHE_HOME even if xdg socket exists\" '\n+\ttest_when_finished \"\n+\t\tgit credential-cache exit &&\n+\t\tsane_unset XDG_CACHE_HOME\n+\t\" &&\n+\tcheck approve cache <<-\\EOF &&\n+\tprotocol=https\n+\thost=example.com\n+\tusername=store-user\n+\tpassword=store-pass\n+\tEOF\n+\tfind . &&\n+\ttest -S \"$HOME/.cache/git/credential/socket\" &&\n+\tXDG_CACHE_HOME=\"$HOME/xdg\" &&\n+\texport XDG_CACHE_HOME &&\n+\tcheck approve cache <<-\\EOF &&\n+\tprotocol=https\n+\thost=example.com\n+\tusername=store-user\n+\tpassword=store-pass\n+\tEOF\n+\ttest -S \"$XDG_CACHE_HOME/git/credential/socket\"\n+'\n+\n+test_expect_success 'use user socket if user directory exists' '\n+\ttest_when_finished \"\n+\t\tgit credential-cache exit &&\n+\t\trmdir \\\"\\$HOME/.git-credential-cache/\\\"\n+\t\" &&\n+\tmkdir -p -m 700 \"$HOME/.git-credential-cache/\" &&\n+\tcheck approve cache <<-\\EOF &&\n+\tprotocol=https\n+\thost=example.com\n+\tusername=store-user\n+\tpassword=store-pass\n+\tEOF\n+\ttest -S \"$HOME/.git-credential-cache/socket\"\n+'\n+\n+test_expect_success 'use user socket if user directory is a symlink to a directory' '\n+\ttest_when_finished \"\n+\t\tgit credential-cache exit &&\n+\t\trmdir \\\"\\$HOME/dir/\\\" &&\n+\t\trm \\\"\\$HOME/.git-credential-cache\\\"\n+\t\" &&\n+\tmkdir -p -m 700 \"$HOME/dir/\" &&\n+\tln -s \"$HOME/dir\" \"$HOME/.git-credential-cache\" &&\n+\tcheck approve cache <<-\\EOF &&\n+\tprotocol=https\n+\thost=example.com\n+\tusername=store-user\n+\tpassword=store-pass\n+\tEOF\n+\ttest -S \"$HOME/.git-credential-cache/socket\"\n+'\n+\n helper_test_timeout cache --timeout=1\n \n # we can't rely on our \"trap\" above working after test_done,\n-- \n2.11.0\n\n"},{"id":"314309","messageId":"xmqq37eca2e0.fsf@gitster.mtv.corp.google.com","threadId":"45367","inReplyTo":"20170317025315.84548-3-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH v5 3/3] credential-cache: add tests for XDG functionality","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-03-17T05:38:47Z","receivedAt":"2017-03-17T05:38:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Devin Lehmacher <lehmacdj@gmail.com> writes:\n\n> +# test that the daemon works with no special setup\n>  helper_test cache\n> +\n> +test_expect_success 'socket defaults to ~/.cache/git/credential/socket' '\n> +\ttest_when_finished \"\n> +\t\tgit credential-cache exit &&\n> +\t\trmdir -p .cache/git/credential/\n> +\t\" &&\n> +\ttest_path_is_missing \"$HOME/.git-credential-cache\" &&\n> +\ttest -S \"$HOME/.cache/git/credential/socket\"\n> +'\n\nOK, the clean-up looks quite sensible.\n\n> +test_expect_success \"use custom XDG_CACHE_HOME even if xdg socket exists\" '\n> +...\n> +\tpassword=store-pass\n> +\tEOF\n> +\tfind . &&\n\nA leftover from a debugging session?  If so remove the \"find\" line.\n\n> +\ttest -S \"$HOME/.cache/git/credential/socket\" &&\n> +\tXDG_CACHE_HOME=\"$HOME/xdg\" &&\n> ...\n> +'\n\n> +test_expect_success 'use user socket if user directory is a symlink to a directory' '\n\nI think anybody without NO_UNIX_SOCKETS is practically capable of\ndoing a symbolic link, but still it is a good idea to protect this\none behind the SYMLINKS prerequisite, i.e.\n\n\ttest_expect_success SYMLINKS 'use ~/.git-credential-cache that is a symlink' '\n\t\t...\n\n> +\ttest_when_finished \"\n> +...\n> +'\n> +\n>  helper_test_timeout cache --timeout=1\n>  \n>  # we can't rely on our \"trap\" above working after test_done,\n\nThanks.\n"},{"id":"314327","messageId":"20170317123634.10863-2-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170317123634.10863-1-lehmacdj@gmail.com","subject":"[GSoC][PATCH v6 2/3] credential-cache: use XDG_CACHE_HOME for socket","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-17T12:36:33Z","receivedAt":"2017-03-17T12:37:02Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"Make git-credential-cache follow the XDG base path specification by\ndefault. This increases consistency with other applications and helps\nkeep clutter out of users' home directories.\n\nCheck the old socket location, ~/.git-credential-cache/, and use\n~/.git-credential-cache/socket if that directory exists rather than\nforcing users who have used `git credential-cache` before to migrate to\nthe new XDG compliant location.\nOtherwise use the socket $XDG_CACHE_HOME/git/credential/socket following\nXDG base path specification. Use the subdirectory credential/ in case\nother files are cached under $XDG_CACHE_HOME/git/ in the future and to\nmake the socket's purpose clear.\n\nSigned-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n Documentation/git-credential-cache.txt | 11 +++++++----\n credential-cache.c                     | 15 ++++++++++++++-\n 2 files changed, 21 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-credential-cache.txt b/Documentation/git-credential-cache.txt\nindex 96208f822..2b8582639 100644\n--- a/Documentation/git-credential-cache.txt\n+++ b/Documentation/git-credential-cache.txt\n@@ -33,10 +33,13 @@ OPTIONS\n --socket <path>::\n \n \tUse `<path>` to contact a running cache daemon (or start a new\n-\tcache daemon if one is not started). Defaults to\n-\t`~/.git-credential-cache/socket`. If your home directory is on a\n-\tnetwork-mounted filesystem, you may need to change this to a\n-\tlocal filesystem. You must specify an absolute path.\n+\tcache daemon if one is not started).\n+\tDefaults to `$XDG_CACHE_HOME/git/credential/socket` unless\n+\t`~/.git-credential-cache/` exists in which case\n+\t`~/.git-credential-cache/socket` is used instead.\n+\tIf your home directory is on a network-mounted filesystem, you\n+\tmay need to change this to a local filesystem. You must specify\n+\tan absolute path.\n \n CONTROLLING THE DAEMON\n ----------------------\ndiff --git a/credential-cache.c b/credential-cache.c\nindex cc8a6ee19..3cbd42001 100644\n--- a/credential-cache.c\n+++ b/credential-cache.c\n@@ -83,6 +83,19 @@ static void do_cache(const char *socket, const char *action, int timeout,\n \tstrbuf_release(&buf);\n }\n \n+static char *get_socket_path(void)\n+{\n+\tstruct stat sb;\n+\tchar *old_dir, *socket;\n+\told_dir = expand_user_path(\"~/.git-credential-cache\");\n+\tif (old_dir && !stat(old_dir, &sb) && S_ISDIR(sb.st_mode))\n+\t\tsocket = xstrfmt(\"%s/socket\", old_dir);\n+\telse\n+\t\tsocket = xdg_cache_home(\"credential/socket\");\n+\tfree(old_dir);\n+\treturn socket;\n+}\n+\n int cmd_main(int argc, const char **argv)\n {\n \tchar *socket_path = NULL;\n@@ -106,7 +119,7 @@ int cmd_main(int argc, const char **argv)\n \top = argv[0];\n \n \tif (!socket_path)\n-\t\tsocket_path = expand_user_path(\"~/.git-credential-cache/socket\");\n+\t\tsocket_path = get_socket_path();\n \tif (!socket_path)\n \t\tdie(\"unable to find a suitable socket path; use --socket\");\n \n-- \n2.11.0\n\n"},{"id":"314328","messageId":"20170317123634.10863-1-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170317025315.84548-3-lehmacdj@gmail.com","subject":"[GSoC][PATCH v6 1/3] path.c: add xdg_cache_home","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-17T12:36:32Z","receivedAt":"2017-03-17T12:37:21Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"We already have xdg_config_home to format paths relative to\nXDG_CONFIG_HOME. Let's provide a similar function xdg_cache_home to do\nthe same for paths relative to XDG_CACHE_HOME.\n\nSigned-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n cache.h |  7 +++++++\n path.c  | 15 +++++++++++++++\n 2 files changed, 22 insertions(+)\n\ndiff --git a/cache.h b/cache.h\nindex c95826971..66761bc56 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1169,6 +1169,13 @@ extern int is_ntfs_dotgit(const char *name);\n  */\n extern char *xdg_config_home(const char *filename);\n \n+/**\n+ * Return a newly allocated string with the evaluation of\n+ * \"$XDG_CACHE_HOME/git/$filename\" if $XDG_CACHE_HOME is non-empty, otherwise\n+ * \"$HOME/.cache/git/$filename\". Return NULL upon error.\n+ */\n+extern char *xdg_cache_home(const char *filename);\n+\n /* object replacement */\n #define LOOKUP_REPLACE_OBJECT 1\n #define LOOKUP_UNKNOWN_OBJECT 2\ndiff --git a/path.c b/path.c\nindex efcedafba..22248436b 100644\n--- a/path.c\n+++ b/path.c\n@@ -1272,6 +1272,21 @@ char *xdg_config_home(const char *filename)\n \treturn NULL;\n }\n \n+char *xdg_cache_home(const char *filename)\n+{\n+\tconst char *home, *cache_home;\n+\n+\tassert(filename);\n+\tcache_home = getenv(\"XDG_CACHE_HOME\");\n+\tif (cache_home && *cache_home)\n+\t\treturn mkpathdup(\"%s/git/%s\", cache_home, filename);\n+\n+\thome = getenv(\"HOME\");\n+\tif (home)\n+\t\treturn mkpathdup(\"%s/.cache/git/%s\", home, filename);\n+\treturn NULL;\n+}\n+\n GIT_PATH_FUNC(git_path_cherry_pick_head, \"CHERRY_PICK_HEAD\")\n GIT_PATH_FUNC(git_path_revert_head, \"REVERT_HEAD\")\n GIT_PATH_FUNC(git_path_squash_msg, \"SQUASH_MSG\")\n-- \n2.11.0\n\n"},{"id":"314329","messageId":"20170317123634.10863-3-lehmacdj@gmail.com","threadId":"45367","inReplyTo":"20170317123634.10863-1-lehmacdj@gmail.com","subject":"[GSoC][PATCH v6 3/3] credential-cache: add tests for XDG functionality","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-17T12:36:34Z","receivedAt":"2017-03-17T12:37:22Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"Signed-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n---\n t/t0301-credential-cache.sh | 93 +++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 93 insertions(+)\n\ndiff --git a/t/t0301-credential-cache.sh b/t/t0301-credential-cache.sh\nindex 82c841121..fd92533ac 100755\n--- a/t/t0301-credential-cache.sh\n+++ b/t/t0301-credential-cache.sh\n@@ -12,7 +12,100 @@ test -z \"$NO_UNIX_SOCKETS\" || {\n # don't leave a stale daemon running\n trap 'code=$?; git credential-cache exit; (exit $code); die' EXIT\n \n+# test that the daemon works with no special setup\n helper_test cache\n+\n+test_expect_success 'socket defaults to ~/.cache/git/credential/socket' '\n+\ttest_when_finished \"\n+\t\tgit credential-cache exit &&\n+\t\trmdir -p .cache/git/credential/\n+\t\" &&\n+\ttest_path_is_missing \"$HOME/.git-credential-cache\" &&\n+\ttest -S \"$HOME/.cache/git/credential/socket\"\n+'\n+\n+XDG_CACHE_HOME=\"$HOME/xdg\"\n+export XDG_CACHE_HOME\n+# test behavior when XDG_CACHE_HOME is set\n+helper_test cache\n+\n+test_expect_success \"use custom XDG_CACHE_HOME if set and default sockets are not created\" '\n+\ttest_when_finished \"git credential-cache exit\" &&\n+\ttest -S \"$XDG_CACHE_HOME/git/credential/socket\" &&\n+\ttest_path_is_missing \"$HOME/.git-credential-cache/socket\" &&\n+\ttest_path_is_missing \"$HOME/.cache/git/credential/socket\"\n+'\n+unset XDG_CACHE_HOME\n+\n+test_expect_success 'credential-cache --socket option overrides default location' '\n+\ttest_when_finished \"\n+\t\tgit credential-cache exit --socket \\\"\\$HOME/dir/socket\\\" &&\n+\t\trmdir \\\"\\$HOME/dir\\\"\n+\t\" &&\n+\tcheck approve \"cache --socket \\\"\\$HOME/dir/socket\\\"\" <<-\\EOF &&\n+\tprotocol=https\n+\thost=example.com\n+\tusername=store-user\n+\tpassword=store-pass\n+\tEOF\n+\ttest -S \"$HOME/dir/socket\"\n+'\n+\n+test_expect_success \"use custom XDG_CACHE_HOME even if xdg socket exists\" '\n+\ttest_when_finished \"\n+\t\tgit credential-cache exit &&\n+\t\tsane_unset XDG_CACHE_HOME\n+\t\" &&\n+\tcheck approve cache <<-\\EOF &&\n+\tprotocol=https\n+\thost=example.com\n+\tusername=store-user\n+\tpassword=store-pass\n+\tEOF\n+\ttest -S \"$HOME/.cache/git/credential/socket\" &&\n+\tXDG_CACHE_HOME=\"$HOME/xdg\" &&\n+\texport XDG_CACHE_HOME &&\n+\tcheck approve cache <<-\\EOF &&\n+\tprotocol=https\n+\thost=example.com\n+\tusername=store-user\n+\tpassword=store-pass\n+\tEOF\n+\ttest -S \"$XDG_CACHE_HOME/git/credential/socket\"\n+'\n+\n+test_expect_success 'use user socket if user directory exists' '\n+\ttest_when_finished \"\n+\t\tgit credential-cache exit &&\n+\t\trmdir \\\"\\$HOME/.git-credential-cache/\\\"\n+\t\" &&\n+\tmkdir -p -m 700 \"$HOME/.git-credential-cache/\" &&\n+\tcheck approve cache <<-\\EOF &&\n+\tprotocol=https\n+\thost=example.com\n+\tusername=store-user\n+\tpassword=store-pass\n+\tEOF\n+\ttest -S \"$HOME/.git-credential-cache/socket\"\n+'\n+\n+test_expect_success SYMLINKS 'use user socket if user directory is a symlink to a directory' '\n+\ttest_when_finished \"\n+\t\tgit credential-cache exit &&\n+\t\trmdir \\\"\\$HOME/dir/\\\" &&\n+\t\trm \\\"\\$HOME/.git-credential-cache\\\"\n+\t\" &&\n+\tmkdir -p -m 700 \"$HOME/dir/\" &&\n+\tln -s \"$HOME/dir\" \"$HOME/.git-credential-cache\" &&\n+\tcheck approve cache <<-\\EOF &&\n+\tprotocol=https\n+\thost=example.com\n+\tusername=store-user\n+\tpassword=store-pass\n+\tEOF\n+\ttest -S \"$HOME/.git-credential-cache/socket\"\n+'\n+\n helper_test_timeout cache --timeout=1\n \n # we can't rely on our \"trap\" above working after test_done,\n-- \n2.11.0\n\n"},{"id":"314331","messageId":"20170317134203.6hqzfblyse2jrzdp@sigill.intra.peff.net","threadId":"45367","inReplyTo":"20170317123634.10863-2-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH v6 2/3] credential-cache: use XDG_CACHE_HOME for socket","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-03-17T13:42:03Z","receivedAt":"2017-03-17T13:44:15Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Mar 17, 2017 at 08:36:33AM -0400, Devin Lehmacher wrote:\n\n> Make git-credential-cache follow the XDG base path specification by\n> default. This increases consistency with other applications and helps\n> keep clutter out of users' home directories.\n> \n> Check the old socket location, ~/.git-credential-cache/, and use\n> ~/.git-credential-cache/socket if that directory exists rather than\n> forcing users who have used `git credential-cache` before to migrate to\n> the new XDG compliant location.\n> Otherwise use the socket $XDG_CACHE_HOME/git/credential/socket following\n> XDG base path specification. Use the subdirectory credential/ in case\n> other files are cached under $XDG_CACHE_HOME/git/ in the future and to\n> make the socket's purpose clear.\n\nMakes sense.\n\n> +static char *get_socket_path(void)\n> +{\n> +\tstruct stat sb;\n> +\tchar *old_dir, *socket;\n> +\told_dir = expand_user_path(\"~/.git-credential-cache\");\n> +\tif (old_dir && !stat(old_dir, &sb) && S_ISDIR(sb.st_mode))\n> +\t\tsocket = xstrfmt(\"%s/socket\", old_dir);\n> +\telse\n> +\t\tsocket = xdg_cache_home(\"credential/socket\");\n> +\tfree(old_dir);\n> +\treturn socket;\n> +}\n\nThe implementation looks nice and clean.\n\n-Peff\n"},{"id":"314332","messageId":"20170317134229.qlrz4fqotirb5len@sigill.intra.peff.net","threadId":"45367","inReplyTo":"20170317123634.10863-1-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH v6 1/3] path.c: add xdg_cache_home","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-03-17T13:42:29Z","receivedAt":"2017-03-17T13:44:20Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Mar 17, 2017 at 08:36:32AM -0400, Devin Lehmacher wrote:\n\n> We already have xdg_config_home to format paths relative to\n> XDG_CONFIG_HOME. Let's provide a similar function xdg_cache_home to do\n> the same for paths relative to XDG_CACHE_HOME.\n> \n> Signed-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n\nLooks obviously correct. The whole series looks good to me.\n\n-Peff\n"},{"id":"314333","messageId":"20170317133817.nt6s7viputaeh2cy@sigill.intra.peff.net","threadId":"45367","inReplyTo":"20170317123634.10863-3-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH v6 3/3] credential-cache: add tests for XDG functionality","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-03-17T13:38:17Z","receivedAt":"2017-03-17T13:45:06Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Mar 17, 2017 at 08:36:34AM -0400, Devin Lehmacher wrote:\n\n> +test_expect_success 'credential-cache --socket option overrides default location' '\n> +\ttest_when_finished \"\n> +\t\tgit credential-cache exit --socket \\\"\\$HOME/dir/socket\\\" &&\n> +\t\trmdir \\\"\\$HOME/dir\\\"\n> +\t\" &&\n> +\tcheck approve \"cache --socket \\\"\\$HOME/dir/socket\\\"\" <<-\\EOF &&\n\nI wondered how this one got through the quoting/eval mess of the\n\"check()\" function. But it works because we pass a raw unexpanded $HOME\ninto the config variable, and the credential subsystem then runs \"cache\n--socket ...\" using a shell, which is where it gets expanded.\n\n> +\tmkdir -p -m 700 \"$HOME/.git-credential-cache/\" &&\n\nThis is our first use of \"mkdir -m\". It's in POSIX, so it should\nprobably be fine. I'm not sure if platforms without POSIXPERM would\ncomplain, but I think in practice anything with unix sockets will handle\nit just fine.\n\nThe rest of the tests look OK to me.\n\n-Peff\n"},{"id":"314343","messageId":"2952fc80-a313-4193-64b6-072b7ccdef4f@ramsayjones.plus.com","threadId":"45367","inReplyTo":"20170317025315.84548-2-lehmacdj@gmail.com","subject":"Re: [GSoC][PATCH v5 2/3] credential-cache: use XDG_CACHE_HOME for socket","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2017-03-17T16:12:33Z","receivedAt":"2017-03-17T16:13:08Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 17/03/17 02:53, Devin Lehmacher wrote:\n> Make git-credential-cache follow the XDG base path specification by\n> default. This increases consistency with other applications and helps\n> keep clutter out of users' home directories.\n> \n> Check the old socket location, ~/.git-credential-cache/, and use\n> ~/.git-credential-cache/socket if that directory exists rather than\n> forcing users who have used `git credential-cache` before to migrate to\n> the new XDG compliant location.\n> Otherwise use the socket $XDG_CACHE_HOME/git/credential/socket following\n> XDG base path specification. Use the subdirectory credential/ in case\n> other files are cached under $XDG_CACHE_HOME/git/ in the future and to\n> make the socket's purpose clear.\n> \n> Signed-off-by: Devin Lehmacher <lehmacdj@gmail.com>\n> ---\n>  Documentation/git-credential-cache.txt | 11 +++++++----\n>  credential-cache.c                     | 15 ++++++++++++++-\n>  2 files changed, 21 insertions(+), 5 deletions(-)\n> \n> diff --git a/Documentation/git-credential-cache.txt b/Documentation/git-credential-cache.txt\n> index 96208f822..2b8582639 100644\n> --- a/Documentation/git-credential-cache.txt\n> +++ b/Documentation/git-credential-cache.txt\n> @@ -33,10 +33,13 @@ OPTIONS\n>  --socket <path>::\n>  \n>  \tUse `<path>` to contact a running cache daemon (or start a new\n> -\tcache daemon if one is not started). Defaults to\n> -\t`~/.git-credential-cache/socket`. If your home directory is on a\n> -\tnetwork-mounted filesystem, you may need to change this to a\n> -\tlocal filesystem. You must specify an absolute path.\n> +\tcache daemon if one is not started).\n> +\tDefaults to `$XDG_CACHE_HOME/git/credential/socket` unless\n\nor $HOME/.cache/git/credential/socket if $XDG_CACHE_HOME is not set.\nI don't have a good suggestion to re-word this paragraph. (I just\nspent ten minutes trying!).\n\nHmm, git-credential-store doesn't mention the $HOME/.config/git/credentials\noutside of the files section. (In particular, not as part of the --file\noption description).\n\n> +\t`~/.git-credential-cache/` exists in which case\n> +\t`~/.git-credential-cache/socket` is used instead.\n> +\tIf your home directory is on a network-mounted filesystem, you\n> +\tmay need to change this to a local filesystem. You must specify\n> +\tan absolute path.\n\nATB,\nRamsay Jones\n\n"},{"id":"314383","messageId":"2E94DDE8-FC43-4243-9E61-1498E1993467@gmail.com","threadId":"45367","inReplyTo":"2952fc80-a313-4193-64b6-072b7ccdef4f@ramsayjones.plus.com","subject":"Re: [GSoC][PATCH v5 2/3] credential-cache: use XDG_CACHE_HOME for socket","fromName":"Devin Lehmacher","fromEmail":"lehmacdj@gmail.com","sentAt":"2017-03-17T19:31:25Z","receivedAt":"2017-03-17T19:32:28Z","isPatch":true,"sender":{"key":"lehmacdj@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13156983?v=4"},"body":"> or $HOME/.cache/git/credential/socket if $XDG_CACHE_HOME is not set.\n> I don't have a good suggestion to re-word this paragraph. (I just\n> spent ten minutes trying!).\n\nI think it would not be too bad to not include this though because\n`$HOME/.cache/` is what XDG specifies as the default if\n`$XDG_CACHE_HOME` is unset.\n\nDevin\n"}]}