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 1/6] Support notes from external repositories
Date: Mon, 17 Oct 2022 13:50:05 +0200	[thread overview]
Message-ID: <20221017115010.21977-2-vegard.nossum@oracle.com> (raw)
In-Reply-To: <20221017115010.21977-1-vegard.nossum@oracle.com>

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


  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 ` Vegard Nossum [this message]
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 ` [PATCH 5/6] cgit: add extra alternates Vegard Nossum
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-2-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).