summaryrefslogtreecommitdiff
path: root/convert.h
diff options
context:
space:
mode:
authorTorsten Bögershausen <tboegi@web.de>2016-06-28 10:01:16 +0200
committerJunio C Hamano <gitster@pobox.com>2016-07-07 09:17:12 -0700
commit9e2be614c1fa594f786b408e717159f1ed52bb37 (patch)
treee258b374c5ebb6ec538c602429997d31592052bf /convert.h
parent75964d2722cb95f0a9a04f9c0a5814faabbd232f (diff)
downloadgit-tb/convert-peek-in-index.tar.gz
correct ce_compare_data() in a middle of a mergetb/convert-peek-in-index
The following didn't work as expected: - In a middle of a merge - merge.renormalize is true, - .gitattributes = "* text=auto" - core.eol = crlf Merge a blob with CRLF "first line\r\nsame line\r\n" and a blob with LF "first line\nsame line\n". The expected result of the merge is "first line\nsame line\n". The content in the working tree is "first line\r\nsame line\r\n", and ce_compare_data() should find that the content is clean and return 0. Deep down crlf_to_git() is invoked, to check if CRLF are converted or not. The "new safer autocrlf handling" calls blob_has_cr(). Instead of using the sha1 of the blob, (CRLF in this example), the function get_sha1_from_index() is invoked. get_sha1_from_index() decides to return "ours" when in the middle of the merge, which is LF. As a result, the CRLF in the worktree are converted into LF before the comparison. The contents of LF and CRLF don't match any more. The problem is that ce_compare_data() has ce->sha1, but the sha1 is lost on it's way into blob_has_cr(). Forwarding ce->sha1 from ce_compare_data() into crlf_to_git() makes sure that blob_has_cr() looks at the appropriate blob. Add a new parameter index_blob_sha1 to convert_to_git(), and forward the sha1 from ce_compare_data() into convert_to_git(). Other callers use NULL for index_blob_sha1, and the sha1 is determined from path using get_sha1_from_cache(path). This is the same handling as before. In the same spirit, forward the sha1 into would_convert_to_git(). While at it, rename has_cr_in_index() into blob_has_cr() and replace 0 with SAFE_CRLF_FALSE. Add a TC in t6038 to have a test coverage under Linux. Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'convert.h')
-rw-r--r--convert.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/convert.h b/convert.h
index 82871a11d5..97d427296f 100644
--- a/convert.h
+++ b/convert.h
@@ -39,19 +39,26 @@ extern const char *get_convert_attr_ascii(const char *path);
/* returns 1 if *dst was used */
extern int convert_to_git(const char *path, const char *src, size_t len,
- struct strbuf *dst, enum safe_crlf checksafe);
+ struct strbuf *dst, enum safe_crlf checksafe,
+ const unsigned char *index_blob_sha1);
+
extern int convert_to_working_tree(const char *path, const char *src,
size_t len, struct strbuf *dst);
extern int renormalize_buffer(const char *path, const char *src, size_t len,
struct strbuf *dst);
-static inline int would_convert_to_git(const char *path)
+static inline int would_convert_to_git(const char *path,
+ const unsigned char *index_blob_sha1)
{
- return convert_to_git(path, NULL, 0, NULL, 0);
+ return convert_to_git(path, NULL, 0, NULL, SAFE_CRLF_FALSE,
+ index_blob_sha1);
}
+
/* Precondition: would_convert_to_git_filter_fd(path) == true */
extern void convert_to_git_filter_fd(const char *path, int fd,
struct strbuf *dst,
- enum safe_crlf checksafe);
+ enum safe_crlf checksafe,
+ const unsigned char *index_blob_sha1);
+
extern int would_convert_to_git_filter_fd(const char *path);
/*****************************************************************