-
Notifications
You must be signed in to change notification settings - Fork 0
/
globals.c
79 lines (61 loc) · 1.34 KB
/
globals.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "headers/globals.h"
#include "headers/fileutils.h"
char* dot_dir = NULL;
char* find_dot_dir(void);
const char*
get_dot_dir(void)
{
// have not been initialized yet
if (dot_dir == NULL) {
dot_dir = find_dot_dir();
}
return (const char*)dot_dir;
}
char*
get_repo_root(void)
{
char* out;
out = strdup(get_dot_dir());
if (strend(out, NON_BARE_DIR)) {
*strrchr(out, '/') = 0;
*strrchr(out, '/') = 0;
strcat(out, "/");
}
return out;
}
void
set_dot_dir(char* dir)
{
assert(dot_dir == NULL);
dot_dir = dir;
}
char*
find_dot_dir(void)
{
char* cwd;
cwd = get_cwd();
cwd = realloc(cwd, strlen(cwd)+20);
*strrchr(cwd, '/') = 0;
do { // this is beyond retarded.
/* check if current dir is 9it working */
strcat(cwd, "/.9it/9IT");
if (access(cwd, F_OK) == 0) {
*(strrchr(cwd, '/')+1) = 0;
break;
}
*strrchr(cwd, '/') = 0;
*strrchr(cwd, '/') = 0;
strcat(cwd, "/9IT");
if (access(cwd, F_OK) == 0) {
*(strrchr(cwd, '/')+1) = 0;
break;
}
*strrchr(cwd, '/') = 0;
*strrchr(cwd, '/') = 0;
} while (strlen(cwd) > 0);
if (strlen(cwd) == 0) {
printf("9it repo not initalized\n");
exit(1);
}
return cwd;
}