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 repo->owner = (pwd ? xstrdup(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name) : "");
69 p = fmt("%s/description", path);
71 readfile(p, &repo->desc, &size);
73 p = fmt("%s/README.html", path);
75 repo->readme = "README.html";
78 static void scan_path(const char *base, const char *path)
85 if (is_git_dir(path)) {
91 fprintf(stderr, "Error opening directory %s: %s (%d)\n",
92 path, strerror(errno), errno);
95 while((ent = readdir(dir)) != NULL) {
96 if (ent->d_name[0] == '.') {
97 if (ent->d_name[1] == '\0')
99 if (ent->d_name[1] == '.' && ent->d_name[2] == '\0')
102 buf = malloc(strlen(path) + strlen(ent->d_name) + 2);
104 fprintf(stderr, "Alloc error on %s: %s (%d)\n",
105 path, strerror(errno), errno);
108 sprintf(buf, "%s/%s", path, ent->d_name);
109 if (stat(buf, &st)) {
110 fprintf(stderr, "Error checking path %s: %s (%d)\n",
111 buf, strerror(errno), errno);
115 if (S_ISDIR(st.st_mode))
116 scan_path(base, buf);
122 void scan_tree(const char *path)
124 scan_path(path, path);