Skip to content

Commit aa7cf7d

Browse files
Ben Peartdscho
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 <Ben.Peart@microsoft.com>
1 parent d07f7a1 commit aa7cf7d

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,5 +1,6 @@
11
#include "git-compat-util.h"
22
#include "advice.h"
3+
#include "gvfs.h"
34
#include "config.h"
45
#include "convert.h"
56
#include "copy.h"
@@ -555,6 +556,9 @@ static int crlf_to_git(struct index_state *istate,
555556
if (!buf)
556557
return 1;
557558

559+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
560+
die("CRLF conversions not supported when running under GVFS");
561+
558562
/* only grow if not in place */
559563
if (strbuf_avail(buf) + buf->len < len)
560564
strbuf_grow(buf, len - buf->len);
@@ -594,6 +598,9 @@ static int crlf_to_worktree(const char *src, size_t len, struct strbuf *buf,
594598
if (!will_convert_lf_to_crlf(&stats, crlf_action))
595599
return 0;
596600

601+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
602+
die("CRLF conversions not supported when running under GVFS");
603+
597604
/* are we "faking" in place editing ? */
598605
if (src == buf->buf)
599606
to_free = strbuf_detach(buf, NULL);
@@ -703,6 +710,9 @@ static int apply_single_file_filter(const char *path, const char *src, size_t le
703710
struct async async;
704711
struct filter_params params;
705712

713+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
714+
die("Filter \"%s\" not supported when running under GVFS", cmd);
715+
706716
memset(&async, 0, sizeof(async));
707717
async.proc = filter_buffer_or_fd;
708718
async.data = &params;
@@ -1116,6 +1126,9 @@ static int ident_to_git(const char *src, size_t len,
11161126
if (!buf)
11171127
return 1;
11181128

1129+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1130+
die("ident conversions not supported when running under GVFS");
1131+
11191132
/* only grow if not in place */
11201133
if (strbuf_avail(buf) + buf->len < len)
11211134
strbuf_grow(buf, len - buf->len);
@@ -1163,6 +1176,9 @@ static int ident_to_worktree(const char *src, size_t len,
11631176
if (!cnt)
11641177
return 0;
11651178

1179+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1180+
die("ident conversions not supported when running under GVFS");
1181+
11661182
/* are we "faking" in place editing ? */
11671183
if (src == buf->buf)
11681184
to_free = strbuf_detach(buf, NULL);
@@ -1612,6 +1628,9 @@ static int lf_to_crlf_filter_fn(struct stream_filter *filter,
16121628
size_t count, o = 0;
16131629
struct lf_to_crlf_filter *lf_to_crlf = (struct lf_to_crlf_filter *)filter;
16141630

1631+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1632+
die("CRLF conversions not supported when running under GVFS");
1633+
16151634
/*
16161635
* We may be holding onto the CR to see if it is followed by a
16171636
* LF, in which case we would need to go to the main loop.
@@ -1856,6 +1875,9 @@ static int ident_filter_fn(struct stream_filter *filter,
18561875
struct ident_filter *ident = (struct ident_filter *)filter;
18571876
static const char head[] = "$Id";
18581877

1878+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1879+
die("ident conversions not supported when running under GVFS");
1880+
18591881
if (!input) {
18601882
/* drain upon eof */
18611883
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
@@ -344,6 +344,18 @@ checkout_files () {
344344
"
345345
}
346346

347+
test_expect_success 'crlf conversions blocked when under GVFS' '
348+
git checkout -b gvfs &&
349+
test_commit initial &&
350+
rm initial.t &&
351+
test_config core.gvfs 64 &&
352+
test_config core.autocrlf true &&
353+
test_must_fail git read-tree --reset -u HEAD &&
354+
355+
git config core.autocrlf false &&
356+
git read-tree --reset -u HEAD
357+
'
358+
347359
# Test control characters
348360
# NUL SOH CR EOF==^Z
349361
test_expect_success 'ls-files --eol -o Text/Binary' '

0 commit comments

Comments
 (0)