6 /* return 1 if path contains a objects/ directory and a HEAD file */
7 static int is_git_dir(const char *path)
10 static char buf[MAX_PATH];
12 if (snprintf(buf, MAX_PATH, "%s/objects", path) >= MAX_PATH) {
13 fprintf(stderr, "Insanely long path: %s\n", path);
18 fprintf(stderr, "Error checking path %s: %s (%d)\n",
19 path, strerror(errno), errno);
22 if (!S_ISDIR(st.st_mode))
25 sprintf(buf, "%s/HEAD", path);
28 fprintf(stderr, "Error checking path %s: %s (%d)\n",
29 path, strerror(errno), errno);
32 if (!S_ISREG(st.st_mode))
38 static void add_repo(const char *base, const char *path)
40 struct cgit_repo *repo;
46 if (stat(path, &st)) {
47 fprintf(stderr, "Error accessing %s: %s (%d)\n",
48 path, strerror(errno), errno);
51 if ((pwd = getpwuid(st.st_uid)) == NULL) {
52 fprintf(stderr, "Error reading owner-info for %s: %s (%d)\n",
53 path, strerror(errno), errno);
59 p = fmt("%s", path + strlen(base) + 1);
61 if (!strcmp(p + strlen(p) - 5, "/.git"))
62 p[strlen(p) - 5] = '\0';
64 repo = cgit_add_repo(xstrdup(p));
65 repo->name = repo->url;
66 repo->path = xstrdup(path);
67 p = (pwd && pwd->pw_gecos) ? strchr(pwd->pw_gecos, ',') : NULL;
70 repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : "");
72 p = fmt("%s/description", path);
74 readfile(p, &repo->desc, &size);
76 p = fmt("%s/README.html", path);
78 repo->readme = "README.html";
81 static void scan_path(const char *base, const char *path)
88 if (is_git_dir(path)) {
94 fprintf(stderr, "Error opening directory %s: %s (%d)\n",
95 path, strerror(errno), errno);
98 while((ent = readdir(dir)) != NULL) {
99 if (ent->d_name[0] == '.') {
100 if (ent->d_name[1] == '\0')
102 if (ent->d_name[1] == '.' && ent->d_name[2] == '\0')
105 buf = malloc(strlen(path) + strlen(ent->d_name) + 2);
107 fprintf(stderr, "Alloc error on %s: %s (%d)\n",
108 path, strerror(errno), errno);
111 sprintf(buf, "%s/%s", path, ent->d_name);
112 if (stat(buf, &st)) {
113 fprintf(stderr, "Error checking path %s: %s (%d)\n",
114 buf, strerror(errno), errno);
118 if (S_ISDIR(st.st_mode))
119 scan_path(base, buf);
125 void scan_tree(const char *path)
127 scan_path(path, path);