]> git.ipfire.org Git - thirdparty/git.git/blob - compat/fsmonitor/fsm-ipc-darwin.c
Merge branch 'es/add-doc-list-short-form-of-all-in-synopsis'
[thirdparty/git.git] / compat / fsmonitor / fsm-ipc-darwin.c
1 #include "git-compat-util.h"
2 #include "config.h"
3 #include "gettext.h"
4 #include "hex.h"
5 #include "path.h"
6 #include "repository.h"
7 #include "strbuf.h"
8 #include "fsmonitor-ll.h"
9 #include "fsmonitor-ipc.h"
10 #include "fsmonitor-path-utils.h"
11
12 static GIT_PATH_FUNC(fsmonitor_ipc__get_default_path, "fsmonitor--daemon.ipc")
13
14 const char *fsmonitor_ipc__get_path(struct repository *r)
15 {
16 static const char *ipc_path = NULL;
17 git_SHA_CTX sha1ctx;
18 char *sock_dir = NULL;
19 struct strbuf ipc_file = STRBUF_INIT;
20 unsigned char hash[GIT_MAX_RAWSZ];
21
22 if (!r)
23 BUG("No repository passed into fsmonitor_ipc__get_path");
24
25 if (ipc_path)
26 return ipc_path;
27
28
29 /* By default the socket file is created in the .git directory */
30 if (fsmonitor__is_fs_remote(r->gitdir) < 1) {
31 ipc_path = fsmonitor_ipc__get_default_path();
32 return ipc_path;
33 }
34
35 git_SHA1_Init(&sha1ctx);
36 git_SHA1_Update(&sha1ctx, r->worktree, strlen(r->worktree));
37 git_SHA1_Final(hash, &sha1ctx);
38
39 repo_config_get_string(r, "fsmonitor.socketdir", &sock_dir);
40
41 /* Create the socket file in either socketDir or $HOME */
42 if (sock_dir && *sock_dir) {
43 strbuf_addf(&ipc_file, "%s/.git-fsmonitor-%s",
44 sock_dir, hash_to_hex(hash));
45 } else {
46 strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s", hash_to_hex(hash));
47 }
48 free(sock_dir);
49
50 ipc_path = interpolate_path(ipc_file.buf, 1);
51 if (!ipc_path)
52 die(_("Invalid path: %s"), ipc_file.buf);
53
54 strbuf_release(&ipc_file);
55 return ipc_path;
56 }