Skip to content

Commit f665caa

Browse files
dschomjcheetham
authored andcommitted
Merge branch 'sparse-index-stuff'
This is random stuff that probably all got upstream in the meantime.
2 parents 17249b6 + 8f01a41 commit f665caa

14 files changed

+199
-17
lines changed

Documentation/config/index.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
index.deleteSparseDirectories::
2+
When enabled, the cone mode sparse-checkout feature will delete
3+
directories that are outside of the sparse-checkout cone, unless
4+
such a directory contains an untracked, non-ignored file. Defaults
5+
to true.
6+
17
index.recordEndOfIndexEntries::
28
Specifies whether the index file should include an "End Of Index
39
Entry" section. This reduces index load time on multiprocessor

builtin/add.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
#define USE_THE_REPOSITORY_VARIABLE
2+
13
/*
24
* "git add" builtin command
35
*
46
* Copyright (C) 2006 Linus Torvalds
57
*/
68
#include "builtin.h"
9+
#include "environment.h"
710
#include "advice.h"
811
#include "config.h"
912
#include "lockfile.h"
@@ -46,6 +49,7 @@ static int chmod_pathspec(struct repository *repo,
4649
int err;
4750

4851
if (!include_sparse &&
52+
!core_virtualfilesystem &&
4953
(ce_skip_worktree(ce) ||
5054
!path_in_sparse_checkout(ce->name, repo->index)))
5155
continue;
@@ -131,8 +135,9 @@ static int refresh(struct repository *repo, int verbose, const struct pathspec *
131135
if (!seen[i]) {
132136
const char *path = pathspec->items[i].original;
133137

134-
if (matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
135-
!path_in_sparse_checkout(path, repo->index)) {
138+
if (!core_virtualfilesystem &&
139+
(matches_skip_worktree(pathspec, i, &skip_worktree_seen) ||
140+
!path_in_sparse_checkout(path, repo->index))) {
136141
string_list_append(&only_match_skip_worktree,
137142
pathspec->items[i].original);
138143
} else {
@@ -142,7 +147,11 @@ static int refresh(struct repository *repo, int verbose, const struct pathspec *
142147
}
143148
}
144149

145-
if (only_match_skip_worktree.nr) {
150+
/*
151+
* When using a virtual filesystem, we might re-add a path
152+
* that is currently virtual and we want that to succeed.
153+
*/
154+
if (!core_virtualfilesystem && only_match_skip_worktree.nr) {
146155
advise_on_updating_sparse_paths(&only_match_skip_worktree);
147156
ret = 1;
148157
}
@@ -527,7 +536,11 @@ int cmd_add(int argc,
527536
if (seen[i])
528537
continue;
529538

530-
if (!include_sparse &&
539+
/*
540+
* When using a virtual filesystem, we might re-add a path
541+
* that is currently virtual and we want that to succeed.
542+
*/
543+
if (!include_sparse && !core_virtualfilesystem &&
531544
matches_skip_worktree(&pathspec, i, &skip_worktree_seen)) {
532545
string_list_append(&only_match_skip_worktree,
533546
pathspec.items[i].original);
@@ -551,7 +564,6 @@ int cmd_add(int argc,
551564
}
552565
}
553566

554-
555567
if (only_match_skip_worktree.nr) {
556568
advise_on_updating_sparse_paths(&only_match_skip_worktree);
557569
exit_status = 1;

builtin/reset.c

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include "add-interactive.h"
3939
#include "strbuf.h"
4040
#include "quote.h"
41+
#include "dir.h"
42+
#include "entry.h"
4143

4244
#define REFRESH_INDEX_DELAY_WARNING_IN_MS (2 * 1000)
4345

@@ -158,9 +160,48 @@ static void update_index_from_diff(struct diff_queue_struct *q,
158160

159161
for (i = 0; i < q->nr; i++) {
160162
int pos;
163+
int respect_skip_worktree = 1;
161164
struct diff_filespec *one = q->queue[i]->one;
165+
struct diff_filespec *two = q->queue[i]->two;
162166
int is_in_reset_tree = one->mode && !is_null_oid(&one->oid);
167+
int is_missing = !(one->mode && !is_null_oid(&one->oid));
168+
int was_missing = !two->mode && is_null_oid(&two->oid);
163169
struct cache_entry *ce;
170+
struct cache_entry *ceBefore;
171+
struct checkout state = CHECKOUT_INIT;
172+
173+
/*
174+
* When using the virtual filesystem feature, the cache entries that are
175+
* added here will not have the skip-worktree bit set.
176+
*
177+
* Without this code there is data that is lost because the files that
178+
* would normally be in the working directory are not there and show as
179+
* deleted for the next status or in the case of added files just disappear.
180+
* We need to create the previous version of the files in the working
181+
* directory so that they will have the right content and the next
182+
* status call will show modified or untracked files correctly.
183+
*/
184+
if (core_virtualfilesystem && !file_exists(two->path))
185+
{
186+
respect_skip_worktree = 0;
187+
pos = index_name_pos(the_repository->index, two->path, strlen(two->path));
188+
189+
if ((pos >= 0 && ce_skip_worktree(the_repository->index->cache[pos])) &&
190+
(is_missing || !was_missing))
191+
{
192+
state.force = 1;
193+
state.refresh_cache = 1;
194+
state.istate = the_repository->index;
195+
ceBefore = make_cache_entry(the_repository->index, two->mode,
196+
&two->oid, two->path,
197+
0, 0);
198+
if (!ceBefore)
199+
die(_("make_cache_entry failed for path '%s'"),
200+
two->path);
201+
202+
checkout_entry(ceBefore, &state, NULL, NULL);
203+
}
204+
}
164205

165206
if (!is_in_reset_tree && !intent_to_add) {
166207
remove_file_from_index(the_repository->index, one->path);
@@ -179,8 +220,14 @@ static void update_index_from_diff(struct diff_queue_struct *q,
179220
* to properly construct the reset sparse directory.
180221
*/
181222
pos = index_name_pos(the_repository->index, one->path, strlen(one->path));
182-
if ((pos >= 0 && ce_skip_worktree(the_repository->index->cache[pos])) ||
183-
(pos < 0 && !path_in_sparse_checkout(one->path, the_repository->index)))
223+
224+
/*
225+
* Do not add the SKIP_WORKTREE bit back if we populated the
226+
* file on purpose in a virtual filesystem scenario.
227+
*/
228+
if (respect_skip_worktree &&
229+
((pos >= 0 && ce_skip_worktree(the_repository->index->cache[pos])) ||
230+
(pos < 0 && !path_in_sparse_checkout(one->path, the_repository->index))))
184231
ce->ce_flags |= CE_SKIP_WORKTREE;
185232

186233
if (!ce)

builtin/rm.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#define USE_THE_REPOSITORY_VARIABLE
77
#include "builtin.h"
8+
#include "environment.h"
89
#include "advice.h"
910
#include "config.h"
1011
#include "lockfile.h"
@@ -314,7 +315,7 @@ int cmd_rm(int argc,
314315
for (i = 0; i < the_repository->index->cache_nr; i++) {
315316
const struct cache_entry *ce = the_repository->index->cache[i];
316317

317-
if (!include_sparse &&
318+
if (!include_sparse && !core_virtualfilesystem &&
318319
(ce_skip_worktree(ce) ||
319320
!path_in_sparse_checkout(ce->name, the_repository->index)))
320321
continue;
@@ -351,7 +352,11 @@ int cmd_rm(int argc,
351352
*original ? original : ".");
352353
}
353354

354-
if (only_match_skip_worktree.nr) {
355+
/*
356+
* When using a virtual filesystem, we might re-add a path
357+
* that is currently virtual and we want that to succeed.
358+
*/
359+
if (!core_virtualfilesystem && only_match_skip_worktree.nr) {
355360
advise_on_updating_sparse_paths(&only_match_skip_worktree);
356361
ret = 1;
357362
}

builtin/sparse-checkout.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static int sparse_checkout_list(int argc, const char **argv, const char *prefix)
108108

109109
static void clean_tracked_sparse_directories(struct repository *r)
110110
{
111-
int i, was_full = 0;
111+
int i, value, was_full = 0;
112112
struct strbuf path = STRBUF_INIT;
113113
size_t pathlen;
114114
struct string_list_item *item;
@@ -124,6 +124,13 @@ static void clean_tracked_sparse_directories(struct repository *r)
124124
!r->index->sparse_checkout_patterns->use_cone_patterns)
125125
return;
126126

127+
/*
128+
* Users can disable this behavior.
129+
*/
130+
if (!repo_config_get_bool(r, "index.deletesparsedirectories", &value) &&
131+
!value)
132+
return;
133+
127134
/*
128135
* Use the sparse index as a data structure to assist finding
129136
* directories that are safe to delete. This conversion to a

diff.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4044,6 +4044,13 @@ static int reuse_worktree_file(struct index_state *istate,
40444044
if (!FAST_WORKING_DIRECTORY && !want_file && has_object_pack(oid))
40454045
return 0;
40464046

4047+
/*
4048+
* If this path does not match our sparse-checkout definition,
4049+
* then the file will not be in the working directory.
4050+
*/
4051+
if (!path_in_sparse_checkout(name, istate))
4052+
return 0;
4053+
40474054
/*
40484055
* Similarly, if we'd have to convert the file contents anyway, that
40494056
* makes the optimization not worthwhile.

dir.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,13 @@ static int path_in_sparse_checkout_1(const char *path,
15781578
enum pattern_match_result match = UNDECIDED;
15791579
const char *end, *slash;
15801580

1581+
/*
1582+
* When using a virtual filesystem, there aren't really patterns
1583+
* to follow, but be extra careful to skip this check.
1584+
*/
1585+
if (core_virtualfilesystem)
1586+
return 1;
1587+
15811588
/*
15821589
* We default to accepting a path if the path is empty, there are no
15831590
* patterns, or the patterns are of the wrong type.

read-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3969,7 +3969,7 @@ static void update_callback(struct diff_queue_struct *q,
39693969
struct diff_filepair *p = q->queue[i];
39703970
const char *path = p->one->path;
39713971

3972-
if (!data->include_sparse &&
3972+
if (!data->include_sparse && !core_virtualfilesystem &&
39733973
!path_in_sparse_checkout(path, data->index))
39743974
continue;
39753975

repo-settings.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void prepare_repo_settings(struct repository *r)
6969
repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1);
7070
repo_cfg_bool(r, "pack.usepathwalk", &r->settings.pack_use_path_walk, 0);
7171
repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1);
72-
repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0);
72+
repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 1);
7373
repo_cfg_bool(r, "index.skiphash", &r->settings.index_skip_hash, r->settings.index_skip_hash);
7474
repo_cfg_bool(r, "pack.readreverseindex", &r->settings.pack_read_reverse_index, 1);
7575
repo_cfg_bool(r, "pack.usebitmapboundarytraversal",

sequencer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ static int do_recursive_merge(struct repository *r,
769769
o.branch2 = next ? next_label : "(empty tree)";
770770
if (is_rebase_i(opts))
771771
o.buffer_output = 2;
772-
o.show_rename_progress = 1;
772+
o.show_rename_progress = isatty(2);
773773

774774
head_tree = parse_tree_indirect(head);
775775
if (!head_tree)

0 commit comments

Comments
 (0)