Skip to content

Commit

Permalink
backfill: assume --sparse when sparse-checkout is enabled
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
derrickstolee committed Nov 8, 2024
1 parent 0e66529 commit c3a46e3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Documentation/git-backfill.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ OPTIONS

--[no-]sparse::
Only download objects if they appear at a path that matches the
current sparse-checkout.
current sparse-checkout. If the sparse-checkout feature is enabled,
then `--sparse` is assumed and can be disabled with `--no-sparse`.

SEE ALSO
--------
Expand Down
7 changes: 7 additions & 0 deletions builtin/backfill.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/* We need this macro to access core_apply_sparse_checkout */
#define USE_THE_REPOSITORY_VARIABLE

#include "builtin.h"
#include "git-compat-util.h"
#include "config.h"
#include "parse-options.h"
#include "repository.h"
#include "commit.h"
#include "dir.h"
#include "environment.h"
#include "hex.h"
#include "tree.h"
#include "tree-walk.h"
Expand Down Expand Up @@ -136,5 +140,8 @@ int cmd_backfill(int argc, const char **argv, const char *prefix, struct reposit

repo_config(repo, git_default_config, NULL);

if (ctx.sparse < 0)
ctx.sparse = core_apply_sparse_checkout;

return do_backfill(&ctx);
}
13 changes: 12 additions & 1 deletion t/t5620-backfill.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ test_expect_success 'do partial clone 2, backfill batch size' '
test_line_count = 0 revs2
'

test_expect_success 'backfill --sparse without sparse-checkout fails' '
git init not-sparse &&
test_must_fail git -C not-sparse backfill --sparse 2>err &&
grep "problem loading sparse-checkout" err
'

test_expect_success 'backfill --sparse' '
git clone --sparse --filter=blob:none \
--single-branch --branch=main \
Expand Down Expand Up @@ -105,7 +111,12 @@ test_expect_success 'backfill --sparse' '
test_trace2_data promisor fetch_count 8 <sparse-trace2 &&
test_trace2_data path-walk paths 15 <sparse-trace2 &&
git -C backfill3 rev-list --quiet --objects --missing=print HEAD >missing &&
test_line_count = 24 missing
test_line_count = 24 missing &&
# Disabling the --sparse option (on by default) will download everything
git -C backfill3 backfill --no-sparse &&
git -C backfill3 rev-list --quiet --objects --missing=print HEAD >missing &&
test_line_count = 0 missing
'

test_expect_success 'backfill --sparse without cone mode' '
Expand Down

0 comments on commit c3a46e3

Please sign in to comment.