[PATCH 0/8] fetch: refactor code that prints reference updates
From: Patrick Steinhardt <hidden>
Date: 2023-03-15 11:23:00
Hi,
at GitLab, we want to gain more control over fetches to achieve two
different things:
1. We want to take control of the reference updates so that we can
atomically update all or a subset of references that git-fetch
would have updated.
2. We want to be able to quarantine objects in a fetch so that we
can e.g. perform consistency checks for them before they land in
the main repository.
To do this, we aim to use git-fetch(1)'s `--dry-run` mode with a
manually set up quarantine directory. One issue we currently face though
is that git-fetch(1), to the best of my knowledge, has no mode in which
it would print all reference updates in a machine-parseable format.
I thus set out to implement a "porcelain"-style mode for git-fetch(1)
that surfaces this information:
- The reference that would be updated.
- The remote reference this is coming from.
- The old and new object IDs of the reference.
- Whether there's any error, like a D/F conflict.
I had a hard time understanding the current implementation of how ref
updates are printed though. So as a first step towards such a porcelain
mode this patch series refactors said code. It sets out to achieve two
major goals:
- There should be as few global state as possible. This is to reduce
confusion and having to repeat the same incantations in multiple
different locations.
- The logic should be as self-contained as possible. This is so that
it can easily be changed in a subsequent patch series.
This patch series does exactly that, but does not yet introduce the new
machine-parsebale porcelain mode.
Patrick
Patrick Steinhardt (8):
fetch: rename `display` buffer to avoid name conflict
fetch: move reference width calculation into `display_state`
fetch: move output format into `display_state`
fetch: pass the full local reference name to `format_display`
fetch: deduplicate handling of per-reference format
fetch: deduplicate logic to print remote URL
fetch: fix inconsistent summary width for pruned and updated refs
fetch: centralize printing of reference updates
builtin/fetch.c | 270 ++++++++++++++++++++++++------------------------
1 file changed, 134 insertions(+), 136 deletions(-)
--
2.40.0
Attachments
- signature.asc [application/pgp-signature] 833 bytes