Skip to content

Commit 7331eea

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 ff09727 commit 7331eea

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
@@ -774,6 +774,15 @@ core.gvfs::
774774
since these will be downloaded on demand. This flag will skip the
775775
checks on the reachability of objects during a fetch as well as
776776
the upload pack so that extraneous objects don't get downloaded.
777+
GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS::
778+
Bit value 64
779+
With a virtual file system we only know the file size before any
780+
CRLF or smudge/clean filters processing is done on the client.
781+
To prevent file corruption due to truncation or expansion with
782+
garbage at the end, these filters must not run when the file
783+
is first accessed and brought down to the client. Git.exe can't
784+
currently tell the first access vs subsequent accesses so this
785+
flag just blocks them from occurring at all.
777786
--
778787

779788
core.sparseCheckout::

convert.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "git-compat-util.h"
55
#include "advice.h"
6+
#include "gvfs.h"
67
#include "config.h"
78
#include "convert.h"
89
#include "copy.h"
@@ -563,6 +564,9 @@ static int crlf_to_git(struct index_state *istate,
563564
if (!buf)
564565
return 1;
565566

567+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
568+
die("CRLF conversions not supported when running under GVFS");
569+
566570
/* only grow if not in place */
567571
if (strbuf_avail(buf) + buf->len < len)
568572
strbuf_grow(buf, len - buf->len);
@@ -602,6 +606,9 @@ static int crlf_to_worktree(const char *src, size_t len, struct strbuf *buf,
602606
if (!will_convert_lf_to_crlf(&stats, crlf_action))
603607
return 0;
604608

609+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
610+
die("CRLF conversions not supported when running under GVFS");
611+
605612
/* are we "faking" in place editing ? */
606613
if (src == buf->buf)
607614
to_free = strbuf_detach(buf, NULL);
@@ -711,6 +718,9 @@ static int apply_single_file_filter(const char *path, const char *src, size_t le
711718
struct async async;
712719
struct filter_params params;
713720

721+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
722+
die("Filter \"%s\" not supported when running under GVFS", cmd);
723+
714724
memset(&async, 0, sizeof(async));
715725
async.proc = filter_buffer_or_fd;
716726
async.data = &params;
@@ -1130,6 +1140,9 @@ static int ident_to_git(const char *src, size_t len,
11301140
if (!buf)
11311141
return 1;
11321142

1143+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1144+
die("ident conversions not supported when running under GVFS");
1145+
11331146
/* only grow if not in place */
11341147
if (strbuf_avail(buf) + buf->len < len)
11351148
strbuf_grow(buf, len - buf->len);
@@ -1177,6 +1190,9 @@ static int ident_to_worktree(const char *src, size_t len,
11771190
if (!cnt)
11781191
return 0;
11791192

1193+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1194+
die("ident conversions not supported when running under GVFS");
1195+
11801196
/* are we "faking" in place editing ? */
11811197
if (src == buf->buf)
11821198
to_free = strbuf_detach(buf, NULL);
@@ -1629,6 +1645,9 @@ static int lf_to_crlf_filter_fn(struct stream_filter *filter,
16291645
size_t count, o = 0;
16301646
struct lf_to_crlf_filter *lf_to_crlf = (struct lf_to_crlf_filter *)filter;
16311647

1648+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1649+
die("CRLF conversions not supported when running under GVFS");
1650+
16321651
/*
16331652
* We may be holding onto the CR to see if it is followed by a
16341653
* LF, in which case we would need to go to the main loop.
@@ -1873,6 +1892,9 @@ static int ident_filter_fn(struct stream_filter *filter,
18731892
struct ident_filter *ident = (struct ident_filter *)filter;
18741893
static const char head[] = "$Id";
18751894

1895+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1896+
die("ident conversions not supported when running under GVFS");
1897+
18761898
if (!input) {
18771899
/* drain upon eof */
18781900
switch (ident->state) {

gvfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define GVFS_MISSING_OK (1 << 2)
1616
#define GVFS_NO_DELETE_OUTSIDE_SPARSECHECKOUT (1 << 3)
1717
#define GVFS_FETCH_SKIP_REACHABILITY_AND_UPLOADPACK (1 << 4)
18+
#define GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS (1 << 6)
1819

1920
void gvfs_load_config_value(const char *value);
2021
int gvfs_config_is_set(int 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
@@ -343,6 +343,18 @@ checkout_files () {
343343
"
344344
}
345345

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

0 commit comments

Comments
 (0)