Re: [PATCH] GIT_ONE_FILESYSTEM: flip the default to stop at filesystem boundaries
Junio C Hamano <gitster@pobox.com> writes:
Show 30 quoted lines
> I wonder if "git add" and friends should also notice it and warn. If
> you have more than one values of ce->ce_dev in the index, it means that
> the working tree spans more than one filesystem and from a subdirectory
> with an entry that has a ce->ce_dev different from the value for a path
> at the top of the work tree, you will not be able to discover the top
> of the tree without GIT_ONE_FILESYSTEM set to true. A likely scenario
> for this to happen would be:
>
> (1) You have a tarball of some sort; you extract it $there;
>
> $ mkdir $there && cd $there
> $ tar xf /var/tmp/tarball.tar
>
> (2) You notice the filesystem lacks enough free space, and move some
> part (say "images/") to a separate filesystem, and bind-mount;
>
> $ mv images $another/. && rm -fr images && mkdir images
> $ mount --bind $another/images images
>
> (3) You add everything to start the project;
>
> $ git init && git add .
>
> Up to this point it would work (you are at the top of the working
> tree). And this is the point we _could_ notice and warn that you
> will have trouble in step (4).
>
> (4) Go down to a subdirectory and start futzing;
>
> $ cd images && gimp naughty.jpg && git add -u
And this adds such a check.
read-cache.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index f1f789b..486bb2a 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1550,6 +1550,7 @@ int write_index(struct index_state *istate, int newfd)
struct cache_entry **cache = istate->cache;
int entries = istate->cache_nr;
struct stat st;
+ int more_than_one_dev;
for (i = removed = extended = 0; i < entries; i++) {
if (cache[i]->ce_flags & CE_REMOVE)
@@ -1572,6 +1573,7 @@ int write_index(struct index_state *istate, int newfd)
if (ce_write(&c, newfd, &hdr, sizeof(hdr)) < 0)
return -1;
+ more_than_one_dev = 0;
for (i = 0; i < entries; i++) {
struct cache_entry *ce = cache[i];
if (ce->ce_flags & CE_REMOVE)
@@ -1580,8 +1582,15 @@ int write_index(struct index_state *istate, int newfd)
ce_smudge_racily_clean_entry(ce);
if (ce_write_entry(&c, newfd, ce) < 0)
return -1;
+ if (i && ce->ce_dev != cache[0]->ce_dev)
+ more_than_one_dev = 1;
}
+ if (more_than_one_dev &&
+ !git_env_bool("GIT_DISCOVERY_ACROSS_FILESYSTEM", 0))
+ warning("working tree spans across filesystems but "
+ "GIT_DISCOVERY_ACROSS_FILESYSTEM is not set.");
+
/* Write extension data here */
if (istate->cache_tree) {
struct strbuf sb = STRBUF_INIT;