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