From 1dcb0688c7c229501e6a486c03ffe251d5ed2761 Mon Sep 17 00:00:00 2001 From: Marco Miller Date: Thu, 21 Jun 2018 14:18:48 -0400 Subject: [PATCH] ResolveMerger: Fix encoding with string; use bytes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change fixes the issue [1]. Before this fix, a merge involving the caching of consecutive yet similar filenames with Norwegian characters [2] used to throw an IllegalStateException: Duplicate stages not allowed. This was caused by inaccurate decoding of the filenames, using string values assuming default encoding. In the toString method of DirCacheEntry, used before through getPathString, UTF-8 encoding is used, but the end result becomes default encoding, through Object's default toString usage. The special characters in those two consecutive (particular) filenames [2] were becoming the very same decoded /single character, lending consecutive -but then identical- filenames. Thus the perceived duplicate 0-staging of the file(s). Replace getPathString usage with getRawPath for this specific case, or use byte array representations of cached entries instead of string. Adding a test for this change is not possible, as there is no known way to change the default encoding for filenames such as [2] (e.g.). JGitTestUtil does write file contents through UTF-8, but encoding like so does not apply to the actual file name. Hence there is no way to create files with names properly made of special characters such as [2]'s. And the test that is necessary for this case assumes such Norwegian (or similar characters) filenames. Changing the default locale programmatically in a test has no effect either. And changing the LANG value passed to the JVM is only possible upon starting it. [1] https://bugs.chromium.org/p/gerrit/issues/detail?id=9153 [2] <=> (...) "a/b/SíÒr-Norge.map", "a/b/Sør-Norge.map", (...) Change-Id: Ib9f2f5297932337c9817064cc09d9f774dd168f4 Signed-off-by: Marco Miller --- org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java index f667af278..90107be2e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java @@ -393,7 +393,7 @@ public class ResolveMerger extends ThreeWayMerger { * @return the entry which was added to the index */ private DirCacheEntry keep(DirCacheEntry e) { - DirCacheEntry newEntry = new DirCacheEntry(e.getPathString(), + DirCacheEntry newEntry = new DirCacheEntry(e.getRawPath(), e.getStage()); newEntry.setFileMode(e.getFileMode()); newEntry.setObjectId(e.getObjectId());