]> git.ipfire.org Git - thirdparty/git.git/commitdiff
backfill: assume --sparse when sparse-checkout is enabled
authorDerrick Stolee <derrickstolee@github.com>
Mon, 3 Feb 2025 17:11:07 +0000 (17:11 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 4 Feb 2025 00:12:42 +0000 (16:12 -0800)
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>
Documentation/git-backfill.txt
builtin/backfill.c
t/t5620-backfill.sh

index a28678983e3f759ead3146cc1439bb0d482a5a27..95623051f789b29b704ac4ca8c12e98bc381a05c 100644 (file)
@@ -59,7 +59,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
 --------
index d7b997fd6f7d537968899c150c5cfc5c08f76233..d7ee84692f3d046dba45b1f2688feba5c2650a4b 100644 (file)
@@ -1,3 +1,6 @@
+/* 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"
@@ -5,6 +8,7 @@
 #include "repository.h"
 #include "commit.h"
 #include "dir.h"
+#include "environment.h"
 #include "hex.h"
 #include "tree.h"
 #include "tree-walk.h"
@@ -133,6 +137,9 @@ 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;
+
        result = do_backfill(&ctx);
        backfill_context_clear(&ctx);
        return result;
index 6b72e9d0e314808b83ce93a0e638e202aa8f925c..58c81556e72c899a6ff5a7a7d0169441bb62aa8f 100755 (executable)
@@ -77,6 +77,12 @@ test_expect_success 'do partial clone 2, backfill min 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           \
@@ -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 (positive)' '