@matheusbsbs / matheus-bagliano / commits / 08aefc9e47
Fork 0

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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Aug 20, 2009 at 20:47 UTC 08aefc9e47eb2eaf231352223c939d69b0fb3759
7 files changed +48 -7
Documentation/config.txt
+4
@@ -439,6 +439,10 @@ On some file system/operating system combinations, this is unreliable.
439 Set this config setting to 'rename' there; However, This will remove the
440 check that makes sure that existing object files will not get overwritten.
441
442 +core.sparseCheckout::
443 + Enable "sparse checkout" feature. See section "Sparse checkout" in
444 + linkgit:git-read-tree[1] for more information.
445 +
446 add.ignore-errors::
447 Tells 'git-add' to continue adding files when some files cannot be
448 added due to indexing errors. Equivalent to the '--ignore-errors'
Documentation/git-read-tree.txt
+3 -1
@@ -401,7 +401,9 @@ follows:
401 ----------------
402
403 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.
407
408
409 SEE ALSO
cache.h
+1
@@ -526,6 +526,7 @@ extern size_t delta_base_cache_limit;
526 extern int auto_crlf;
527 extern int fsync_object_files;
528 extern int core_preload_index;
529 +extern int core_apply_sparse_checkout;
530
531 enum safe_crlf {
532 SAFE_CRLF_FALSE = 0,
config.c
+5
@@ -503,6 +503,11 @@ static int git_default_core_config(const char *var, const char *value)
503 return 0;
504 }
505
506 + if (!strcmp(var, "core.sparsecheckout")) {
507 + core_apply_sparse_checkout = git_config_bool(var, value);
508 + return 0;
509 + }
510 +
511 /* Add other config variables here and to Documentation/config.txt. */
512 return 0;
513 }
environment.c
+1
@@ -48,6 +48,7 @@ enum push_default_type push_default = PUSH_DEFAULT_MATCHING;
48 #endif
49 enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
50 int grafts_replace_parents = 1;
51 +int core_apply_sparse_checkout;
52
53 /* Parallel index stat data preload? */
54 int core_preload_index = 0;
unpack-trees.c
+30 -6
@@ -378,6 +378,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
378 {
379 int ret;
380 static struct cache_entry *dfc;
381 + struct exclude_list el;
382
383 if (len > MAX_UNPACK_TREES)
384 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
388 state.quiet = 1;
389 state.refresh_cache = 1;
390
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 +
401 memset(&o->result, 0, sizeof(o->result));
402 o->result.initialized = 1;
403 if (o->src_index) {
@@ -407,26 +418,39 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
418 info.fn = unpack_callback;
419 info.data = o;
420
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 + }
425 }
426
427 /* Any left-over entries in the index? */
428 if (o->merge) {
429 while (o->pos < o->src_index->cache_nr) {
430 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 + }
435 }
436 }
437
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 + }
442
443 o->src_index = NULL;
444 ret = check_updates(o) ? (-2) : 0;
445 if (o->dst_index)
446 *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 +
454 return ret;
455 }
456
unpack-trees.h
+4
@@ -4,6 +4,7 @@
4 #define MAX_UNPACK_TREES 8
5
6 struct unpack_trees_options;
7 +struct exclude_list;
8
9 typedef int (*merge_fn_t)(struct cache_entry **src,
10 struct unpack_trees_options *options);
@@ -28,6 +29,7 @@ struct unpack_trees_options {
29 skip_unmerged,
30 initial_checkout,
31 diff_index_cached,
32 + skip_sparse_checkout,
33 gently;
34 const char *prefix;
35 int pos;
@@ -44,6 +46,8 @@ struct unpack_trees_options {
46 struct index_state *dst_index;
47 struct index_state *src_index;
48 struct index_state result;
49 +
50 + struct exclude_list *el; /* for internal use */
51 };
52
53 extern int unpack_trees(unsigned n, struct tree_desc *t,