diff options
author | Torsten Bögershausen <tboegi@web.de> | 2016-06-28 10:01:16 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-07-07 09:17:12 -0700 |
commit | 9e2be614c1fa594f786b408e717159f1ed52bb37 (patch) | |
tree | e258b374c5ebb6ec538c602429997d31592052bf /read-cache.c | |
parent | 75964d2722cb95f0a9a04f9c0a5814faabbd232f (diff) | |
download | git-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 'read-cache.c')
-rw-r--r-- | read-cache.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/read-cache.c b/read-cache.c index a3ef967411..c109b6d9bb 100644 --- a/read-cache.c +++ b/read-cache.c @@ -163,7 +163,9 @@ static int ce_compare_data(const struct cache_entry *ce, struct stat *st) if (fd >= 0) { unsigned char sha1[20]; - if (!index_fd(sha1, fd, st, OBJ_BLOB, ce->name, 0)) + unsigned flags = HASH_USE_SHA_NOT_PATH; + memcpy(sha1, ce->sha1, sizeof(sha1)); + if (!index_fd(sha1, fd, st, OBJ_BLOB, ce->name, flags)) match = hashcmp(sha1, ce->sha1); /* index_fd() closed the file descriptor already */ } |