[PATCH 1/6] Support notes from external repositories

Vegard Nossum vegard.nossum at oracle.com
Mon Oct 17 11:50:05 UTC 2022


Before this commit, all git notes had to be part of the repository that
the notes are displayed for.

This adds an option to display notes from an external repository.

Signed-off-by: Vegard Nossum <vegard.nossum at oracle.com>
---
 cgit.c       | 27 ++++++++++++++++++++++++++-
 cgit.h       |  2 ++
 cgitrc.5.txt |  8 ++++++++
 shared.c     |  2 ++
 4 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/cgit.c b/cgit.c
index 08d81a1..dc6b491 100644
--- a/cgit.c
+++ b/cgit.c
@@ -107,6 +107,10 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
 		repo->hide = atoi(value);
 	else if (!strcmp(name, "ignore"))
 		repo->ignore = atoi(value);
+	else if (!strcmp(name, "notes_repo"))
+		repo->notes_repo = xstrdup(value);
+	else if (!strcmp(name, "notes_ref"))
+		repo->notes_ref = xstrdup(value);
 	else if (ctx.cfg.enable_filter_overrides) {
 		if (!strcmp(name, "about-filter"))
 			repo->about_filter = cgit_new_filter(value, ABOUT);
@@ -570,6 +574,8 @@ static void print_no_repo_clone_urls(const char *url)
         html("</a></td></tr>\n");
 }
 
+static struct repository notes_repo;
+
 static void prepare_repo_env(int *nongit)
 {
 	/* The path to the git repository. */
@@ -579,7 +585,26 @@ static void prepare_repo_env(int *nongit)
 	 * load local configuration from the git repository, so we do them both while
 	 * the HOME variables are unset. */
 	setup_git_directory_gently(nongit);
-	load_display_notes(NULL);
+
+	if (ctx.repo->notes_repo) {
+		if (repo_init(&notes_repo, ctx.repo->notes_repo, NULL) == 0)
+			add_to_alternates_memory(notes_repo.objects->odb->path);
+	}
+
+	if (ctx.repo->notes_ref) {
+		struct display_notes_opt notes_opt;
+
+		init_display_notes(&notes_opt);
+		notes_opt.use_default_notes = 0;
+
+		if (ctx.repo->notes_repo)
+			notes_opt.repo = &notes_repo;
+
+		string_list_append(&notes_opt.extra_notes_refs, ctx.repo->notes_ref);
+		load_display_notes(&notes_opt);
+	} else {
+		load_display_notes(NULL);
+	}
 }
 
 static int prepare_repo_cmd(int nongit)
diff --git a/cgit.h b/cgit.h
index 69b5c13..50a5c73 100644
--- a/cgit.h
+++ b/cgit.h
@@ -113,6 +113,8 @@ struct cgit_repo {
 	struct string_list submodules;
 	int hide;
 	int ignore;
+	char *notes_repo;
+	char *notes_ref;
 };
 
 typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 33a6a8c..f3f31ee 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -562,6 +562,14 @@ repo.max-stats::
 repo.name::
 	The value to show as repository name. Default value: <repo.url>.
 
+repo.notes_ref::
+	A ref or glob similar to the "notes.displayRef" git config option.
+	Default value: none.
+
+repo.notes_repo::
+	If you want to use notes from an external repository, set this
+	option to the path of the repository. Default value: none.
+
 repo.owner::
 	A value used to identify the owner of the repository. Default value:
 	none.
diff --git a/shared.c b/shared.c
index 8115469..d3d0fa0 100644
--- a/shared.c
+++ b/shared.c
@@ -79,6 +79,8 @@ struct cgit_repo *cgit_add_repo(const char *url)
 	ret->clone_url = ctx.cfg.clone_url;
 	ret->submodules.strdup_strings = 1;
 	ret->hide = ret->ignore = 0;
+	ret->notes_repo = NULL;
+	ret->notes_ref = NULL;
 	return ret;
 }
 
-- 
2.35.1.46.g38062e73e0



More information about the CGit mailing list