Skip to content

Commit 3c0e417

Browse files
committed
Merge branch 'ds/fetch-pull-with-sparse-index'
"git fetch" and "git pull" are now declared sparse-index clean. Also "git ls-files" learns the "--sparse" option to help debugging. * ds/fetch-pull-with-sparse-index: test-read-cache: remove --table, --expand options t1091/t3705: remove 'test-tool read-cache --table' t1092: replace 'read-cache --table' with 'ls-files --sparse' ls-files: add --sparse option fetch/pull: use the sparse index
2 parents b48c69c + 408c51f commit 3c0e417

File tree

8 files changed

+168
-82
lines changed

8 files changed

+168
-82
lines changed

Documentation/git-ls-files.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ Both the <eolinfo> in the index ("i/<eolinfo>")
187187
and in the working tree ("w/<eolinfo>") are shown for regular files,
188188
followed by the ("attr/<eolattr>").
189189

190+
--sparse::
191+
If the index is sparse, show the sparse directories without expanding
192+
to the contained files. Sparse directories will be shown with a
193+
trailing slash, such as "x/" for a sparse directory "x".
194+
190195
\--::
191196
Do not interpret any more arguments as options.
192197

builtin/fetch.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
20092009
}
20102010

20112011
git_config(git_fetch_config, NULL);
2012+
prepare_repo_settings(the_repository);
2013+
the_repository->settings.command_requires_full_index = 0;
20122014

20132015
argc = parse_options(argc, argv, prefix,
20142016
builtin_fetch_options, builtin_fetch_usage, 0);

builtin/ls-files.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static int debug_mode;
3737
static int show_eol;
3838
static int recurse_submodules;
3939
static int skipping_duplicates;
40+
static int show_sparse_dirs;
4041

4142
static const char *prefix;
4243
static int max_prefix_len;
@@ -315,8 +316,10 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
315316

316317
if (!(show_cached || show_stage || show_deleted || show_modified))
317318
return;
318-
/* TODO: audit for interaction with sparse-index. */
319-
ensure_full_index(repo->index);
319+
320+
if (!show_sparse_dirs)
321+
ensure_full_index(repo->index);
322+
320323
for (i = 0; i < repo->index->cache_nr; i++) {
321324
const struct cache_entry *ce = repo->index->cache[i];
322325
struct stat st;
@@ -670,13 +673,18 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
670673
OPT_BOOL(0, "debug", &debug_mode, N_("show debugging data")),
671674
OPT_BOOL(0, "deduplicate", &skipping_duplicates,
672675
N_("suppress duplicate entries")),
676+
OPT_BOOL(0, "sparse", &show_sparse_dirs,
677+
N_("show sparse directories in the presence of a sparse index")),
673678
OPT_END()
674679
};
675680
int ret = 0;
676681

677682
if (argc == 2 && !strcmp(argv[1], "-h"))
678683
usage_with_options(ls_files_usage, builtin_ls_files_options);
679684

685+
prepare_repo_settings(the_repository);
686+
the_repository->settings.command_requires_full_index = 0;
687+
680688
prefix = cmd_prefix;
681689
if (prefix)
682690
prefix_len = strlen(prefix);

builtin/pull.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
994994
set_reflog_message(argc, argv);
995995

996996
git_config(git_pull_config, NULL);
997+
prepare_repo_settings(the_repository);
998+
the_repository->settings.command_requires_full_index = 0;
997999

9981000
argc = parse_options(argc, argv, prefix, pull_options, pull_usage, 0);
9991001

