You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DirCacheLargePathTest.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (C) 2008-2009, Google Inc. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.dircache;
  11. import static org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.assertNotSame;
  13. import static org.junit.Assert.assertSame;
  14. import static org.junit.Assert.assertTrue;
  15. import java.io.IOException;
  16. import org.eclipse.jgit.errors.CorruptObjectException;
  17. import org.eclipse.jgit.junit.RepositoryTestCase;
  18. import org.eclipse.jgit.lib.FileMode;
  19. import org.junit.Test;
  20. public class DirCacheLargePathTest extends RepositoryTestCase {
  21. @Test
  22. public void testPath_4090() throws Exception {
  23. testLongPath(4090);
  24. }
  25. @Test
  26. public void testPath_4094() throws Exception {
  27. testLongPath(4094);
  28. }
  29. @Test
  30. public void testPath_4095() throws Exception {
  31. testLongPath(4095);
  32. }
  33. @Test
  34. public void testPath_4096() throws Exception {
  35. testLongPath(4096);
  36. }
  37. @Test
  38. public void testPath_16384() throws Exception {
  39. testLongPath(16384);
  40. }
  41. private void testLongPath(int len) throws CorruptObjectException,
  42. IOException {
  43. final String longPath = makeLongPath(len);
  44. final String shortPath = "~~~ shorter-path";
  45. final DirCacheEntry longEnt = new DirCacheEntry(longPath);
  46. final DirCacheEntry shortEnt = new DirCacheEntry(shortPath);
  47. longEnt.setFileMode(FileMode.REGULAR_FILE);
  48. shortEnt.setFileMode(FileMode.REGULAR_FILE);
  49. assertEquals(longPath, longEnt.getPathString());
  50. assertEquals(shortPath, shortEnt.getPathString());
  51. {
  52. final DirCache dc1 = db.lockDirCache();
  53. {
  54. final DirCacheBuilder b = dc1.builder();
  55. b.add(longEnt);
  56. b.add(shortEnt);
  57. assertTrue(b.commit());
  58. }
  59. assertEquals(2, dc1.getEntryCount());
  60. assertSame(longEnt, dc1.getEntry(0));
  61. assertSame(shortEnt, dc1.getEntry(1));
  62. }
  63. {
  64. final DirCache dc2 = db.readDirCache();
  65. assertEquals(2, dc2.getEntryCount());
  66. assertNotSame(longEnt, dc2.getEntry(0));
  67. assertEquals(longPath, dc2.getEntry(0).getPathString());
  68. assertNotSame(shortEnt, dc2.getEntry(1));
  69. assertEquals(shortPath, dc2.getEntry(1).getPathString());
  70. }
  71. }
  72. private static String makeLongPath(int len) {
  73. final StringBuilder r = new StringBuilder(len);
  74. for (int i = 0; i < len; i++)
  75. r.append('a' + (i % 26));
  76. return r.toString();
  77. }
  78. }