# HG changeset patch # User Artem Tikhomirov # Date 1321930957 -3600 # Node ID 6d2c6b2469fcfea82a177d3cb664456c8dc7a1df # Parent 58725dd511b3c5854f52b4e6d771877f46c9f748 Issue 18: Invalid storage path for certain long names diff -r 58725dd511b3 -r 6d2c6b2469fc src/org/tmatesoft/hg/internal/StoragePathHelper.java --- a/src/org/tmatesoft/hg/internal/StoragePathHelper.java Tue Nov 22 03:14:40 2011 +0100 +++ b/src/org/tmatesoft/hg/internal/StoragePathHelper.java Tue Nov 22 04:02:37 2011 +0100 @@ -141,7 +141,16 @@ int left = MAX_PATH_LEN - sb2.length() - 40 /*digest.length()*/ - STR_DH.length() - ".i".length(); assert left >= 0; fnameStart++; // move from / to actual name - sb2.append(sb, fnameStart, fnameStart + left > sb.length() ? sb.length() : fnameStart+left); + if (fnameStart + left > sb.length()) { + // there left less chars in the mangled name that we can fit + sb2.append(sb, fnameStart, sb.length()); + int stillAvailable = (fnameStart+left) - sb.length(); + // stillAvailable > 0; + sb2.append(".i", 0, stillAvailable > 2 ? 2 : stillAvailable); + } else { + // add as much as we can + sb2.append(sb, fnameStart, fnameStart+left); + } completeHashName.append(sb2); } completeHashName.append(digest); diff -r 58725dd511b3 -r 6d2c6b2469fc test/org/tmatesoft/hg/test/TestStorePath.java --- a/test/org/tmatesoft/hg/test/TestStorePath.java Tue Nov 22 03:14:40 2011 +0100 +++ b/test/org/tmatesoft/hg/test/TestStorePath.java Tue Nov 22 04:02:37 2011 +0100 @@ -70,4 +70,21 @@ errorCollector.checkThat(storePathHelper.rewrite(n2), CoreMatchers.equalTo(r2)); errorCollector.checkThat(storePathHelper.rewrite(n3), CoreMatchers.equalTo(r3)); } + + @Test + public void testIndexFileExtensionIsPartOfTheName() { + // with "data/" and ".i" 121 chars + String n1 = "src/jgit/main/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/.settings/org.eclipse.core.resources.prefs"; + String r1 = "store/dh/src/jgit/main/org.ecli/org.ecli/~2esetti/org.eclipse.core.resources.prefs.ie1f4f9eed1009d220cd5afa6e01e7d9a06c02201.i"; + // with "data/" and ".i" 122 chars + String n2 = "src/jgit/main/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/.settings/org.eclipse.core.resources.prefs"; + String r2 = "store/dh/src/jgit/main/org.ecli/org.ecli/~2esetti/org.eclipse.core.resources.prefs.i5193ab724f0225178fa949738444c4aac05e5e00.i"; + // + // with "data/" and ".i" just 118 chars, use as sanity that it's not mangled + String n3 = "src/jgit/main/org.eclipse.jgit.packaging/org.eclipse.jgit.updatesite/.settings/org.eclipse.core.resources.prefs"; + String r3 = "store/data/src/jgit/main/org.eclipse.jgit.packaging/org.eclipse.jgit.updatesite/~2esettings/org.eclipse.core.resources.prefs.i"; + errorCollector.checkThat(storePathHelper.rewrite(n1), CoreMatchers.equalTo(r1)); + errorCollector.checkThat(storePathHelper.rewrite(n2), CoreMatchers.equalTo(r2)); + errorCollector.checkThat(storePathHelper.rewrite(n3), CoreMatchers.equalTo(r3)); + } }