Skip to content

Commit 4767665

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 <[email protected]>
1 parent e106776 commit 4767665

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed

Documentation/config/core.adoc

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

778787
core.sparseCheckout::

convert.c

Lines changed: 23 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,10 @@ static int crlf_to_git(struct index_state *istate,
563564
if (!buf)
564565
return 1;
565566

567+
if (gvfs_config_is_set(istate && istate->repo ? istate->repo : the_repository,
568+
GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
569+
die("CRLF conversions not supported when running under GVFS");
570+
566571
/* only grow if not in place */
567572
if (strbuf_avail(buf) + buf->len < len)
568573
strbuf_grow(buf, len - buf->len);
@@ -602,6 +607,9 @@ static int crlf_to_worktree(const char *src, size_t len, struct strbuf *buf,
602607
if (!will_convert_lf_to_crlf(&stats, crlf_action))
603608
return 0;
604609

610+
if (gvfs_config_is_set(the_repository, GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
611+
die("CRLF conversions not supported when running under GVFS");
612+
605613
/* are we "faking" in place editing ? */
606614
if (src == buf->buf)
607615
to_free = strbuf_detach(buf, NULL);
@@ -711,6 +719,9 @@ static int apply_single_file_filter(const char *path, const char *src, size_t le
711719
struct async async;
712720
struct filter_params params;
713721

722+
if (gvfs_config_is_set(the_repository, GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
723+
die("Filter \"%s\" not supported when running under GVFS", cmd);
724+
714725
memset(&async, 0, sizeof(async));
715726
async.proc = filter_buffer_or_fd;
716727
async.data = &params;
@@ -1130,6 +1141,9 @@ static int ident_to_git(const char *src, size_t len,
11301141
if (!buf)
11311142
return 1;
11321143

1144+
if (gvfs_config_is_set(the_repository, GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1145+
die("ident conversions not supported when running under GVFS");
1146+
11331147
/* only grow if not in place */
11341148
if (strbuf_avail(buf) + buf->len < len)
11351149
strbuf_grow(buf, len - buf->len);
@@ -1177,6 +1191,9 @@ static int ident_to_worktree(const char *src, size_t len,
11771191
if (!cnt)
11781192
return 0;
11791193

1194+
if (gvfs_config_is_set(the_repository, GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1195+
die("ident conversions not supported when running under GVFS");
1196+
11801197
/* are we "faking" in place editing ? */
11811198
if (src == buf->buf)
11821199
to_free = strbuf_detach(buf, NULL);
@@ -1629,6 +1646,9 @@ static int lf_to_crlf_filter_fn(struct stream_filter *filter,
16291646
size_t count, o = 0;
16301647
struct lf_to_crlf_filter *lf_to_crlf = (struct lf_to_crlf_filter *)filter;
16311648

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

1896+
if (gvfs_config_is_set(the_repository, GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
1897+
die("ident conversions not supported when running under GVFS");
1898+
18761899
if (!input) {
18771900
/* drain upon eof */
18781901
switch (ident->state) {

gvfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct repository;
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
int gvfs_config_is_set(struct repository *r, int mask);
2021

t/t0021-conversion.sh

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

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