Skip to content

Commit 08aefc9

Browse files
pcloudsgitster
authored andcommitted
unpack-trees(): "enable" sparse checkout and load $GIT_DIR/info/sparse-checkout
This patch introduces core.sparseCheckout, which will control whether sparse checkout support is enabled in unpack_trees() It also loads sparse-checkout file that will be used in the next patch. I split it out so the next patch will be shorter, easier to read. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 35a5aa7 commit 08aefc9

File tree

7 files changed

+48
-7
lines changed

7 files changed

+48
-7
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,10 @@ On some file system/operating system combinations, this is unreliable.
439439
Set this config setting to 'rename' there; However, This will remove the
440440
check that makes sure that existing object files will not get overwritten.
441441

442+
core.sparseCheckout::
443+
Enable "sparse checkout" feature. See section "Sparse checkout" in
444+
linkgit:git-read-tree[1] for more information.
445+
442446
add.ignore-errors::
443447
Tells 'git-add' to continue adding files when some files cannot be
444448
added due to indexing errors. Equivalent to the '--ignore-errors'

Documentation/git-read-tree.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,9 @@ follows:
401401
----------------
402402

403403
Then you can disable sparse checkout. Sparse checkout support in "git
404-
read-tree" and similar commands is disabled by default.
404+
read-tree" and similar commands is disabled by default. You need to
405+
turn `core.sparseCheckout` on in order to have sparse checkout
406+
support.
405407

406408

407409
SEE ALSO

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ extern size_t delta_base_cache_limit;
526526
extern int auto_crlf;
527527
extern int fsync_object_files;
528528
extern int core_preload_index;
529+
extern int core_apply_sparse_checkout;
529530

530531
enum safe_crlf {
531532
SAFE_CRLF_FALSE = 0,

config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,11 @@ static int git_default_core_config(const char *var, const char *value)
503503
return 0;
504504
}
505505

506+
if (!strcmp(var, "core.sparsecheckout")) {
507+
core_apply_sparse_checkout = git_config_bool(var, value);
508+
return 0;
509+
}
510+
506511
/* Add other config variables here and to Documentation/config.txt. */
507512
return 0;
508513
}

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ enum push_default_type push_default = PUSH_DEFAULT_MATCHING;
4848
#endif
4949
enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
5050
int grafts_replace_parents = 1;
51+
int core_apply_sparse_checkout;
5152

5253
/* Parallel index stat data preload? */
5354
int core_preload_index = 0;

unpack-trees.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
378378
{
379379
int ret;
380380
static struct cache_entry *dfc;
381+
struct exclude_list el;
381382

382383
if (len > MAX_UNPACK_TREES)
383384
die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
@@ -387,6 +388,16 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
387388
state.quiet = 1;
388389
state.refresh_cache = 1;
389390

391+
memset(&el, 0, sizeof(el));
392+
if (!core_apply_sparse_checkout || !o->update)
393+
o->skip_sparse_checkout = 1;
394+
if (!o->skip_sparse_checkout) {
395+
if (add_excludes_from_file_to_list(git_path("info/sparse-checkout"), "", 0, NULL, &el, 0) < 0)
396+
o->skip_sparse_checkout = 1;
397+
else
398+
o->el = &el;
399+
}
400+
390401
memset(&o->result, 0, sizeof(o->result));
391402
o->result.initialized = 1;
392403
if (o->src_index) {
@@ -407,26 +418,39 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
407418
info.fn = unpack_callback;
408419
info.data = o;
409420

410-
if (traverse_trees(len, t, &info) < 0)
411-
return unpack_failed(o, NULL);
421+
if (traverse_trees(len, t, &info) < 0) {
422+
ret = unpack_failed(o, NULL);
423+
goto done;
424+
}
412425
}
413426

414427
/* Any left-over entries in the index? */
415428
if (o->merge) {
416429
while (o->pos < o->src_index->cache_nr) {
417430
struct cache_entry *ce = o->src_index->cache[o->pos];
418-
if (unpack_index_entry(ce, o) < 0)
419-
return unpack_failed(o, NULL);
431+
if (unpack_index_entry(ce, o) < 0) {
432+
ret = unpack_failed(o, NULL);
433+
goto done;
434+
}
420435
}
421436
}
422437

423-
if (o->trivial_merges_only && o->nontrivial_merge)
424-
return unpack_failed(o, "Merge requires file-level merging");
438+
if (o->trivial_merges_only && o->nontrivial_merge) {
439+
ret = unpack_failed(o, "Merge requires file-level merging");
440+
goto done;
441+
}
425442

426443
o->src_index = NULL;
427444
ret = check_updates(o) ? (-2) : 0;
428445
if (o->dst_index)
429446
*o->dst_index = o->result;
447+
448+
done:
449+
for (i = 0;i < el.nr;i++)
450+
free(el.excludes[i]);
451+
if (el.excludes)
452+
free(el.excludes);
453+
430454
return ret;
431455
}
432456

unpack-trees.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#define MAX_UNPACK_TREES 8
55

66
struct unpack_trees_options;
7+
struct exclude_list;
78

89
typedef int (*merge_fn_t)(struct cache_entry **src,
910
struct unpack_trees_options *options);
@@ -28,6 +29,7 @@ struct unpack_trees_options {
2829
skip_unmerged,
2930
initial_checkout,
3031
diff_index_cached,
32+
skip_sparse_checkout,
3133
gently;
3234
const char *prefix;
3335
int pos;
@@ -44,6 +46,8 @@ struct unpack_trees_options {
4446
struct index_state *dst_index;
4547
struct index_state *src_index;
4648
struct index_state result;
49+
50+
struct exclude_list *el; /* for internal use */
4751
};
4852

4953
extern int unpack_trees(unsigned n, struct tree_desc *t,

0 commit comments

Comments
 (0)