Commit Diff


commit - 59d3c40ea91b14cc0aa6331c420a5d5c90e752ff
commit + 9a1cc63fe0022b929860dfe206daf674f83a7d9a
blob - 5a0d7c217fdcef3f2933f791dbf73383268f8cc9
blob + a071ae4751bd72becbb2df2a8d940355b72725e8
--- gotweb/gotweb.c
+++ gotweb/gotweb.c
@@ -160,7 +160,7 @@ static struct gw_header		*gw_init_header(void);
 
 static const struct got_error	*gw_get_repo_description(char **, struct gw_trans *,
 				    char *);
-static char			*gw_get_repo_owner(struct gw_trans *,
+static const struct got_error	*gw_get_repo_owner(char **, struct gw_trans *,
 				    char *);
 static char			*gw_get_time_str(time_t, int);
 static const struct got_error	*gw_get_repo_age(char **, struct gw_trans *,
@@ -539,7 +539,8 @@ gw_index(struct gw_trans *gw_trans)
 			return got_error_from_errno("asprintf");
 
 		if (asprintf(&html, index_projects, gw_dir->name, gw_dir->name,
-		    gw_dir->description, gw_dir->owner, gw_dir->age,
+		    gw_dir->description, gw_dir->owner ? gw_dir->owner : "",
+		    gw_dir->age,
 		    navs) == -1)
 			return got_error_from_errno("asprintf");
 
@@ -786,20 +787,18 @@ gw_summary(struct gw_trans *gw_trans)
 		}
 	}
 
-	if (gw_trans->gw_conf->got_show_repo_owner) {
-		if (gw_trans->gw_dir->owner != NULL &&
-		    (strcmp(gw_trans->gw_dir->owner, "") != 0)) {
-			if (asprintf(&repo_owner_html, repo_owner,
-			    gw_trans->gw_dir->owner) == -1) {
-				error = got_error_from_errno("asprintf");
-				goto done;
-			}
+	if (gw_trans->gw_conf->got_show_repo_owner &&
+	    gw_trans->gw_dir->owner != NULL) {
+		if (asprintf(&repo_owner_html, repo_owner,
+		    gw_trans->gw_dir->owner) == -1) {
+			error = got_error_from_errno("asprintf");
+			goto done;
+		}
 
-			kerr = khttp_puts(gw_trans->gw_req, repo_owner_html);
-			if (kerr != KCGI_OK) {
-				error = gw_kcgi_error(kerr);
-				goto done;
-			}
+		kerr = khttp_puts(gw_trans->gw_req, repo_owner_html);
+		if (kerr != KCGI_OK) {
+			error = gw_kcgi_error(kerr);
+			goto done;
 		}
 	}
 
@@ -1047,7 +1046,9 @@ done:
 	    gw_dir->path);
 	if (error)
 		goto errored;
-	gw_dir->owner = gw_get_repo_owner(gw_trans, gw_dir->path);
+	error = gw_get_repo_owner(&gw_dir->owner, gw_trans, gw_dir->path);
+	if (error)
+		goto errored;
 	error = gw_get_repo_age(&gw_dir->age, gw_trans, gw_dir->path,
 	    "refs/heads", TM_DIFF);
 	if (error)
@@ -1746,63 +1747,29 @@ done:
 		return diff_html;
 }
 
