Skip to content

Commit 96eaffe

Browse files
derrickstoleegitster
authored andcommitted
maintenance: set log.excludeDecoration durin prefetch
The 'prefetch' task fetches refs from all remotes and places them in the refs/prefetch/<remote>/ refspace. As this task is intended to run in the background, this allows users to keep their local data very close to the remote servers' data while not updating the users' understanding of the remote refs in refs/remotes/<remote>/. However, this can clutter 'git log' decorations with copies of the refs with the full name 'refs/prefetch/<remote>/<branch>'. The log.excludeDecoration config option was added in a6be5e6 (log: add log.excludeDecoration config option, 2020-05-16) for exactly this purpose. Ensure we set this only for users that would benefit from it by assigning it at the beginning of the prefetch task. Other alternatives would be during 'git maintenance register' or 'git maintenance start', but those might assign the config even when the prefetch task is disabled by existing config. Further, users could run 'git maintenance run --task=prefetch' using their own scripting or scheduling. This provides the best coverage to automatically update the config when valuable. It is improbable, but possible, that users might want to run the prefetch task _and_ see these refs in their log decorations. This seems incredibly unlikely to me, but users can always opt-in on a command-by-command basis using --decorate-refs=refs/prefetch/. Test that this works in a few cases. In particular, ensure that our assignment of log.excludeDecoration=refs/prefetch/ is additive to other existing exclusions. Further, ensure we do not add multiple copies in multiple runs. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Reviewed-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 66e871b commit 96eaffe

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

builtin/gc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,12 @@ static int maintenance_task_prefetch(struct maintenance_run_opts *opts)
897897
struct string_list_item *item;
898898
struct string_list remotes = STRING_LIST_INIT_DUP;
899899

900+
git_config_set_multivar_gently("log.excludedecoration",
901+
"refs/prefetch/",
902+
"refs/prefetch/",
903+
CONFIG_FLAGS_FIXED_VALUE |
904+
CONFIG_FLAGS_MULTI_REPLACE);
905+
900906
if (for_each_remote(append_remote, &remotes)) {
901907
error(_("failed to fill remotes"));
902908
result = 1;

t/t7900-maintenance.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,31 @@ test_expect_success 'prefetch multiple remotes' '
149149
git log prefetch/remote2/two &&
150150
git fetch --all &&
151151
test_cmp_rev refs/remotes/remote1/one refs/prefetch/remote1/one &&
152-
test_cmp_rev refs/remotes/remote2/two refs/prefetch/remote2/two
152+
test_cmp_rev refs/remotes/remote2/two refs/prefetch/remote2/two &&
153+
154+
test_cmp_config refs/prefetch/ log.excludedecoration &&
155+
git log --oneline --decorate --all >log &&
156+
! grep "prefetch" log
157+
'
158+
159+
test_expect_success 'prefetch and existing log.excludeDecoration values' '
160+
git config --unset-all log.excludeDecoration &&
161+
git config log.excludeDecoration refs/remotes/remote1/ &&
162+
git maintenance run --task=prefetch &&
163+
164+
git config --get-all log.excludeDecoration >out &&
165+
grep refs/remotes/remote1/ out &&
166+
grep refs/prefetch/ out &&
167+
168+
git log --oneline --decorate --all >log &&
169+
! grep "prefetch" log &&
170+
! grep "remote1" log &&
171+
grep "remote2" log &&
172+
173+
# a second run does not change the config
174+
git maintenance run --task=prefetch &&
175+
git log --oneline --decorate --all >log2 &&
176+
test_cmp log log2
153177
'
154178

155179
test_expect_success 'loose-objects task' '

0 commit comments

Comments
 (0)