Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin Lehmacher <lehmacdj@gmail.com>2017-03-17 15:36:33 +0300
committerJunio C Hamano <gitster@pobox.com>2017-03-17 21:19:40 +0300
commit60759baac1f063a6c3069ca4b909abb8a20fa08a (patch)
treefaeb57c96340077486ccd0446bb3b470dcba146a /credential-cache.c
parente7f136bf93132c24183c168a9a054540e6216c06 (diff)
credential-cache: use XDG_CACHE_HOME for socket
Make git-credential-cache follow the XDG base path specification by default. This increases consistency with other applications and helps keep clutter out of users' home directories. Check the old socket location, ~/.git-credential-cache/, and use ~/.git-credential-cache/socket if that directory exists rather than forcing users who have used `git credential-cache` before to migrate to the new XDG compliant location. Otherwise use the socket $XDG_CACHE_HOME/git/credential/socket following XDG base path specification. Use the subdirectory credential/ in case other files are cached under $XDG_CACHE_HOME/git/ in the future and to make the socket's purpose clear. Signed-off-by: Devin Lehmacher <lehmacdj@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'credential-cache.c')
-rw-r--r--credential-cache.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/credential-cache.c b/credential-cache.c
index cc8a6ee192..3cbd420019 100644
--- a/credential-cache.c
+++ b/credential-cache.c
@@ -83,6 +83,19 @@ static void do_cache(const char *socket, const char *action, int timeout,
strbuf_release(&buf);
}
+static char *get_socket_path(void)
+{
+ struct stat sb;
+ char *old_dir, *socket;
+ old_dir = expand_user_path("~/.git-credential-cache");
+ if (old_dir && !stat(old_dir, &sb) && S_ISDIR(sb.st_mode))
+ socket = xstrfmt("%s/socket", old_dir);
+ else
+ socket = xdg_cache_home("credential/socket");
+ free(old_dir);
+ return socket;
+}
+
int cmd_main(int argc, const char **argv)
{
char *socket_path = NULL;
@@ -106,7 +119,7 @@ int cmd_main(int argc, const char **argv)
op = argv[0];
if (!socket_path)
- socket_path = expand_user_path("~/.git-credential-cache/socket");
+ socket_path = get_socket_path();
if (!socket_path)
die("unable to find a suitable socket path; use --socket");