mirror of
https://github.com/git/git
synced 2024-08-25 02:35:46 +00:00
merge: avoid "safer crlf" during recording of merge results
When merge_recursive() decides what the correct blob object merge result for a path should be, it uses update_file_flags() helper function to write it out to a working tree file and then calls add_cacheinfo(). The add_cacheinfo() function in turn calls make_cache_entry() to create a new cache entry to replace the higher-stage entries for the path that represents the conflict. The make_cache_entry() function calls refresh_cache_entry() to fill in the cached stat information. To mark a cache entry as up-to-date, the data is re-read from the file in the working tree, and goes through convert_to_git() conversion to be compared with the blob object name the new cache entry records. It is important to note that this happens while the higher-stage entries, which are going to be replaced with the new entry, are still in the index. Unfortunately, the convert_to_git() conversion has a misguided "safer crlf" mechanism baked in, and looks at the existing cache entry for the path to decide how to convert the contents in the working tree file. If our side (i.e. stage#2) records a text blob with CRLF in it, even when the system is configured to record LF in blobs and convert them to CRLF upon checkout (and back to LF upon checkin), the "safer crlf" mechanism stops us doing so. This especially poses a problem during a renormalizing merge, where the merge result for the path is computed by first "normalizing" the blobs involved in the merge by using convert_to_working_tree() followed by convert_to_git() with "safer crlf" disabled. The merge result that is computed correctly and fed to add_cacheinfo() via update_file_flags() does _not_ match what refresh_cache_entry() sees by converting the working tree file via convert_to_git(). We can work this around by not refreshing the new cache entry in make_cache_entry() called by add_cacheinfo(). After add_cacheinfo() adds the new entry, we can call refresh_cache_entry() on that, knowing that addition of this new cache entry would have removed the stale cache entries that had CRLF in stage #2 that were carried over before the renormalizing merge started and will not interfere with the correct recording of the result. The test update was taken from a series by Torsten Bögershausen that attempted to fix this with a different approach. Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com> Reviewed-by: Torsten Bögershausen <tboegi@web.de>
This commit is contained in:
parent
6523728499
commit
1335d76e45
1
cache.h
1
cache.h
|
@ -632,6 +632,7 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
|
||||||
#define REFRESH_IGNORE_SUBMODULES 0x0010 /* ignore submodules */
|
#define REFRESH_IGNORE_SUBMODULES 0x0010 /* ignore submodules */
|
||||||
#define REFRESH_IN_PORCELAIN 0x0020 /* user friendly output, not "needs update" */
|
#define REFRESH_IN_PORCELAIN 0x0020 /* user friendly output, not "needs update" */
|
||||||
extern int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
|
extern int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
|
||||||
|
extern struct cache_entry *refresh_cache_entry(struct cache_entry *, unsigned int);
|
||||||
|
|
||||||
extern void update_index_if_able(struct index_state *, struct lock_file *);
|
extern void update_index_if_able(struct index_state *, struct lock_file *);
|
||||||
|
|
||||||
|
|
|
@ -202,12 +202,21 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
|
||||||
const char *path, int stage, int refresh, int options)
|
const char *path, int stage, int refresh, int options)
|
||||||
{
|
{
|
||||||
struct cache_entry *ce;
|
struct cache_entry *ce;
|
||||||
ce = make_cache_entry(mode, sha1 ? sha1 : null_sha1, path, stage,
|
int ret;
|
||||||
(refresh ? (CE_MATCH_REFRESH |
|
|
||||||
CE_MATCH_IGNORE_MISSING) : 0 ));
|
ce = make_cache_entry(mode, sha1 ? sha1 : null_sha1, path, stage, 0);
|
||||||
if (!ce)
|
if (!ce)
|
||||||
return error(_("addinfo_cache failed for path '%s'"), path);
|
return error(_("addinfo_cache failed for path '%s'"), path);
|
||||||
return add_cache_entry(ce, options);
|
|
||||||
|
ret = add_cache_entry(ce, options);
|
||||||
|
if (refresh) {
|
||||||
|
struct cache_entry *nce;
|
||||||
|
|
||||||
|
nce = refresh_cache_entry(ce, CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING);
|
||||||
|
if (nce != ce)
|
||||||
|
ret = add_cache_entry(nce, options);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)
|
static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)
|
||||||
|
|
|
@ -19,9 +19,6 @@
|
||||||
#include "split-index.h"
|
#include "split-index.h"
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
|
|
||||||
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
|
|
||||||
unsigned int options);
|
|
||||||
|
|
||||||
/* Mask for the name length in ce_flags in the on-disk index */
|
/* Mask for the name length in ce_flags in the on-disk index */
|
||||||
|
|
||||||
#define CE_NAMEMASK (0x0fff)
|
#define CE_NAMEMASK (0x0fff)
|
||||||
|
@ -1254,7 +1251,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
|
||||||
return has_errors;
|
return has_errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
|
struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
|
||||||
unsigned int options)
|
unsigned int options)
|
||||||
{
|
{
|
||||||
return refresh_cache_ent(&the_index, ce, options, NULL, NULL);
|
return refresh_cache_ent(&the_index, ce, options, NULL, NULL);
|
||||||
|
|
|
@ -91,16 +91,13 @@ test_expect_success 'Merge after setting text=auto' '
|
||||||
compare_files expected file
|
compare_files expected file
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'Merge addition of text=auto' '
|
test_expect_success 'Merge addition of text=auto eol=LF' '
|
||||||
|
git config core.eol lf &&
|
||||||
cat <<-\EOF >expected &&
|
cat <<-\EOF >expected &&
|
||||||
first line
|
first line
|
||||||
same line
|
same line
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if test_have_prereq NATIVE_CRLF; then
|
|
||||||
append_cr <expected >expected.temp &&
|
|
||||||
mv expected.temp expected
|
|
||||||
fi &&
|
|
||||||
git config merge.renormalize true &&
|
git config merge.renormalize true &&
|
||||||
git rm -fr . &&
|
git rm -fr . &&
|
||||||
rm -f .gitattributes &&
|
rm -f .gitattributes &&
|
||||||
|
@ -109,17 +106,31 @@ test_expect_success 'Merge addition of text=auto' '
|
||||||
compare_files expected file
|
compare_files expected file
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'Merge addition of text=auto eol=CRLF' '
|
||||||
|
git config core.eol crlf &&
|
||||||
|
cat <<-\EOF >expected &&
|
||||||
|
first line
|
||||||
|
same line
|
||||||
|
EOF
|
||||||
|
|
||||||
|
append_cr <expected >expected.temp &&
|
||||||
|
mv expected.temp expected &&
|
||||||
|
git config merge.renormalize true &&
|
||||||
|
git rm -fr . &&
|
||||||
|
rm -f .gitattributes &&
|
||||||
|
git reset --hard b &&
|
||||||
|
echo >&2 "After git reset --hard b" &&
|
||||||
|
git ls-files -s --eol >&2 &&
|
||||||
|
git merge a &&
|
||||||
|
compare_files expected file
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'Detect CRLF/LF conflict after setting text=auto' '
|
test_expect_success 'Detect CRLF/LF conflict after setting text=auto' '
|
||||||
|
git config core.eol native &&
|
||||||
echo "<<<<<<<" >expected &&
|
echo "<<<<<<<" >expected &&
|
||||||
if test_have_prereq NATIVE_CRLF; then
|
|
||||||
echo first line | append_cr >>expected &&
|
|
||||||
echo same line | append_cr >>expected &&
|
|
||||||
echo ======= | append_cr >>expected
|
|
||||||
else
|
|
||||||
echo first line >>expected &&
|
echo first line >>expected &&
|
||||||
echo same line >>expected &&
|
echo same line >>expected &&
|
||||||
echo ======= >>expected
|
echo ======= >>expected &&
|
||||||
fi &&
|
|
||||||
echo first line | append_cr >>expected &&
|
echo first line | append_cr >>expected &&
|
||||||
echo same line | append_cr >>expected &&
|
echo same line | append_cr >>expected &&
|
||||||
echo ">>>>>>>" >>expected &&
|
echo ">>>>>>>" >>expected &&
|
||||||
|
@ -135,15 +146,9 @@ test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' '
|
||||||
echo "<<<<<<<" >expected &&
|
echo "<<<<<<<" >expected &&
|
||||||
echo first line | append_cr >>expected &&
|
echo first line | append_cr >>expected &&
|
||||||
echo same line | append_cr >>expected &&
|
echo same line | append_cr >>expected &&
|
||||||
if test_have_prereq NATIVE_CRLF; then
|
|
||||||
echo ======= | append_cr >>expected &&
|
|
||||||
echo first line | append_cr >>expected &&
|
|
||||||
echo same line | append_cr >>expected
|
|
||||||
else
|
|
||||||
echo ======= >>expected &&
|
echo ======= >>expected &&
|
||||||
echo first line >>expected &&
|
echo first line >>expected &&
|
||||||
echo same line >>expected
|
echo same line >>expected &&
|
||||||
fi &&
|
|
||||||
echo ">>>>>>>" >>expected &&
|
echo ">>>>>>>" >>expected &&
|
||||||
git config merge.renormalize false &&
|
git config merge.renormalize false &&
|
||||||
rm -f .gitattributes &&
|
rm -f .gitattributes &&
|
||||||
|
|
Loading…
Reference in a new issue