From b4112c17484d6a54e956807298593847da079577 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sun, 25 Sep 2011 00:17:19 +0200 Subject: [PATCH] Fix DirCache,getEntriesWithin for empty string arguemnt Change-Id: I0bea130df611de3ef8c9251093b11c62b5442cd1 --- .../tst/org/eclipse/jgit/dircache/DirCacheFindTest.java | 7 +++++++ .../src/org/eclipse/jgit/dircache/DirCache.java | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java index e861bed17..a4bb559da 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java @@ -88,6 +88,13 @@ public class DirCacheFindTest extends RepositoryTestCase { for (int i = aFirst, j = 0; i <= aLast; i++, j++) assertSame(ents[i], aContents[j]); } + { + final DirCacheEntry[] aContents = dc.getEntriesWithin(""); + assertNotNull(aContents); + assertEquals(ents.length, aContents.length); + for (int i = 0; i < ents.length; i++) + assertSame(ents[i], aContents[i]); + } assertNotNull(dc.getEntriesWithin("a.")); assertEquals(0, dc.getEntriesWithin("a.").length); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java index 456236c09..af98c3315 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java @@ -712,6 +712,11 @@ public class DirCache { * @return all entries recursively contained within the subtree. */ public DirCacheEntry[] getEntriesWithin(String path) { + if (path.length() == 0) { + final DirCacheEntry[] r = new DirCacheEntry[sortedEntries.length]; + System.arraycopy(sortedEntries, 0, r, 0, sortedEntries.length); + return r; + } if (!path.endsWith("/")) path += "/"; final byte[] p = Constants.encode(path);