Skip to content

Commit 04e60c0

Browse files
Ben Peartmjcheetham
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 43507e2 commit 04e60c0

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
@@ -2,6 +2,7 @@
22

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

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

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

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

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

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

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

1894+
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1895+
die("ident conversions not supported when running under GVFS");
1896+
18751897
if (!input) {
18761898
/* drain upon eof */
18771899
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
@@ -336,6 +336,43 @@ test_expect_success "filter: smudge empty file" '
336336
test_cmp expected filtered-empty-in-repo
337337
'
338338

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