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>
This commit is contained in:
Ben Peart 2016-06-15 14:59:16 +00:00 коммит произвёл Johannes Schindelin
Родитель da1edf71d9
Коммит daf6bc41c9
5 изменённых файлов: 81 добавлений и 0 удалений

Просмотреть файл

@ -744,6 +744,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::

Просмотреть файл

@ -1,4 +1,5 @@
#include "cache.h"
#include "gvfs.h"
#include "config.h"
#include "object-store.h"
#include "attr.h"
@ -548,6 +549,9 @@ static int crlf_to_git(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);
@ -587,6 +591,9 @@ static int crlf_to_worktree(const char *src, size_t len, struct strbuf *buf,
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);
@ -698,6 +705,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;
@ -1109,6 +1119,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);
@ -1156,6 +1169,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);
@ -1605,6 +1621,9 @@ static int lf_to_crlf_filter_fn(struct stream_filter *filter,
size_t count, o = 0;
struct lf_to_crlf_filter *lf_to_crlf = (struct lf_to_crlf_filter *)filter;
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
die("CRLF conversions not supported when running under GVFS");
/*
* We may be holding onto the CR to see if it is followed by a
* LF, in which case we would need to go to the main loop.
@ -1849,6 +1868,9 @@ static int ident_filter_fn(struct stream_filter *filter,
struct ident_filter *ident = (struct ident_filter *)filter;
static const char head[] = "$Id";
if (gvfs_config_is_set(GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS))
die("ident conversions not supported when running under GVFS");
if (!input) {
/* drain upon eof */
switch (ident->state) {

1
gvfs.h
Просмотреть файл

@ -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;

Просмотреть файл

@ -338,6 +338,43 @@ 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 &&
test_must_fail git checkout -- ident.i
'
test_expect_success 'disable filter with empty override' '
test_config_global filter.disable.smudge false &&
test_config_global filter.disable.clean false &&

Просмотреть файл

@ -333,6 +333,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' '