Skip to content

Commit 36343ce

Browse files
Ben Peartderrickstolee
authored andcommitted
gvfs: ensure all filters and EOL conversions are blocked
Ensure all filters and EOL conversions are blocked when running under GVFS so that our projected file sizes will match the actual file size when it is hydrated on the local machine. Signed-off-by: Ben Peart <[email protected]>
1 parent 2d38fa4 commit 36343ce

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

Documentation/config/core.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,15 @@ core.gvfs::
759759
since these will be downloaded on demand. This flag will skip the
760760
checks on the reachability of objects during a fetch as well as
761761
the upload pack so that extraneous objects don't get downloaded.
762+
GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS::
763+
Bit value 64
764+
With a virtual file system we only know the file size before any
765+
CRLF or smudge/clean filters processing is done on the client.
766+
To prevent file corruption due to truncation or expansion with
767+
garbage at the end, these filters must not run when the file
768+
is first accessed and brought down to the client. Git.exe can't
769+
currently tell the first access vs subsequent accesses so this
770+
flag just blocks them from occurring at all.
762771
--
763772

764773
core.sparseCheckout::

convert.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "cache.h"
2+
#include "gvfs.h"
23
#include "config.h"
34
#include "object-store.h"
45
#include "attr.h"
@@ -548,6 +549,9 @@ static int crlf_to_git(struct index_state *istate,
548549
if (!buf)
549550
return 1;
550551

552+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
553+
die("CRLF conversions not supported when running under GVFS");
554+
551555
/* only grow if not in place */
552556
if (strbuf_avail(buf) + buf->len < len)
553557
strbuf_grow(buf, len - buf->len);
@@ -587,6 +591,9 @@ static int crlf_to_worktree(const char *src, size_t len, struct strbuf *buf,
587591
if (!will_convert_lf_to_crlf(&stats, crlf_action))
588592
return 0;
589593

594+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
595+
die("CRLF conversions not supported when running under GVFS");
596+
590597
/* are we "faking" in place editing ? */
591598
if (src == buf->buf)
592599
to_free = strbuf_detach(buf, NULL);
@@ -698,6 +705,9 @@ static int apply_single_file_filter(const char *path, const char *src, size_t le
698705
struct async async;
699706
struct filter_params params;
700707

708+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
709+
die("Filter \"%s\" not supported when running under GVFS", cmd);
710+
701711
memset(&async, 0, sizeof(async));
702712
async.proc = filter_buffer_or_fd;
703713
async.data = &params;
@@ -1109,6 +1119,9 @@ static int ident_to_git(const char *src, size_t len,
11091119
if (!buf)
11101120
return 1;
11111121

1122+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1123+
die("ident conversions not supported when running under GVFS");
1124+
11121125
/* only grow if not in place */
11131126
if (strbuf_avail(buf) + buf->len < len)
11141127
strbuf_grow(buf, len - buf->len);
@@ -1156,6 +1169,9 @@ static int ident_to_worktree(const char *src, size_t len,
11561169
if (!cnt)
11571170
return 0;
11581171

1172+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1173+
die("ident conversions not supported when running under GVFS");
1174+
11591175
/* are we "faking" in place editing ? */
11601176
if (src == buf->buf)
11611177
to_free = strbuf_detach(buf, NULL);
@@ -1605,6 +1621,9 @@ static int lf_to_crlf_filter_fn(struct stream_filter *filter,
16051621
size_t count, o = 0;
16061622
struct lf_to_crlf_filter *lf_to_crlf = (struct lf_to_crlf_filter *)filter;
16071623

1624+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1625+
die("CRLF conversions not supported when running under GVFS");
1626+
16081627
/*
16091628
* We may be holding onto the CR to see if it is followed by a
16101629
* LF, in which case we would need to go to the main loop.
@@ -1849,6 +1868,9 @@ static int ident_filter_fn(struct stream_filter *filter,
18491868
struct ident_filter *ident = (struct ident_filter *)filter;
18501869
static const char head[] = "$Id";
18511870

1871+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1872+
die("ident conversions not supported when running under GVFS");
1873+
18521874
if (!input) {
18531875
/* drain upon eof */
18541876
switch (ident->state) {

gvfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define GVFS_MISSING_OK (1 << 2)
1818
#define GVFS_NO_DELETE_OUTSIDE_SPARSECHECKOUT (1 << 3)
1919
#define GVFS_FETCH_SKIP_REACHABILITY_AND_UPLOADPACK (1 << 4)
20+
#define GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS (1 << 6)
2021

2122
static inline int gvfs_config_is_set(int mask) {
2223
return (core_gvfs & mask) == mask;

t/t0021-conversion.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,43 @@ test_expect_success "filter: smudge empty file" '
335335
test_cmp expected filtered-empty-in-repo
336336
'
337337

338+
test_expect_success "filter: clean filters blocked when under GVFS" '
339+
test_config filter.empty-in-repo.clean "cat >/dev/null" &&
340+
test_config filter.empty-in-repo.smudge "echo smudged && cat" &&
341+
test_config core.gvfs 64 &&
342+
343+
echo dead data walking >empty-in-repo &&
344+
test_must_fail git add empty-in-repo
345+
'
346+
347+
test_expect_success "filter: smudge filters blocked when under GVFS" '
348+
test_config filter.empty-in-repo.clean "cat >/dev/null" &&
349+
test_config filter.empty-in-repo.smudge "echo smudged && cat" &&
350+
test_config core.gvfs 64 &&
351+
352+
test_must_fail git checkout
353+
'
354+
355+
test_expect_success "ident blocked on add when under GVFS" '
356+
test_config core.gvfs 64 &&
357+
test_config core.autocrlf false &&
358+
359+
echo "*.i ident" >.gitattributes &&
360+
echo "\$Id\$" > ident.i &&
361+
362+
test_must_fail git add ident.i
363+
'
364+
365+
test_expect_success "ident blocked when under GVFS" '
366+
git add ident.i &&
367+
368+
git commit -m "added ident.i" &&
369+
test_config core.gvfs 64 &&
370+
rm ident.i &&
371+
372+
test_must_fail git checkout -- ident.i
373+
'
374+
338375
test_expect_success 'disable filter with empty override' '
339376
test_config_global filter.disable.smudge false &&
340377
test_config_global filter.disable.clean false &&

t/t0027-auto-crlf.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,18 @@ checkout_files () {
334334
"
335335
}
336336

337+
test_expect_success 'crlf conversions blocked when under GVFS' '
338+
git checkout -b gvfs &&
339+
test_commit initial &&
340+
rm initial.t &&
341+
test_config core.gvfs 64 &&
342+
test_config core.autocrlf true &&
343+
test_must_fail git read-tree --reset -u HEAD &&
344+
345+
git config core.autocrlf false &&
346+
git read-tree --reset -u HEAD
347+
'
348+
337349
# Test control characters
338350
# NUL SOH CR EOF==^Z
339351
test_expect_success 'ls-files --eol -o Text/Binary' '

0 commit comments

Comments
 (0)