Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Kristofer Karlsson <krka@spotify.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 06/10] commit-graph: move remaining write parameters into options
Date: Thu, 5 Nov 2026 14:20:50 +0100	[thread overview]
Message-ID: <auyCsmn6Hx_uc6zq@pks.im> (raw)
In-Reply-To: <CAL71e4N4BvO=eMfO0wnJ9=gGbfTRz5ayWFZULoN1dGSF7uCZAA@mail.gmail.com>

On Wed, Nov 04, 2026 at 06:49:50PM +0100, Kristofer Karlsson wrote:
> On Wed, 4 Nov 2026 at 17:15, Patrick Steinhardt <ps@pks.im> wrote:
> >
> >                 if (graph_write_mode != GRAPH_WRITE_TIPS)
> >                         write_opts.flags |= COMMIT_GRAPH_WRITE_REACHABLE;
> > +               else
> > +                       write_opts.commits = &updated_tips;
> 
> Ah, this touches on my previous patch cef2d8c4cb
> (fetch: write commit-graph using updated refs only, 2026-10-07).
> 
> My only nit would be that the if/else also covers the skip case,
> so one of the branches always fires for it.  A switch would make
> each mode set exactly what it needs:
> 
>   switch (graph_write_mode) {
>   case GRAPH_WRITE_SKIP:
>       break;
>   case GRAPH_WRITE_REACHABLE:
>       write_opts.flags |= COMMIT_GRAPH_WRITE_REACHABLE;
>       break;
>   case GRAPH_WRITE_TIPS:
>       write_opts.commits = &updated_tips;
>       break;
>   }
> 
> It doesn't matter for correctness since the skip case never calls
> the writer, but it looks easier to reason about to me.
> 
> But that's just a preference, I don't feel strongly about it.

I was wondering whether we want to maybe introduce a tagged union where
it becomes implicitly clear that some of the options only apply to a
specific mode. Something like this:

diff --git a/commit-graph.h b/commit-graph.h
index 2156499a688..8d53f80f179 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -160,7 +160,6 @@ enum commit_graph_write_flags {
 	COMMIT_GRAPH_WRITE_SPLIT      = (1 << 2),
 	COMMIT_GRAPH_WRITE_BLOOM_FILTERS = (1 << 3),
 	COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS = (1 << 4),
-	COMMIT_GRAPH_WRITE_REACHABLE  = (1 << 5),
 };
 
 enum commit_graph_split_flags {
@@ -170,9 +169,18 @@ enum commit_graph_split_flags {
 };
 
 struct commit_graph_write_options {
+	enum commit_graph_write_mode {
+		COMMIT_GRAPH_WRITE_ALL,
+		COMMIT_GRAPH_WRITE_REACHABLE,
+		COMMIT_GRAPH_WRITE_PACKS_INDEXES,
+		COMMIT_GRAPH_WRITE_COMMITS,
+	} mode;
+	union {
+		const struct string_list *pack_indexes;
+		struct oidset *commits;
+	} mode_args;
+
 	enum commit_graph_write_flags flags;
-	const struct string_list *pack_indexes;
-	struct oidset *commits;
 	int size_multiple;
 	int max_commits;
 	timestamp_t expire_time;

I wasn't really sure whether that complexity is really worth it, so for
now I decided to not pursue it. I think I still tend to stick with that
decision for now, but it's maybe something to keep in mind for the
future?

Patrick

  reply	other threads:[~2026-11-05 13:20 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 15:57 [PATCH 00/10] commit-graph: several refactorings for writing commit graphs Patrick Steinhardt
2026-11-04 15:57 ` [PATCH 01/10] commit-graph: rename `struct commit_graph_opts` Patrick Steinhardt
2026-11-04 15:57 ` [PATCH 02/10] commit-graph: pass writer flags via options Patrick Steinhardt
2026-11-04 15:57 ` [PATCH 03/10] commit-graph: drop `NULL` checks for write options Patrick Steinhardt
2026-11-04 15:57 ` [PATCH 04/10] commit-graph: drop redundant flags in write context Patrick Steinhardt
2026-11-04 19:18   ` Junio C Hamano
2026-11-04 15:57 ` [PATCH 05/10] commit-graph: merge the two commit graph writers Patrick Steinhardt
2026-11-04 16:33   ` Derrick Stolee
2026-11-04 15:57 ` [PATCH 06/10] commit-graph: move remaining write parameters into options Patrick Steinhardt
2026-11-04 16:34   ` Derrick Stolee
2026-11-04 17:49   ` Kristofer Karlsson
2026-11-05 13:20     ` Patrick Steinhardt [this message]
2026-11-05 15:07       ` Kristofer Karlsson
2026-11-04 15:57 ` [PATCH 07/10] commit-graph: fix mixup of write/verify flags Patrick Steinhardt
2026-11-04 15:57 ` [PATCH 08/10] builtin/commit-graph: set flags directly Patrick Steinhardt
2026-11-04 15:57 ` [PATCH 09/10] odb/source-files: verify commit-graphs as part of fsck Patrick Steinhardt
2026-11-04 15:57 ` [PATCH 10/10] commit-graph: modernize function names Patrick Steinhardt
2026-11-04 16:37 ` [PATCH 00/10] commit-graph: several refactorings for writing commit graphs Derrick Stolee
2026-11-05 13:55   ` Patrick Steinhardt
2026-11-05 13:57   ` Patrick Steinhardt
2026-11-05 15:18     ` Derrick Stolee
2026-11-05 15:33       ` Patrick Steinhardt

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=auyCsmn6Hx_uc6zq@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=krka@spotify.com \
    /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