Git fork

backfill: assume --sparse when sparse-checkout is enabled

The previous change introduced the '--[no-]sparse' option for the 'git
backfill' command, but did not assume it as enabled by default. However,
this is likely the behavior that users will most often want to happen.
Without this default, users with a small sparse-checkout may be confused
when 'git backfill' downloads every version of every object in the full
history.

However, this is left as a separate change so this decision can be reviewed
independently of the value of the '--[no-]sparse' option.

Add a test of adding the '--sparse' option to a repo without sparse-checkout
to make it clear that supplying it without a sparse-checkout is an error.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Derrick Stolee and committed by
Junio C Hamano
85127bcd bff45557

+21 -2
+2 -1
Documentation/git-backfill.txt
··· 59 59 60 60 `--[no-]sparse`:: 61 61 Only download objects if they appear at a path that matches the 62 - current sparse-checkout. 62 + current sparse-checkout. If the sparse-checkout feature is enabled, 63 + then `--sparse` is assumed and can be disabled with `--no-sparse`. 63 64 64 65 SEE ALSO 65 66 --------
+7
builtin/backfill.c
··· 1 + /* We need this macro to access core_apply_sparse_checkout */ 2 + #define USE_THE_REPOSITORY_VARIABLE 3 + 1 4 #include "builtin.h" 2 5 #include "git-compat-util.h" 3 6 #include "config.h" ··· 5 8 #include "repository.h" 6 9 #include "commit.h" 7 10 #include "dir.h" 11 + #include "environment.h" 8 12 #include "hex.h" 9 13 #include "tree.h" 10 14 #include "tree-walk.h" ··· 132 136 0); 133 137 134 138 repo_config(repo, git_default_config, NULL); 139 + 140 + if (ctx.sparse < 0) 141 + ctx.sparse = core_apply_sparse_checkout; 135 142 136 143 result = do_backfill(&ctx); 137 144 backfill_context_clear(&ctx);
+12 -1
t/t5620-backfill.sh
··· 77 77 test_line_count = 0 revs2 78 78 ' 79 79 80 + test_expect_success 'backfill --sparse without sparse-checkout fails' ' 81 + git init not-sparse && 82 + test_must_fail git -C not-sparse backfill --sparse 2>err && 83 + grep "problem loading sparse-checkout" err 84 + ' 85 + 80 86 test_expect_success 'backfill --sparse' ' 81 87 git clone --sparse --filter=blob:none \ 82 88 --single-branch --branch=main \ ··· 105 111 test_trace2_data promisor fetch_count 8 <sparse-trace2 && 106 112 test_trace2_data path-walk paths 15 <sparse-trace2 && 107 113 git -C backfill3 rev-list --quiet --objects --missing=print HEAD >missing && 108 - test_line_count = 24 missing 114 + test_line_count = 24 missing && 115 + 116 + # Disabling the --sparse option (on by default) will download everything 117 + git -C backfill3 backfill --no-sparse && 118 + git -C backfill3 rev-list --quiet --objects --missing=print HEAD >missing && 119 + test_line_count = 0 missing 109 120 ' 110 121 111 122 test_expect_success 'backfill --sparse without cone mode (positive)' '