Skip to content

Commit

Permalink
gvfs: ensure all filters and EOL conversions are blocked
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ben Peart authored and dscho committed Feb 27, 2019
1 parent 0253f80 commit a82642b
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Documentation/config/core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,15 @@ core.gvfs::
since these will be downloaded on demand. This flag will skip the
checks on the reachability of objects during a fetch as well as
the upload pack so that extraneous objects don't get downloaded.
GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS::
Bit value 64
With a virtual file system we only know the file size before any
CRLF or smudge/clean filters processing is done on the client.
To prevent file corruption due to truncation or expansion with
garbage at the end, these filters must not run when the file
is first accessed and brought down to the client. Git.exe can't
currently tell the first access vs subsequent accesses so this
flag just blocks them from occurring at all.
--

core.sparseCheckout::
Expand Down
16 changes: 16 additions & 0 deletions convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "pkt-line.h"
#include "sub-process.h"
#include "utf8.h"
#include "gvfs.h"

/*
* convert.c - convert a file when checking it out and checking it in.
Expand Down Expand Up @@ -564,6 +565,9 @@ static int crlf_to_git(const struct index_state *istate,
if (!buf)
return 1;

if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
die("CRLF conversions not supported when running under GVFS");

/* only grow if not in place */
if (strbuf_avail(buf) + buf->len < len)
strbuf_grow(buf, len - buf->len);
Expand Down Expand Up @@ -603,6 +607,9 @@ static int crlf_to_worktree(const char *src, size_t len,
if (!will_convert_lf_to_crlf(&stats, crlf_action))
return 0;

if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
die("CRLF conversions not supported when running under GVFS");

/* are we "faking" in place editing ? */
if (src == buf->buf)
to_free = strbuf_detach(buf, NULL);
Expand Down Expand Up @@ -717,6 +724,9 @@ static int apply_single_file_filter(const char *path, const char *src, size_t le
struct async async;
struct filter_params params;

if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
die("Filter \"%s\" not supported when running under GVFS", cmd);

memset(&async, 0, sizeof(async));
async.proc = filter_buffer_or_fd;
async.data = &params;
Expand Down Expand Up @@ -1101,6 +1111,9 @@ static int ident_to_git(const char *src, size_t len,
if (!buf)
return 1;

if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
die("ident conversions not supported when running under GVFS");

/* only grow if not in place */
if (strbuf_avail(buf) + buf->len < len)
strbuf_grow(buf, len - buf->len);
Expand Down Expand Up @@ -1148,6 +1161,9 @@ static int ident_to_worktree(const char *src, size_t len,
if (!cnt)
return 0;

if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
die("ident conversions not supported when running under GVFS");

/* are we "faking" in place editing ? */
if (src == buf->buf)
to_free = strbuf_detach(buf, NULL);
Expand Down
1 change: 1 addition & 0 deletions gvfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define GVFS_MISSING_OK (1 << 2)
#define GVFS_NO_DELETE_OUTSIDE_SPARSECHECKOUT (1 << 3)
#define GVFS_FETCH_SKIP_REACHABILITY_AND_UPLOADPACK (1 << 4)
#define GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS (1 << 6)

static inline int gvfs_config_is_set(int mask) {
return (core_gvfs & mask) == mask;
Expand Down
38 changes: 38 additions & 0 deletions t/t0021-conversion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,44 @@ test_expect_success "filter: smudge empty file" '
test_cmp expected filtered-empty-in-repo
'

test_expect_success "filter: clean filters blocked when under GVFS" '
test_config filter.empty-in-repo.clean "cat >/dev/null" &&
test_config filter.empty-in-repo.smudge "echo smudged && cat" &&
test_config core.gvfs 64 &&
echo dead data walking >empty-in-repo &&
test_must_fail git add empty-in-repo
'

test_expect_success "filter: smudge filters blocked when under GVFS" '
test_config filter.empty-in-repo.clean "cat >/dev/null" &&
test_config filter.empty-in-repo.smudge "echo smudged && cat" &&
test_config core.gvfs 64 &&
test_must_fail git checkout
'

test_expect_success "ident blocked on add when under GVFS" '
test_config core.gvfs 64 &&
test_config core.autocrlf false &&
echo "*.i ident" >.gitattributes &&
echo "\$Id\$" > ident.i &&
test_must_fail git add ident.i
'

test_expect_success "ident blocked when under GVFS" '
git add ident.i &&
git commit -m "added ident.i" &&
test_config core.gvfs 64 &&
rm ident.i &&
git checkout -- ident.i &&
test_must_fail git status
'

test_expect_success 'disable filter with empty override' '
test_config_global filter.disable.smudge false &&
test_config_global filter.disable.clean false &&
Expand Down
12 changes: 12 additions & 0 deletions t/t0027-auto-crlf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,18 @@ checkout_files () {
"
}

test_expect_success 'crlf conversions blocked when under GVFS' '
git checkout -b gvfs &&
test_commit initial &&
rm initial.t &&
test_config core.gvfs 64 &&
test_config core.autocrlf true &&
test_must_fail git read-tree --reset -u HEAD &&
git config core.autocrlf false &&
git read-tree --reset -u HEAD
'

# Test control characters
# NUL SOH CR EOF==^Z
test_expect_success 'ls-files --eol -o Text/Binary' '
Expand Down

0 comments on commit a82642b

Please sign in to comment.