Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Drop the scan's redundant stats and one-pass loop
The description and cgitrc readers already return when the file will not open, a repository's description is never NULL before it is read, and the owner lookup never went round a second time.
Diffstat (limited to 'source')
-rw-r--r--source/scan-tree.c23
1 file changed, 11 insertions, 12 deletions
diff --git a/source/scan-tree.c b/source/scan-tree.c
index be37805..eb3f6c4 100644
--- a/source/scan-tree.c
+++ b/source/scan-tree.c
@@ -223,23 +223,23 @@ static void add_repo(const char *base, struct strbuf *path)
strip_suffix_mem(current_repo->url, &urllen, "/");
current_repo->url[urllen] = '\0';
}
- while (!current_repo->owner) {
+ if (!current_repo->owner) {
if (!(pwd = getpwuid(st.st_uid))) {
fprintf(stderr, "[cgit] Unable to read the owner of %s: %s (%d)\n",
path->buf, strerror(errno), errno);
- break;
+ } else {
+ // A gecos field puts the owner's name in front of a
+ // comma separated list of office and phone details.
+ if (pwd->pw_gecos && (comma = strchr(pwd->pw_gecos, ',')))
+ *comma = '\0';
+ current_repo->owner =
+ cgit_strdup_first_line(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name);
}
- // A gecos field puts the owner's name in front of a comma
- // separated list of office and phone details.
- if (pwd->pw_gecos && (comma = strchr(pwd->pw_gecos, ',')))
- *comma = '\0';
- current_repo->owner = cgit_strdup_first_line(pwd->pw_gecos ? pwd->pw_gecos : pwd->pw_name);
}
- if (current_repo->desc == cgit_default_repo_desc || !current_repo->desc) {
+ if (current_repo->desc == cgit_default_repo_desc) {
strbuf_addstr(path, "description");
- if (!stat(path->buf, &st))
- cgit_read_first_line(path->buf, &current_repo->desc, &desc_size);
+ cgit_read_first_line(path->buf, &current_repo->desc, &desc_size);
strbuf_setlen(path, pathlen);
if (current_repo->desc && !strcmp(current_repo->desc, default_git_desc)) {
free(current_repo->desc);
@@ -251,8 +251,7 @@ static void add_repo(const char *base, struct strbuf *path)
set_section_from_path(&relpath, ctx.cfg.section_from_path);
strbuf_addstr(path, "cgitrc");
- if (!stat(path->buf, &st))
- config_file_parse(path->buf, apply_cgitrc);
+ config_file_parse(path->buf, apply_cgitrc);
strbuf_release(&relpath);
}