git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Devin Lehmacher <lehmacdj@gmail.com>
To: lehmacdj@gmail.com
Cc: git@vger.kernel.org, gitster@pobox.com, peff@peff.net
Subject: [GSoC][PATCH v6 2/3] credential-cache: use XDG_CACHE_HOME for socket
Date: Fri, 17 Mar 2017 08:36:33 -0400	[thread overview]
Message-ID: <20170317123634.10863-2-lehmacdj@gmail.com> (raw)
In-Reply-To: <20170317123634.10863-1-lehmacdj@gmail.com>

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>
---
 Documentation/git-credential-cache.txt | 11 +++++++----
 credential-cache.c                     | 15 ++++++++++++++-
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/Documentation/git-credential-cache.txt b/Documentation/git-credential-cache.txt
index 96208f822..2b8582639 100644
--- a/Documentation/git-credential-cache.txt
+++ b/Documentation/git-credential-cache.txt
@@ -33,10 +33,13 @@ OPTIONS
 --socket <path>::
 
 	Use `<path>` to contact a running cache daemon (or start a new
-	cache daemon if one is not started). Defaults to
-	`~/.git-credential-cache/socket`. If your home directory is on a
-	network-mounted filesystem, you may need to change this to a
-	local filesystem. You must specify an absolute path.
+	cache daemon if one is not started).
+	Defaults to `$XDG_CACHE_HOME/git/credential/socket` unless
+	`~/.git-credential-cache/` exists in which case
+	`~/.git-credential-cache/socket` is used instead.
+	If your home directory is on a network-mounted filesystem, you
+	may need to change this to a local filesystem. You must specify
+	an absolute path.
 
 CONTROLLING THE DAEMON
 ----------------------
diff --git a/credential-cache.c b/credential-cache.c
index cc8a6ee19..3cbd42001 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");
 
-- 
2.11.0


  reply	other threads:[~2017-03-17 12:37 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-13 17:22 [GSoC][PATCH 0/3] Move ~/.git-credential-cache to ~/.cache/git Devin Lehmacher
2017-03-13 17:22 ` [GSoC][PATCH 1/3] path.c: Add xdg_cache_home to get paths under XDG_CACHE_HOME Devin Lehmacher
2017-03-13 18:48   ` Jeff King
2017-03-13 19:44     ` Devin Lehmacher
2017-03-13 17:22 ` [GSoC][PATCH 2/3] credential-cache.c: Make git use XDG_CACHE_HOME for credentials Devin Lehmacher
2017-03-13 18:09   ` Junio C Hamano
2017-03-13 19:03     ` Jeff King
2017-03-13 19:05       ` Junio C Hamano
2017-03-13 19:24         ` Devin Lehmacher
2017-03-13 19:22     ` Devin Lehmacher
2017-03-13 18:11   ` Junio C Hamano
2017-03-13 19:01   ` Jeff King
2017-03-13 17:22 ` [GSoC][PATCH 3/3] Update documentation to reflect new socket location Devin Lehmacher
2017-03-13 18:04   ` Junio C Hamano
2017-03-13 20:42   ` [GSoC][PATCH v2 2/2] credential-cache: use XDG_CACHE_HOME for socket Devin Lehmacher
2017-03-13 20:43   ` [GSoC][PATCH v2 1/2] path.c: add xdg_cache_home Devin Lehmacher
2017-03-13 20:43     ` [GSoC][PATCH v2 2/2] credential-cache: use XDG_CACHE_HOME for socket Devin Lehmacher
2017-03-13 21:52       ` Junio C Hamano
2017-03-14  0:32         ` [GSoC][PATCH/RFC v3 0/3] Fix commit messages, check if socket is socket Devin Lehmacher
2017-03-14  0:32           ` [GSoC][PATCH/RFC v3 1/3] path.c: add xdg_cache_home Devin Lehmacher
2017-03-14  0:32           ` [GSoC][PATCH/RFC v3 2/3] credential-cache: use XDG_CACHE_HOME for socket Devin Lehmacher
2017-03-14  1:50             ` Junio C Hamano
2017-03-14  0:32           ` [GSoC][PATCH/RFC v3 3/3] credential-cache: only use user_socket if a socket Devin Lehmacher
2017-03-14  0:40             ` Devin Lehmacher
2017-03-14  0:44               ` Brandon Williams
2017-03-14  1:30                 ` Devin Lehmacher
2017-03-14 17:03                   ` Brandon Williams
2017-03-14  1:52             ` Junio C Hamano
2017-03-14  6:10               ` Junio C Hamano
2017-03-14  6:17                 ` Devin Lehmacher
2017-03-16  5:18             ` [GSoC][PATCH v4 0/4] Moving credential-cache socket to xdg path Devin Lehmacher
2017-03-16  5:18               ` [GSoC][PATCH v4 1/4] path.c: add xdg_cache_home Devin Lehmacher
2017-03-16  5:18               ` [GSoC][PATCH v4 2/4] dir: add directory_exists Devin Lehmacher
2017-03-16 16:09                 ` Junio C Hamano
2017-03-16 18:26                   ` Junio C Hamano
2017-03-16  5:18               ` [GSoC][PATCH v4 3/4] credential-cache: use XDG_CACHE_HOME for socket Devin Lehmacher
2017-03-16 16:20                 ` Junio C Hamano
2017-03-16 18:02                   ` Jeff King
2017-03-16  5:18               ` [GSoC][PATCH v4 4/4] credential-cache: add tests for XDG functionality Devin Lehmacher
2017-03-16 16:29                 ` Junio C Hamano
2017-03-16 17:58                   ` Jeff King
2017-03-17  2:53                 ` [GSoC][PATCH v5 1/3] path.c: add xdg_cache_home Devin Lehmacher
2017-03-17  2:53                   ` [GSoC][PATCH v5 2/3] credential-cache: use XDG_CACHE_HOME for socket Devin Lehmacher
2017-03-17 16:12                     ` Ramsay Jones
2017-03-17 19:31                       ` Devin Lehmacher
2017-03-17  2:53                   ` [GSoC][PATCH v5 3/3] credential-cache: add tests for XDG functionality Devin Lehmacher
2017-03-17  5:38                     ` Junio C Hamano
2017-03-17 12:36                     ` [GSoC][PATCH v6 1/3] path.c: add xdg_cache_home Devin Lehmacher
2017-03-17 12:36                       ` Devin Lehmacher [this message]
2017-03-17 13:42                         ` [GSoC][PATCH v6 2/3] credential-cache: use XDG_CACHE_HOME for socket Jeff King
2017-03-17 12:36                       ` [GSoC][PATCH v6 3/3] credential-cache: add tests for XDG functionality Devin Lehmacher
2017-03-17 13:38                         ` Jeff King
2017-03-17 13:42                       ` [GSoC][PATCH v6 1/3] path.c: add xdg_cache_home Jeff King
2017-03-13 21:39     ` [GSoC][PATCH v2 1/2] " Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170317123634.10863-2-lehmacdj@gmail.com \
    --to=lehmacdj@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).