Merge branch 'ab/grep-preparatory-cleanup' into sb/submodule-blanket-recursive
[gitweb.git] / credential-cache.c
index 774d1469fb533c0e68fec648d7348f3bc7443f24..91550bfb0b3325ad92a3f3c65d5f779b61fa9951 100644 (file)
@@ -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", 0);
+       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", 0);
+               socket_path = get_socket_path();
        if (!socket_path)
                die("unable to find a suitable socket path; use --socket");