-static char *
-gw_get_repo_owner(struct gw_trans *gw_trans, char *dir)
-{
-	FILE *f;
-	char *owner = NULL, *d_file = NULL;
-	char *gotweb = "[gotweb]", *gitweb = "[gitweb]", *gw_owner = "owner";
-	char *comp, *pos, *buf;
-	unsigned int i;
+static const struct got_error *
+gw_get_repo_owner(char **owner, struct gw_trans *gw_trans, char *dir)
+{
+	const struct got_error *error = NULL;
+	struct got_repository *repo;
+	const char *gitconfig_owner;
 
-	if (gw_trans->gw_conf->got_show_repo_owner == 0)
-		goto err;
+	*owner = NULL;
 
-	if (asprintf(&d_file, "%s/config", dir) == -1)
-		goto err;
-
-	if ((f = fopen(d_file, "r")) == NULL)
-		goto err;
+	if (gw_trans->gw_conf->got_show_repo_owner == 0)
+		return NULL;
 
-	if ((buf = calloc(128, sizeof(char *))) == NULL)
-		goto err;
-
-	while ((fgets(buf, 128, f)) != NULL) {
-		if (ferror(f))
-			goto err;
-		if ((pos = strstr(buf, gotweb)) != NULL)
-			break;
-
-		if ((pos = strstr(buf, gitweb)) != NULL)
-			break;
+	error = got_repo_open(&repo, dir, NULL);
+	if (error)
+		return error;
+	gitconfig_owner = got_repo_get_gitconfig_owner(repo);
+	if (gitconfig_owner) {
+		*owner = strdup(gitconfig_owner);
+		if (*owner == NULL)
+			error = got_error_from_errno("strdup");
 	}
-
-	if (pos == NULL)
-		goto err;
-
-	do {
-		fgets(buf, 128, f);
-		if (ferror(f))
-			goto err;
-	} while ((comp = strcasestr(buf, gw_owner)) == NULL);
-
-	if (comp == NULL)
-		goto err;
-
-	if (strncmp(gw_owner, comp, strlen(gw_owner)) != 0)
-		goto err;
-
-	for (i = 0; i < 2; i++)
-		owner = strsep(&buf, "\"");
-
-	if (owner == NULL)
-		goto err;
-
-	fclose(f);
-	free(d_file);
-	return owner;
-err:
-	return strdup("");
+	got_repo_close(repo);
+	return error;
 }
 
 static const struct got_error *
blob - f54c896e78705e3833a92b32f7a8d1a89d804886
blob + d3b000f562ba9a602722f0d0855655cb2703138b
--- include/got_repository.h
+++ include/got_repository.h
@@ -44,6 +44,9 @@ const char *got_repo_get_global_gitconfig_author_name(
 /* Obtain global commit author email parsed ~/.gitconfig, else NULL. */
 const char *got_repo_get_global_gitconfig_author_email(struct got_repository *);
 
+/* Obtain repository owner name if parsed from gitconfig, else NULL. */
+const char *got_repo_get_gitconfig_owner(struct got_repository *);
+
 /* Information about one remote repository. */
 struct got_remote_repo {
 	char *name;
blob - 08d4c9dc4e0493c2c7ecc0d939c2320f04ae787f
blob + f73c2bf8b3f3e83d497b150a9723302b20ff6408
--- lib/got_lib_privsep.h
+++ lib/got_lib_privsep.h
@@ -119,6 +119,8 @@ enum got_imsg_type {
 	GOT_IMSG_GITCONFIG_STR_VAL,
 	GOT_IMSG_GITCONFIG_REMOTES,
 	GOT_IMSG_GITCONFIG_REMOTE,
+	GOT_IMSG_GITCONFIG_OWNER_REQUEST,
+	GOT_IMSG_GITCONFIG_OWNER,
 };
 
 /* Structure for GOT_IMSG_ERROR. */
@@ -325,6 +327,7 @@ const struct got_error *got_privsep_send_gitconfig_aut
     struct imsgbuf *);
 const struct got_error *got_privsep_send_gitconfig_remotes_req(
     struct imsgbuf *);
+const struct got_error *got_privsep_send_gitconfig_owner_req(struct imsgbuf *);
 const struct got_error *got_privsep_send_gitconfig_str(struct imsgbuf *,
     const char *);
 const struct got_error *got_privsep_recv_gitconfig_str(char **,
blob - fe655627724bb2f95ad79457b9a0e7ce0e64140e
blob + 5b1a4057c54cc2ec9b693ef8ab547dd324ef148c
--- lib/got_lib_repository.h
+++ lib/got_lib_repository.h
@@ -49,6 +49,7 @@ struct got_repository {
 	char *global_gitconfig_author_email;
 	int ngitconfig_remotes;
 	struct got_remote_repo *gitconfig_remotes;
+	char *gitconfig_owner;
 };
 
 const struct got_error*got_repo_cache_object(struct got_repository *,
blob - a2566dac4aee1eadf39748a400c7710ebdd34828
blob + 8964ec091913ce64c199534c154e3e151668e74f
--- lib/privsep.c
+++ lib/privsep.c
@@ -1305,6 +1305,17 @@ got_privsep_send_gitconfig_remotes_req(struct imsgbuf 
 }
 
 const struct got_error *
+got_privsep_send_gitconfig_owner_req(struct imsgbuf *ibuf)
+{
+	if (imsg_compose(ibuf,
+	    GOT_IMSG_GITCONFIG_OWNER_REQUEST, 0, 0, -1, NULL, 0) == -1)
+		return got_error_from_errno("imsg_compose "
+		    "GITCONFIG_OWNER_REQUEST");
+
+	return flush_imsg(ibuf);
+}
+
+const struct got_error *
 got_privsep_send_gitconfig_str(struct imsgbuf *ibuf, const char *value)
 {
 	size_t len = value ? strlen(value) + 1 : 0;
blob - 1f4bef491b17397337b2521fb72f2a60b7bb777a
blob + 479f6f6d957cf01339764d71a6da6db9ef04ed9a
--- lib/repository.c
+++ lib/repository.c
@@ -111,6 +111,12 @@ const char *
 got_repo_get_global_gitconfig_author_email(struct got_repository *repo)
 {
 	return repo->global_gitconfig_author_email;
+}
+
+const char *
+got_repo_get_gitconfig_owner(struct got_repository *repo)
+{
+	return repo->gitconfig_owner;
 }
 
 int
@@ -374,6 +380,7 @@ static const struct got_error *
 parse_gitconfig_file(int *gitconfig_repository_format_version,
     char **gitconfig_author_name, char **gitconfig_author_email,
     struct got_remote_repo **remotes, int *nremotes,
+    char **gitconfig_owner,
     const char *gitconfig_path)
 {
 	const struct got_error *err = NULL, *child_err = NULL;
@@ -458,8 +465,17 @@ parse_gitconfig_file(int *gitconfig_repository_format_
 
 		err = got_privsep_recv_gitconfig_remotes(remotes,
 		    nremotes, ibuf);
+		if (err)
+			goto done;
+	}
+
+	if (gitconfig_owner) {
+		err = got_privsep_send_gitconfig_owner_req(ibuf);
 		if (err)
 			goto done;
+		err = got_privsep_recv_gitconfig_str(gitconfig_owner, ibuf);
+		if (err)
+			goto done;
 	}
 
 	imsg_clear(ibuf);
@@ -490,7 +506,7 @@ read_gitconfig(struct got_repository *repo, const char
 		err = parse_gitconfig_file(&dummy_repo_version,
 		    &repo->global_gitconfig_author_name,
 		    &repo->global_gitconfig_author_email,
-		    NULL, NULL, global_gitconfig_path);
+		    NULL, NULL, NULL, global_gitconfig_path);
 		if (err)
 			return err;
 	}
@@ -503,7 +519,7 @@ read_gitconfig(struct got_repository *repo, const char
 	err = parse_gitconfig_file(&repo->gitconfig_repository_format_version,
 	    &repo->gitconfig_author_name, &repo->gitconfig_author_email,
 	    &repo->gitconfig_remotes, &repo->ngitconfig_remotes,
-	    repo_gitconfig_path);
+	    &repo->gitconfig_owner, repo_gitconfig_path);
 	if (err)
 		goto done;
 done:
blob - 7c6439deb2b6bd6dd54a308e07d765495636ca39
blob + 4d1f4a8e9ef496a4c7a895a9789cdf0ba1c63979
--- libexec/got-read-gitconfig/got-read-gitconfig.c
+++ libexec/got-read-gitconfig/got-read-gitconfig.c
@@ -140,6 +140,21 @@ done:
 	free(remotes);
 	got_gitconfig_free_list(sections);
 	return err;
+}
+
+static const struct got_error *
+gitconfig_owner_request(struct imsgbuf *ibuf, struct got_gitconfig *gitconfig)
+{
+	char *value;
+
+	if (gitconfig == NULL)
+		return got_error(GOT_ERR_PRIVSEP_MSG);
+
+	value = got_gitconfig_get_str(gitconfig, "gotweb", "owner");
+	if (value)
+		return got_privsep_send_gitconfig_str(ibuf, value);
+	value = got_gitconfig_get_str(gitconfig, "gitweb", "owner");
+	return got_privsep_send_gitconfig_str(ibuf, value);
 }
 
 int
@@ -220,6 +235,9 @@ main(int argc, char *argv[])
 		case GOT_IMSG_GITCONFIG_REMOTES_REQUEST:
 			err = gitconfig_remotes_request(&ibuf, gitconfig);
 			break;
+		case GOT_IMSG_GITCONFIG_OWNER_REQUEST:
+			err = gitconfig_owner_request(&ibuf, gitconfig);
+			break;
 		default:
 			err = got_error(GOT_ERR_PRIVSEP_MSG);
 			break;