mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 13:04:42 +00:00
Merge pull request #1254 from ethomson/index_filtered_size
cache should contain on-disk (filtered) file size
This commit is contained in:
commit
56af285c80
@ -724,10 +724,8 @@ static int blob_content_to_file(
|
|||||||
error = buffer_to_file(
|
error = buffer_to_file(
|
||||||
st, &filtered, path, opts->dir_mode, opts->file_open_flags, file_mode);
|
st, &filtered, path, opts->dir_mode, opts->file_open_flags, file_mode);
|
||||||
|
|
||||||
if (!error) {
|
if (!error)
|
||||||
st->st_size = blob->odb_object->raw.len;
|
|
||||||
st->st_mode = entry_filemode;
|
st->st_mode = entry_filemode;
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
git_filters_free(&filters);
|
git_filters_free(&filters);
|
||||||
|
106
tests-clar/checkout/crlf.c
Normal file
106
tests-clar/checkout/crlf.c
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
#include "clar_libgit2.h"
|
||||||
|
#include "checkout_helpers.h"
|
||||||
|
|
||||||
|
#include "git2/checkout.h"
|
||||||
|
#include "repository.h"
|
||||||
|
|
||||||
|
#define UTF8_BOM "\xEF\xBB\xBF"
|
||||||
|
#define ALL_CRLF_TEXT_RAW "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n"
|
||||||
|
#define ALL_LF_TEXT_RAW "lf\nlf\nlf\nlf\nlf\n"
|
||||||
|
#define MORE_CRLF_TEXT_RAW "crlf\r\ncrlf\r\nlf\ncrlf\r\ncrlf\r\n"
|
||||||
|
#define MORE_LF_TEXT_RAW "lf\nlf\ncrlf\r\nlf\nlf\n"
|
||||||
|
|
||||||
|
#define ALL_LF_TEXT_AS_CRLF "lf\r\nlf\r\nlf\r\nlf\r\nlf\r\n"
|
||||||
|
|
||||||
|
static git_repository *g_repo;
|
||||||
|
|
||||||
|
void test_checkout_crlf__initialize(void)
|
||||||
|
{
|
||||||
|
git_tree *tree;
|
||||||
|
|
||||||
|
g_repo = cl_git_sandbox_init("crlf");
|
||||||
|
|
||||||
|
cl_git_pass(git_repository_head_tree(&tree, g_repo));
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_checkout_crlf__cleanup(void)
|
||||||
|
{
|
||||||
|
cl_git_sandbox_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_config_entry_to(const char *entry_name, bool value)
|
||||||
|
{
|
||||||
|
git_config *cfg;
|
||||||
|
|
||||||
|
cl_git_pass(git_repository_config(&cfg, g_repo));
|
||||||
|
cl_git_pass(git_config_set_bool(cfg, entry_name, value));
|
||||||
|
|
||||||
|
git_config_free(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_core_autocrlf_to(bool value)
|
||||||
|
{
|
||||||
|
set_config_entry_to("core.autocrlf", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_checkout_crlf__detect_crlf_autocrlf_false(void)
|
||||||
|
{
|
||||||
|
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
|
||||||
|
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
|
||||||
|
|
||||||
|
set_core_autocrlf_to(false);
|
||||||
|
|
||||||
|
git_checkout_head(g_repo, &opts);
|
||||||
|
|
||||||
|
test_file_contents("./crlf/all-lf", ALL_LF_TEXT_RAW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void)
|
||||||
|
{
|
||||||
|
git_index *index;
|
||||||
|
const git_index_entry *entry;
|
||||||
|
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
|
||||||
|
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
|
||||||
|
|
||||||
|
set_core_autocrlf_to(false);
|
||||||
|
|
||||||
|
git_checkout_head(g_repo, &opts);
|
||||||
|
|
||||||
|
git_repository_index(&index, g_repo);
|
||||||
|
|
||||||
|
cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
|
||||||
|
cl_assert(entry->file_size == strlen(ALL_LF_TEXT_RAW));
|
||||||
|
|
||||||
|
git_index_free(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_checkout_crlf__detect_crlf_autocrlf_true(void)
|
||||||
|
{
|
||||||
|
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
|
||||||
|
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
|
||||||
|
|
||||||
|
set_core_autocrlf_to(true);
|
||||||
|
|
||||||
|
git_checkout_head(g_repo, &opts);
|
||||||
|
|
||||||
|
test_file_contents("./crlf/all-lf", ALL_LF_TEXT_AS_CRLF);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
|
||||||
|
{
|
||||||
|
git_index *index;
|
||||||
|
const git_index_entry *entry;
|
||||||
|
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
|
||||||
|
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
|
||||||
|
|
||||||
|
set_core_autocrlf_to(true);
|
||||||
|
|
||||||
|
git_checkout_head(g_repo, &opts);
|
||||||
|
|
||||||
|
git_repository_index(&index, g_repo);
|
||||||
|
|
||||||
|
cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
|
||||||
|
cl_assert(entry->file_size == strlen(ALL_LF_TEXT_AS_CRLF));
|
||||||
|
|
||||||
|
git_index_free(index);
|
||||||
|
}
|
1
tests-clar/resources/crlf/.gitted/HEAD
Normal file
1
tests-clar/resources/crlf/.gitted/HEAD
Normal file
@ -0,0 +1 @@
|
|||||||
|
ref: refs/heads/master
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
x¥ŽÝ 1„}NÛ€²ù½,ˆøb6<>K6œ`.’‹Ø¾QìÀ·™o†ab-åÖA»ë<C2BB>0¡ódXš”•btnr:0¡cä¤yž(*´Y<Bãµå0‡¨q m-y«|TSöα6èGŸsáÙ—Úà’^¡%¸.µlu…#úQgþ?wˆµœ@jëµ”DöèÅ ãlç?gDl÷<0C>·¾‰7kP
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
xKÊÉOR02aH.ÊIãåÂ$œž
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
tests-clar/resources/crlf/.gitted/refs/heads/master
Normal file
1
tests-clar/resources/crlf/.gitted/refs/heads/master
Normal file
@ -0,0 +1 @@
|
|||||||
|
12faf3c1ea55f572473cec9052fca468c3584ccb
|
1
tests-clar/resources/crlf/.gitted/refs/heads/utf8
Normal file
1
tests-clar/resources/crlf/.gitted/refs/heads/utf8
Normal file
@ -0,0 +1 @@
|
|||||||
|
baaa042ab2976f8264e467988e6112ee518ec62e
|
Loading…
Reference in New Issue
Block a user