[PATCH 5/6] cgit: add extra alternates

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


This allows you to specify additional alternate repositories to be used
with the given repository to resolve trees and commits.

The main use for this is to be able to view commits that are not really
part of the current repository. In our setup, we have an "all.git" which
is really just an empty (bare) git repository with objects/info/alternates
pointing to every other relevant repository (mainline, stable, etc.) which
we then reference with this new config option.

This is not strictly necessary for notes support, but makes it easier to
linkify certain SHA1s in the notes if those commits are not usually
available from the currently selected repository.

Signed-off-by: Vegard Nossum <vegard.nossum at oracle.com>
---
 cgit.c       | 10 ++++++++++
 cgit.h       |  1 +
 cgitrc.5.txt |  8 ++++++++
 3 files changed, 19 insertions(+)

diff --git a/cgit.c b/cgit.c
index e64694b..e6a94e1 100644
--- a/cgit.c
+++ b/cgit.c
@@ -111,6 +111,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
 		repo->notes_repo = xstrdup(value);
 	else if (!strcmp(name, "notes_ref"))
 		repo->notes_ref = xstrdup(value);
+	else if (!strcmp(name, "alternates"))
+		string_list_append(&repo->alternates, xstrdup(value));
 	else if (ctx.cfg.enable_filter_overrides) {
 		if (!strcmp(name, "about-filter"))
 			repo->about_filter = cgit_new_filter(value, ABOUT);
@@ -578,6 +580,8 @@ static struct repository notes_repo;
 
 static void prepare_repo_env(int *nongit)
 {
+	struct string_list_item *alternates_path;
+
 	/* The path to the git repository. */
 	setenv("GIT_DIR", ctx.repo->path, 1);
 
@@ -605,6 +609,12 @@ static void prepare_repo_env(int *nongit)
 	} else {
 		load_display_notes(NULL);
 	}
+
+	for_each_string_list_item(alternates_path, &ctx.repo->alternates) {
+	        struct repository *extra_repo = malloc(sizeof(*extra_repo));
+	        if (repo_init(extra_repo, alternates_path->string, NULL) == 0)
+		        add_to_alternates_memory(extra_repo->objects->odb->path);
+	}
 }
 
 static int prepare_repo_cmd(int nongit)
diff --git a/cgit.h b/cgit.h
index 50a5c73..de5cd3d 100644
--- a/cgit.h
+++ b/cgit.h
@@ -115,6 +115,7 @@ struct cgit_repo {
 	int ignore;
 	char *notes_repo;
 	char *notes_ref;
+	struct string_list alternates;
 };
 
 typedef void (*repo_config_fn)(struct cgit_repo *repo, const char *name,
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index f3f31ee..1be1922 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -456,6 +456,14 @@ repo.about-filter::
 	Override the default about-filter. Default value: none. See also:
 	"enable-filter-overrides". See also: "FILTER API".
 
+repo.alternates::
+	Include additional repository object databases. This allows the
+	current repository to resolve commits from other repositories
+	(without includings its tags and branches), which is useful if you
+	want a single path that can resolve SHA1s from multiple repositories.
+	This should be an absolute path to the .git directory of the other
+	repository. Default value: none.
+
 repo.branch-sort::
 	Flag which, when set to "age", enables date ordering in the branch ref
 	list, and when set to "name" enables ordering by branch name. Default
-- 
2.35.1.46.g38062e73e0



More information about the CGit mailing list