]>
git.cameronkatri.com Git - cgit.git/blob - scan-tree.c
2 #include "configfile.h"
7 /* return 1 if path contains a objects/ directory and a HEAD file */
8 static int is_git_dir(const char *path
)
11 static char buf
[MAX_PATH
];
13 if (snprintf(buf
, MAX_PATH
, "%s/objects", path
) >= MAX_PATH
) {
14 fprintf(stderr
, "Insanely long path: %s\n", path
);
19 fprintf(stderr
, "Error checking path %s: %s (%d)\n",
20 path
, strerror(errno
), errno
);
23 if (!S_ISDIR(st
.st_mode
))
26 sprintf(buf
, "%s/HEAD", path
);
29 fprintf(stderr
, "Error checking path %s: %s (%d)\n",
30 path
, strerror(errno
), errno
);
33 if (!S_ISREG(st
.st_mode
))
39 struct cgit_repo
*repo
;
40 repo_config_fn config_fn
;
42 static void repo_config(const char *name
, const char *value
)
44 config_fn(repo
, name
, value
);
47 static void add_repo(const char *base
, const char *path
, repo_config_fn fn
)
54 if (stat(path
, &st
)) {
55 fprintf(stderr
, "Error accessing %s: %s (%d)\n",
56 path
, strerror(errno
), errno
);
59 if (!stat(fmt("%s/noweb", path
), &st
))
61 if ((pwd
= getpwuid(st
.st_uid
)) == NULL
) {
62 fprintf(stderr
, "Error reading owner-info for %s: %s (%d)\n",
63 path
, strerror(errno
), errno
);
69 p
= fmt("%s", path
+ strlen(base
) + 1);
71 if (!strcmp(p
+ strlen(p
) - 5, "/.git"))
72 p
[strlen(p
) - 5] = '\0';
74 repo
= cgit_add_repo(xstrdup(p
));
75 repo
->name
= repo
->url
;
76 repo
->path
= xstrdup(path
);
77 p
= (pwd
&& pwd
->pw_gecos
) ? strchr(pwd
->pw_gecos
, ',') : NULL
;
80 repo
->owner
= (pwd
? xstrdup(pwd
->pw_gecos
? pwd
->pw_gecos
: pwd
->pw_name
) : "");
82 p
= fmt("%s/description", path
);
84 readfile(p
, &repo
->desc
, &size
);
86 p
= fmt("%s/README.html", path
);
88 repo
->readme
= "README.html";
90 p
= fmt("%s/cgitrc", path
);
93 parse_configfile(xstrdup(p
), &repo_config
);
97 static void scan_path(const char *base
, const char *path
, repo_config_fn fn
)
104 if (is_git_dir(path
)) {
105 add_repo(base
, path
, fn
);
108 if (is_git_dir(fmt("%s/.git", path
))) {
109 add_repo(base
, fmt("%s/.git", path
), fn
);
114 fprintf(stderr
, "Error opening directory %s: %s (%d)\n",
115 path
, strerror(errno
), errno
);
118 while((ent
= readdir(dir
)) != NULL
) {
119 if (ent
->d_name
[0] == '.') {
120 if (ent
->d_name
[1] == '\0')
122 if (ent
->d_name
[1] == '.' && ent
->d_name
[2] == '\0')
125 buf
= malloc(strlen(path
) + strlen(ent
->d_name
) + 2);
127 fprintf(stderr
, "Alloc error on %s: %s (%d)\n",
128 path
, strerror(errno
), errno
);
131 sprintf(buf
, "%s/%s", path
, ent
->d_name
);
132 if (stat(buf
, &st
)) {
133 fprintf(stderr
, "Error checking path %s: %s (%d)\n",
134 buf
, strerror(errno
), errno
);
138 if (S_ISDIR(st
.st_mode
))
139 scan_path(base
, buf
, fn
);
145 void scan_tree(const char *path
, repo_config_fn fn
)
147 scan_path(path
, path
, fn
);