t/helper/test-read-cache.c

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,39 @@
11
#include "test-tool.h"
22
#include "cache.h"
33
#include "config.h"
4-
#include "blob.h"
5-
#include "commit.h"
6-
#include "tree.h"
7-
#include "sparse-index.h"
8-
9-
static void print_cache_entry(struct cache_entry *ce)
10-
{
11-
const char *type;
12-
printf("%06o ", ce->ce_mode & 0177777);
13-
14-
if (S_ISSPARSEDIR(ce->ce_mode))
15-
type = tree_type;
16-
else if (S_ISGITLINK(ce->ce_mode))
17-
type = commit_type;
18-
else
19-
type = blob_type;
20-
21-
printf("%s %s\t%s\n",
22-
type,
23-
oid_to_hex(&ce->oid),
24-
ce->name);
25-
}
26-
27-
static void print_cache(struct index_state *istate)
28-
{
29-
int i;
30-
for (i = 0; i < istate->cache_nr; i++)
31-
print_cache_entry(istate->cache[i]);
32-
}
334

345
int cmd__read_cache(int argc, const char **argv)
356
{
36-
struct repository *r = the_repository;
377
int i, cnt = 1;
388
const char *name = NULL;
39-
int table = 0, expand = 0;
409

4110
initialize_the_repository();
4211

43-
for (++argv, --argc; *argv && starts_with(*argv, "--"); ++argv, --argc) {
44-
if (skip_prefix(*argv, "--print-and-refresh=", &name))
45-
continue;
46-
if (!strcmp(*argv, "--table"))
47-
table = 1;
48-
else if (!strcmp(*argv, "--expand"))
49-
expand = 1;
12+
if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
13+
argc--;
14+
argv++;
5015
}
5116

52-
if (argc == 1)
53-
cnt = strtol(argv[0], NULL, 0);
17+
if (argc == 2)
18+
cnt = strtol(argv[1], NULL, 0);
5419
setup_git_directory();
5520
git_config(git_default_config, NULL);
5621

57-
prepare_repo_settings(r);
58-
r->settings.command_requires_full_index = 0;
59-
6022
for (i = 0; i < cnt; i++) {
61-
repo_read_index(r);
62-
63-
if (expand)
64-
ensure_full_index(r->index);
65-
23+
read_cache();
6624
if (name) {
6725
int pos;
6826

69-
refresh_index(r->index, REFRESH_QUIET,
27+
refresh_index(&the_index, REFRESH_QUIET,
7028
NULL, NULL, NULL);
71-
pos = index_name_pos(r->index, name, strlen(name));
29+
pos = index_name_pos(&the_index, name, strlen(name));
7230
if (pos < 0)
7331
die("%s not in index", name);
7432
printf("%s is%s up to date\n", name,
75-
ce_uptodate(r->index->cache[pos]) ? "" : " not");
33+
ce_uptodate(the_index.cache[pos]) ? "" : " not");
7634
write_file(name, "%d\n", i);
7735
}
78-
if (table)
79-
print_cache(r->index);
80-
discard_index(r->index);
36+
discard_cache();
8137
}
8238
return 0;
8339
}

t/t1091-sparse-checkout-builtin.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,27 @@ test_expect_success 'sparse-index enabled and disabled' '
234234
235235
git -C repo sparse-checkout init --cone --sparse-index &&
236236
test_cmp_config -C repo true index.sparse &&
237-
test-tool -C repo read-cache --table >cache &&
238-
grep " tree " cache &&
239-
237+
git -C repo ls-files --sparse >sparse &&
240238
git -C repo sparse-checkout disable &&
241-
test-tool -C repo read-cache --table >cache &&
242-
! grep " tree " cache &&
239+
git -C repo ls-files --sparse >full &&
240+
241+
cat >expect <<-\EOF &&
242+
@@ -1,4 +1,7 @@
243+
a
244+
-deep/
245+
-folder1/
246+
-folder2/
247+
+deep/a
248+
+deep/deeper1/a
249+
+deep/deeper1/deepest/a
250+
+deep/deeper2/a
251+
+folder1/a
252+
+folder2/a
253+
EOF
254+
255+
diff -u sparse full | tail -n +3 >actual &&
256+
test_cmp expect actual &&
257+
243258
git -C repo config --list >config &&
244259
! grep index.sparse config
245260
)

0 commit comments

Comments
 (0)