Commit 6e959708e55316664379b9cecf53784c542d8a14

Edward Thomson 2013-01-17T13:11:57

cache should contain on-disk (filtered) file size

diff --git a/src/checkout.c b/src/checkout.c
index 411bf3b..40f5732 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -724,10 +724,8 @@ static int blob_content_to_file(
 	error = buffer_to_file(
 		st, &filtered, path, opts->dir_mode, opts->file_open_flags, file_mode);
 
-	if (!error) {
-		st->st_size = blob->odb_object->raw.len;
+	if (!error)
 		st->st_mode = entry_filemode;
-	}
 
 cleanup:
 	git_filters_free(&filters);
diff --git a/tests-clar/checkout/crlf.c b/tests-clar/checkout/crlf.c
new file mode 100644
index 0000000..cf7521e
--- /dev/null
+++ b/tests-clar/checkout/crlf.c
@@ -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);
+}
diff --git a/tests-clar/resources/crlf/.gitted/HEAD b/tests-clar/resources/crlf/.gitted/HEAD
new file mode 100644
index 0000000..cb089cd
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests-clar/resources/crlf/.gitted/objects/04/de00b358f13389948756732158eaaaefa1448c b/tests-clar/resources/crlf/.gitted/objects/04/de00b358f13389948756732158eaaaefa1448c
new file mode 100644
index 0000000..c3b7598
Binary files /dev/null and b/tests-clar/resources/crlf/.gitted/objects/04/de00b358f13389948756732158eaaaefa1448c differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/0a/a76e474d259bd7c13eb726a1396c381db55c88 b/tests-clar/resources/crlf/.gitted/objects/0a/a76e474d259bd7c13eb726a1396c381db55c88
new file mode 100644
index 0000000..e118d66
Binary files /dev/null and b/tests-clar/resources/crlf/.gitted/objects/0a/a76e474d259bd7c13eb726a1396c381db55c88 differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/0d/06894e14df22e066763ae906e0ed3eb79c205f b/tests-clar/resources/crlf/.gitted/objects/0d/06894e14df22e066763ae906e0ed3eb79c205f
new file mode 100644
index 0000000..b7a1f32
Binary files /dev/null and b/tests-clar/resources/crlf/.gitted/objects/0d/06894e14df22e066763ae906e0ed3eb79c205f differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/0f/f5a53f19bfd2b5eea1ba550295c47515678987 b/tests-clar/resources/crlf/.gitted/objects/0f/f5a53f19bfd2b5eea1ba550295c47515678987
new file mode 100644
index 0000000..5366acd
Binary files /dev/null and b/tests-clar/resources/crlf/.gitted/objects/0f/f5a53f19bfd2b5eea1ba550295c47515678987 differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/12/faf3c1ea55f572473cec9052fca468c3584ccb b/tests-clar/resources/crlf/.gitted/objects/12/faf3c1ea55f572473cec9052fca468c3584ccb
new file mode 100644
index 0000000..96d5b2f
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/objects/12/faf3c1ea55f572473cec9052fca468c3584ccb
@@ -0,0 +1 @@
+x	1}Nۀ,b6K6`.ؾQoab-A0dXbtnr:0cy(*Y<B0q m-y|TSα6Gsٗ^%.lu#Qg?w@j뵔DŠl?gDl7kP
\ No newline at end of file
diff --git a/tests-clar/resources/crlf/.gitted/objects/38/1cfe630df902bc29271a202d3277981180e4a6 b/tests-clar/resources/crlf/.gitted/objects/38/1cfe630df902bc29271a202d3277981180e4a6
new file mode 100644
index 0000000..0cf7072
Binary files /dev/null and b/tests-clar/resources/crlf/.gitted/objects/38/1cfe630df902bc29271a202d3277981180e4a6 differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/79/9770d1cff46753a57db7a066159b5610da6e3a b/tests-clar/resources/crlf/.gitted/objects/79/9770d1cff46753a57db7a066159b5610da6e3a
new file mode 100644
index 0000000..5c701b8
Binary files /dev/null and b/tests-clar/resources/crlf/.gitted/objects/79/9770d1cff46753a57db7a066159b5610da6e3a differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/7c/ce67e58173e2b01f7db124ceaabe3183d19c49 b/tests-clar/resources/crlf/.gitted/objects/7c/ce67e58173e2b01f7db124ceaabe3183d19c49
new file mode 100644
index 0000000..8e836ab
Binary files /dev/null and b/tests-clar/resources/crlf/.gitted/objects/7c/ce67e58173e2b01f7db124ceaabe3183d19c49 differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/a9/a2e8913c1dbe2812fac5e6b4e0a4bd5d0d5966 b/tests-clar/resources/crlf/.gitted/objects/a9/a2e8913c1dbe2812fac5e6b4e0a4bd5d0d5966
new file mode 100644
index 0000000..33d59f1
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/objects/a9/a2e8913c1dbe2812fac5e6b4e0a4bd5d0d5966
@@ -0,0 +1 @@
+xKOR02aH.I$	
\ No newline at end of file
diff --git a/tests-clar/resources/crlf/.gitted/objects/ba/aa042ab2976f8264e467988e6112ee518ec62e b/tests-clar/resources/crlf/.gitted/objects/ba/aa042ab2976f8264e467988e6112ee518ec62e
new file mode 100644
index 0000000..4c544d5
Binary files /dev/null and b/tests-clar/resources/crlf/.gitted/objects/ba/aa042ab2976f8264e467988e6112ee518ec62e differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/dc/88e3b917de821e25962bea7ec1f55c4ce2112c b/tests-clar/resources/crlf/.gitted/objects/dc/88e3b917de821e25962bea7ec1f55c4ce2112c
new file mode 100644
index 0000000..3db13aa
Binary files /dev/null and b/tests-clar/resources/crlf/.gitted/objects/dc/88e3b917de821e25962bea7ec1f55c4ce2112c differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/ea/030d3c6cec212069eca698cabaa5b4550f1511 b/tests-clar/resources/crlf/.gitted/objects/ea/030d3c6cec212069eca698cabaa5b4550f1511
new file mode 100644
index 0000000..117dc72
Binary files /dev/null and b/tests-clar/resources/crlf/.gitted/objects/ea/030d3c6cec212069eca698cabaa5b4550f1511 differ
diff --git a/tests-clar/resources/crlf/.gitted/objects/fe/085d9ace90cc675b87df15e1aeed0c3a31407f b/tests-clar/resources/crlf/.gitted/objects/fe/085d9ace90cc675b87df15e1aeed0c3a31407f
new file mode 100644
index 0000000..2e8d10b
Binary files /dev/null and b/tests-clar/resources/crlf/.gitted/objects/fe/085d9ace90cc675b87df15e1aeed0c3a31407f differ
diff --git a/tests-clar/resources/crlf/.gitted/refs/heads/master b/tests-clar/resources/crlf/.gitted/refs/heads/master
new file mode 100644
index 0000000..a2dbe0c
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/refs/heads/master
@@ -0,0 +1 @@
+12faf3c1ea55f572473cec9052fca468c3584ccb
diff --git a/tests-clar/resources/crlf/.gitted/refs/heads/utf8 b/tests-clar/resources/crlf/.gitted/refs/heads/utf8
new file mode 100644
index 0000000..4b32f7f
--- /dev/null
+++ b/tests-clar/resources/crlf/.gitted/refs/heads/utf8
@@ -0,0 +1 @@
+baaa042ab2976f8264e467988e6112ee518ec62e