List for cgit developers and users
 help / color / mirror / Atom feed
From: Vegard Nossum <vegard.nossum@oracle.com>
To: cgit@lists.zx2c4.com
Cc: konstantin@linuxfoundation.org, Vegard Nossum <vegard.nossum@oracle.com>
Subject: [PATCH 5/6] cgit: add extra alternates
Date: Mon, 17 Oct 2022 13:50:09 +0200	[thread overview]
Message-ID: <20221017115010.21977-6-vegard.nossum@oracle.com> (raw)
In-Reply-To: <20221017115010.21977-1-vegard.nossum@oracle.com>

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@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


  parent reply	other threads:[~2022-10-17 11:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-17 11:50 git notes for the Linux kernel Vegard Nossum
2022-10-17 11:50 ` [PATCH 1/6] Support notes from external repositories Vegard Nossum
2022-10-17 11:50 ` [PATCH 3/6] git: handle diff_queue_is_empty() changes Vegard Nossum
2022-10-17 11:50 ` [PATCH 4/6] git: handle string_list_init_{nodup, dup}() changes for ctx.cfg.mimetypes Vegard Nossum
2022-10-17 11:50 ` Vegard Nossum [this message]
2022-10-17 12:12 ` git notes for the Linux kernel Vegard Nossum
2022-10-18 20:20 ` John Keeping

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221017115010.21977-6-vegard.nossum@oracle.com \
    --to=vegard.nossum@oracle.com \
    --cc=cgit@lists.zx2c4.com \
    --cc=konstantin@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).