Unit test for plugin and then some
cover Unit test for plugin and then some
This adds a JUnit test for the plugin. It doesn't test much yet, but rather than having more people add the infrastructure I submit the skeleton and two small samples here. A writeRef method is implemented to be able to set up the test repository without using native Git.
I also found an unneeded class when using Eclipse 3.3M6. Exterminated.
I also dropped the non-git sort order of trees. This isn't too good looking, but I expect it to be improved in later versions.
-- robin
PATCH 1/4 Drop unneeded GitTreeStorage
---
.../src/org/spearce/egit/core/GitTreeStorage.java | 484 ----------------------- 1 files changed, 0 insertions(+), 484 deletions(-)
org.spearce.egit.core/src/org/spearce/egit/core/GitTreeStorage.java deleted +0 -484
@@ -1,484 +0,0 @@ -/* - * Copyright (C) 2006 Robin Rosenberg - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License, version 2.1, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - */ -package org.spearce.egit.core; - -import java.io.IOException; -import java.net.URI; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceProxy; -import org.eclipse.core.resources.IResourceProxyVisitor; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.ResourceAttributes; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.team.core.RepositoryProvider; -import org.spearce.egit.core.project.RepositoryMapping; -import org.spearce.jgit.lib.ObjectId; -import org.spearce.jgit.lib.Tree; - -public class GitTreeStorage implements IContainer { - - private Tree entry; - - public GitTreeStorage(ObjectId treeId, IResource resource, String relativeResourceName) { - if (treeId == null) - return; - - GitProvider provider = (GitProvider) RepositoryProvider - .getProvider(resource.getProject()); - RepositoryMapping repositoryMapping = provider.getData() - .getRepositoryMapping(resource.getProject()); - Tree tree; - try { - tree = repositoryMapping.getRepository().mapTree(treeId); - String prefix = repositoryMapping.getSubset(); - if (prefix != null) - prefix = prefix + "/"; - else - prefix = ""; - String name = prefix + resource.getProjectRelativePath().toString(); - entry = (Tree)tree.findMember(name); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public boolean exists(IPath path) { - try { - return entry.findMember(path.toString()) != null; - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return false; - } - - public IFile[] findDeletedMembersWithHistory(int depth, - IProgressMonitor monitor) throws CoreException { - // TODO Auto-generated method stub - return null; - } - - public IResource findMember(String name) { - // TODO Auto-generated method stub - return null; - } - - public IResource findMember(IPath path) { - // TODO Auto-generated method stub - return null; - } - - public IResource findMember(String name, boolean includePhantoms) { - // TODO Auto-generated method stub - return null; - } - - public IResource findMember(IPath path, boolean includePhantoms) { - // TODO Auto-generated method stub - return null; - } - - public String getDefaultCharset() throws CoreException { - // TODO Auto-generated method stub - return null; - } - - public String getDefaultCharset(boolean checkImplicit) throws CoreException { - // TODO Auto-generated method stub - return null; - } - - public IFile getFile(IPath path) { - // TODO Auto-generated method stub - return null; - } - - public IFolder getFolder(IPath path) { - // TODO Auto-generated method stub - return null; - } - - public IResource[] members() throws CoreException { - // TODO Auto-generated method stub - return null; - } - - public IResource[] members(boolean includePhantoms) throws CoreException { - // TODO Auto-generated method stub - return null; - } - - public IResource[] members(int memberFlags) throws CoreException { - // TODO Auto-generated method stub - return null; - } - - public void setDefaultCharset(String charset) throws CoreException { - // TODO Auto-generated method stub - - } - - public void setDefaultCharset(String charset, IProgressMonitor monitor) - throws CoreException { - // TODO Auto-generated method stub - - } - - public void accept(IResourceVisitor visitor) throws CoreException { - // TODO Auto-generated method stub - - } - - public void accept(IResourceProxyVisitor visitor, int memberFlags) - throws CoreException { - // TODO Auto-generated method stub - - } - - public void accept(IResourceVisitor visitor, int depth, - boolean includePhantoms) throws CoreException { - // TODO Auto-generated method stub - - } - - public void accept(IResourceVisitor visitor, int depth, int memberFlags) - throws CoreException { - // TODO Auto-generated method stub - - } - - public void clearHistory(IProgressMonitor monitor) throws CoreException { - // TODO Auto-generated method stub - - } - - public void copy(IPath destination, boolean force, IProgressMonitor monitor) - throws CoreException { - // TODO Auto-generated method stub - - } - - public void copy(IPath destination, int updateFlags, - IProgressMonitor monitor) throws CoreException { - // TODO Auto-generated method stub - - } - - public void copy(IProjectDescription description, boolean force, - IProgressMonitor monitor) throws CoreException { - // TODO Auto-generated method stub - - } - - public void copy(IProjectDescription description, int updateFlags, - IProgressMonitor monitor) throws CoreException { - // TODO Auto-generated method stub - - } - - public IMarker createMarker(String type) throws CoreException { - // TODO Auto-generated method stub - return null; - } - - public IResourceProxy createProxy() { - // TODO Auto-generated method stub - return null; - } - - public void delete(boolean force, IProgressMonitor monitor) - throws CoreException { - // TODO Auto-generated method stub - - } - - public void delete(int updateFlags, IProgressMonitor monitor) - throws CoreException { - // TODO Auto-generated method stub - - } - - public void deleteMarkers(String type, boolean includeSubtypes, int depth) - throws CoreException { - // TODO Auto-generated method stub - - } - - public boolean exists() { - // TODO Auto-generated method stub - return false; - } - - public IMarker findMarker(long id) throws CoreException { - // TODO Auto-generated method stub - return null; - } - - public IMarker[] findMarkers(String type, boolean includeSubtypes, int depth) - throws CoreException { - // TODO Auto-generated method stub - return null; - } - - public String getFileExtension() { - // TODO Auto-generated method stub - return null; - } - - public IPath getFullPath() { - // TODO Auto-generated method stub - return null; - } - - public long getLocalTimeStamp() { - // TODO Auto-generated method stub - return 0; - } - - public IPath getLocation() { - // TODO Auto-generated method stub - return null; - } - - public URI getLocationURI() { - // TODO Auto-generated method stub - return null; - } - - public IMarker getMarker(long id) { - // TODO Auto-generated method stub - return null; - } - - public long getModificationStamp() { - // TODO Auto-generated method stub - return 0; - } - - public String getName() { - // TODO Auto-generated method stub - return null; - } - - public IContainer getParent() { - // TODO Auto-generated method stub - return null; - } - - public String getPersistentProperty(QualifiedName key) throws CoreException { - // TODO Auto-generated method stub - return null; - } - - public IProject getProject() { - // TODO Auto-generated method stub - return null; - } - - public IPath getProjectRelativePath() { - // TODO Auto-generated method stub - return null; - } - - public IPath getRawLocation() { - // TODO Auto-generated method stub - return null; - } - - public URI getRawLocationURI() { - // TODO Auto-generated method stub - return null; - } - - public ResourceAttributes getResourceAttributes() { - // TODO Auto-generated method stub - return null; - } - - public Object getSessionProperty(QualifiedName key) throws CoreException { - // TODO Auto-generated method stub - return null; - } - - public int getType() { - // TODO Auto-generated method stub - return 0; - } - - public IWorkspace getWorkspace() { - // TODO Auto-generated method stub - return null; - } - - public boolean isAccessible() { - // TODO Auto-generated method stub - return false; - } - - public boolean isDerived() { - // TODO Auto-generated method stub - return false; - } - - public boolean isLinked() { - // TODO Auto-generated method stub - return false; - } - - public boolean isLinked(int options) { - // TODO Auto-generated method stub - return false; - } - - public boolean isLocal(int depth) { - // TODO Auto-generated method stub - return false; - } - - public boolean isPhantom() { - // TODO Auto-generated method stub - return false; - } - - public boolean isReadOnly() { - // TODO Auto-generated method stub - return false; - } - - public boolean isSynchronized(int depth) { - // TODO Auto-generated method stub - return false; - } - - public boolean isTeamPrivateMember() { - // TODO Auto-generated method stub - return false; - } - - public void move(IPath destination, boolean force, IProgressMonitor monitor) - throws CoreException { - // TODO Auto-generated method stub - - } - - public void move(IPath destination, int updateFlags, - IProgressMonitor monitor) throws CoreException { - // TODO Auto-generated method stub - - } - - public void move(IProjectDescription description, int updateFlags, - IProgressMonitor monitor) throws CoreException { - // TODO Auto-generated method stub - - } - - public void move(IProjectDescription description, boolean force, - boolean keepHistory, IProgressMonitor monitor) throws CoreException { - // TODO Auto-generated method stub - - } - - public void refreshLocal(int depth, IProgressMonitor monitor) - throws CoreException { - // TODO Auto-generated method stub - - } - - public void revertModificationStamp(long value) throws CoreException { - // TODO Auto-generated method stub - - } - - public void setDerived(boolean isDerived) throws CoreException { - // TODO Auto-generated method stub - - } - - public void setLocal(boolean flag, int depth, IProgressMonitor monitor) - throws CoreException { - // TODO Auto-generated method stub - - } - - public long setLocalTimeStamp(long value) throws CoreException { - // TODO Auto-generated method stub - return 0; - } - - public void setPersistentProperty(QualifiedName key, String value) - throws CoreException { - // TODO Auto-generated method stub - - } - - public void setReadOnly(boolean readOnly) { - // TODO Auto-generated method stub - - } - - public void setResourceAttributes(ResourceAttributes attributes) - throws CoreException { - // TODO Auto-generated method stub - - } - - public void setSessionProperty(QualifiedName key, Object value) - throws CoreException { - // TODO Auto-generated method stub - - } - - public void setTeamPrivateMember(boolean isTeamPrivate) - throws CoreException { - // TODO Auto-generated method stub - - } - - public void touch(IProgressMonitor monitor) throws CoreException { - // TODO Auto-generated method stub - - } - - public Object getAdapter(Class adapter) { - // TODO Auto-generated method stub - return null; - } - - public boolean contains(ISchedulingRule rule) { - // TODO Auto-generated method stub - return false; - } - - public boolean isConflicting(ISchedulingRule rule) { - // TODO Auto-generated method stub - return false; - } -}
PATCH 2/4 Use the Git sort order.
In reply to Robin RosenbergDo not resort trees when reading into memory. This requires that a number of routines learn to sort tree entries as if they end with a '/'. To do that a parameter must be passed. I do this by passing a NUL or '/' byte as an extra parameter for the comparison routines.
No noticeable performance difference can be noted. The reason for this patch is to simply implementation of the git index and make jgit more git-like.
---
.../src/org/spearce/egit/core/GitBlobStorage.java | 2 - .../org/spearce/egit/core/GitMoveDeleteHook.java | 17 ++++- .../src/org/spearce/egit/core/GitStorage.java | 5 + .../egit/core/internal/mapping/GitFileHistory.java | 11 ++- .../core/internal/mapping/GitFileRevision.java | 5 + .../org/spearce/egit/core/op/TrackOperation.java | 8 +- .../org/spearce/egit/core/op/UntrackOperation.java | 6 +- .../spearce/egit/core/project/GitProjectData.java | 10 ++- .../egit/core/project/RepositoryMapping.java | 2 - .../org.spearce.jgit--All-Tests.launch | 6 ++ .../src/org/spearce/jgit/lib/MergedTree.java | 27 +++++-- .../src/org/spearce/jgit/lib/ObjectWriter.java | 7 -- .../src/org/spearce/jgit/lib/SubtreeSorter.java | 40 ----------- .../src/org/spearce/jgit/lib/Tree.java | 85 ++++++++++++++++------- .../src/org/spearce/jgit/lib/TreeEntry.java | 9 ++ .../tst/org/spearce/jgit/lib/T0002_Tree.java | 33 +++++---- .../org/spearce/jgit/lib/T0006_DeepSpeedTest.java | 2 - 17 files changed, 160 insertions(+), 115 deletions(-)
org.spearce.egit.core/src/org/spearce/egit/core/GitBlobStorage.java +1 -1
@@ -59,7 +59,7 @@ public class GitBlobStorage implements IStorage { else prefix = ""; String name = prefix + resource.getProjectRelativePath().toString(); - entry = tree.findMember(name); + entry = tree.findBlobMember(name); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();
org.spearce.egit.core/src/org/spearce/egit/core/GitMoveDeleteHook.java +13 -4
@@ -122,7 +122,7 @@ class GitMoveDeleteHook implements IMoveDeleteHook { if (s != null && m != null && m.getCacheTree() != null) { try { - final TreeEntry e = m.getCacheTree().findMember(s); + final TreeEntry e = m.getCacheTree().findTreeMember(s); if (e != null) { e.delete(); m.recomputeMerge();
@@ -182,7 +182,10 @@ class GitMoveDeleteHook implements IMoveDeleteHook { } try { - srcEnt = srcMap.getCacheTree().findMember(srcPath); + if (src.getType() == IResource.FILE) + srcEnt = srcMap.getCacheTree().findBlobMember(srcPath); + else + srcEnt = srcMap.getCacheTree().findTreeMember(srcPath); if (srcEnt == null) { return FINISH_FOR_ME; }
@@ -199,7 +202,11 @@ class GitMoveDeleteHook implements IMoveDeleteHook { if (dstPath == null) { dstTree = dstMap.getCacheTree(); } else { - final TreeEntry e = dstMap.getCacheTree().findMember(dstPath); + final TreeEntry e; + if (src.getType() == IResource.FILE) + e = dstMap.getCacheTree().findBlobMember(dstPath); + else + e = dstMap.getCacheTree().findTreeMember(dstPath); if (e == null) { dstTree = dstMap.getCacheTree().addTree(dstPath); } else if (e instanceof Tree) {
@@ -216,7 +223,9 @@ class GitMoveDeleteHook implements IMoveDeleteHook { // What? Something already exists at the destination? Assume // Eclipse meant for us to replace the item. // - final TreeEntry existing = dstTree.findMember(dstName); + TreeEntry existing = dstTree.findTreeMember(dstName); + if (existing == null) + dstTree.findBlobMember(dstName); if (existing != null) { existing.delete(); }
org.spearce.egit.core/src/org/spearce/egit/core/GitStorage.java +4 -1
@@ -62,7 +62,10 @@ public class GitStorage implements IStorage { else prefix = ""; String name = prefix + resource.getProjectRelativePath().toString(); - entry = tree.findMember(name); + if (resource.getType() == IResource.FILE) + entry = tree.findBlobMember(name); + else + entry = tree.findTreeMember(name); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();
org.spearce.egit.core/src/org/spearce/egit/core/internal/mapping/GitFileHistory.java +9 -2
@@ -147,7 +147,11 @@ public class GitFileHistory extends FileHistory implements IAdaptable { ObjectId[] currentResourceHash = new ObjectId[lastResourceHash.length]; Tree t = current.getTree(); for (int i = 0; i < currentResourceHash.length; ++i) { - TreeEntry m = t.findMember(relativeResourceName[i]); + TreeEntry m; + if (i == relativeResourceName.length-1 && resource.getType() == IResource.FILE) + m = t.findBlobMember(relativeResourceName[i]); + else + m = t.findTreeMember(relativeResourceName[i]); if (m != null) { ObjectId id = m.getId(); currentResourceHash[i] = id;
@@ -251,7 +255,10 @@ public class GitFileHistory extends FileHistory implements IAdaptable { } TreeEntry currentEntry = current.getTree(); for (int i=0; i < relativeResourceName.length && currentEntry != null; ++i) { - ((Tree)currentEntry).findMember(relativeResourceName[i]); + if (i == relativeResourceName.length-1 && resource.getType() == IResource.FILE) + ((Tree)currentEntry).findBlobMember(relativeResourceName[i]); + else + ((Tree)currentEntry).findTreeMember(relativeResourceName[i]); } if (currentEntry != null) revisions = new IFileRevision[] { new GitFileRevision(current, resource,
org.spearce.egit.core/src/org/spearce/egit/core/internal/mapping/GitFileRevision.java +4 -1
@@ -156,7 +156,10 @@ public class GitFileRevision extends FileRevision { else { prefix = prefix + "/"; String name = prefix + relPath; - return tree.findMember(name); + if (resource.getType() == IResource.FILE) + return tree.findBlobMember(name); + else + return tree.findTreeMember(name); } } else return tree;
org.spearce.egit.core/src/org/spearce/egit/core/op/TrackOperation.java +5 -3
@@ -137,12 +137,14 @@ public class TrackOperation implements IWorkspaceRunnable { // Uh, what? Why are we adding a phantom resource? Just say no! // } else if (toAdd instanceof IFile) { - if (!t.exists(path)) { - t.addFile(path); + if (!t.existsTree(path)) { + if (!t.existsBlob(path)) { + t.addFile(path); + } } } else if (toAdd instanceof IContainer) { final IResource[] m = ((IContainer) toAdd).members(); - final TreeEntry e = t.findMember(path); + final TreeEntry e = t.findTreeMember(path); final Tree c; c = e instanceof Tree ? (Tree) e : e == null ? t.addTree(path) : null;
org.spearce.egit.core/src/org/spearce/egit/core/op/UntrackOperation.java +5 -1
@@ -120,7 +120,11 @@ public class UntrackOperation implements IWorkspaceRunnable { try { final Tree t = m.getCacheTree(); - final TreeEntry e = t.findMember(s); + final TreeEntry e; + if (torm.getType() == IResource.FILE) + e = t.findBlobMember(s); + else + e = t.findTreeMember(s); if (e != null) { e.delete(); tomerge.put(m, m);
org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java +8 -2
@@ -296,7 +296,10 @@ public class GitProjectData { if (s != null && m != null && m.getActiveDiff() != null) { try { - return m.getActiveDiff().findMember(s); + if (r.getType() == IResource.FILE) + return m.getActiveDiff().findBlobMember(s); + else + return m.getActiveDiff().findTreeMember(s); } catch (IOException ioe) { throw Activator.error( CoreText.GitProjectData_lazyResolveFailed, ioe);
@@ -416,7 +419,10 @@ public class GitProjectData { try { synchronized (cacheTree) { final TreeEntry e; - e = cacheTree.findMember(s); + if (r.getType() == IResource.FILE) + e = cacheTree.findBlobMember(s); + else + e = cacheTree.findTreeMember(s); if (e instanceof FileTreeEntry) { trace("modified " + r + " -> " + e.getFullName());
org.spearce.egit.core/src/org/spearce/egit/core/project/RepositoryMapping.java +1 -1
@@ -210,7 +210,7 @@ public class RepositoryMapping { Tree head = getRepository().mapTree(Constants.HEAD); if (head != null) { if (getSubset() != null) { - final TreeEntry e = head.findMember(getSubset()); + final TreeEntry e = head.findTreeMember(getSubset()); e.detachParent(); head = e instanceof Tree ? (Tree) e : null; }
org.spearce.jgit/org.spearce.jgit--All-Tests.launch +6 -0
@@ -3,11 +3,17 @@ <booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/> <stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> +<listEntry value="4"/> +</listAttribute> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.spearce.jgit"/> <listAttribute key="org.eclipse.debug.ui.favoriteGroups"> <listEntry value="org.eclipse.debug.ui.launchGroup.run"/> <listEntry value="org.eclipse.debug.ui.launchGroup.debug"/> </listAttribute> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> +<listEntry value="/org.spearce.jgit"/> +</listAttribute> <stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.spearce.jgit"/> <booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> <stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
org.spearce.jgit/src/org/spearce/jgit/lib/MergedTree.java +19 -8
@@ -53,7 +53,7 @@ public class MergedTree { } private static final int binarySearch(final TreeEntry[] entries, - final int width, final byte[] nameUTF8, final int nameStart, + final int width, final byte[] nameUTF8, final byte nameUTF8last, final int nameStart, final int nameEnd) { if (entries.length == 0) return -1;
@@ -66,7 +66,7 @@ public class MergedTree { while (entries[ix] == null) ix++; cmp = Tree.compareNames(entries[ix].getNameUTF8(), nameUTF8, - nameStart, nameEnd); + nameStart, nameEnd, TreeEntry.lastChar(entries[ix]), nameUTF8last); if (cmp < 0) low = mid + 1; else if (cmp == 0)
@@ -95,11 +95,11 @@ public class MergedTree { return isModified(sources); } - public TreeEntry[] findMember(final String s) throws IOException { - return findMember(s.getBytes(Constants.CHARACTER_ENCODING), 0); + public TreeEntry[] findMember(final String s, final byte slast) throws IOException { + return findMember(s.getBytes(Constants.CHARACTER_ENCODING), slast, 0); } - public TreeEntry[] findMember(final byte[] s, final int offset) + public TreeEntry[] findMember(final byte[] s, final byte slast, final int offset) throws IOException { final int srcCnt = sources.length; int slash;
@@ -108,7 +108,8 @@ public class MergedTree { for (slash = offset; slash < s.length && s[slash] != '/'; slash++) { // search for path component terminator } - p = binarySearch(merged, srcCnt, s, offset, slash); + byte xlast = slash<s.length ? (byte)'/' : slast; + p = binarySearch(merged, srcCnt, s, xlast, offset, slash); if (p < 0) return null;
@@ -127,7 +128,15 @@ public class MergedTree { subs[j] = merged[k] instanceof Tree ? (Tree) merged[k] : null; subtrees[p] = new MergedTree(subs); } - return subtrees[p].findMember(s, slash + 1); + return subtrees[p].findMember(s, slast, slash + 1); + } + + public TreeEntry[] findBlobMember(String s) throws IOException { + return findMember(s,(byte)0); + } + + public TreeEntry[] findTreeMember(String s) throws IOException { + return findMember(s,(byte)'/'); } private void matchByName() throws IOException {
@@ -160,6 +169,7 @@ public class MergedTree { newMerged = new TreeEntry[pos * srcCnt]; for (pos = 0, treeId = 0; done < srcCnt; pos += srcCnt, treeId++) { byte[] minName = null; + int minNameLast = 0; if ((pos + srcCnt) >= newMerged.length) { final TreeEntry[] t = new TreeEntry[newMerged.length * 2];
@@ -176,10 +186,11 @@ public class MergedTree { final TreeEntry thisEntry = ents[ti]; final int cmp = minName == null ? -1 : Tree.compareNames( - thisEntry.getNameUTF8(), minName); + thisEntry.getNameUTF8(), minName, TreeEntry.lastChar(thisEntry), minNameLast); if (cmp < 0) { minName = thisEntry.getNameUTF8(); + minNameLast = TreeEntry.lastChar(thisEntry); for (int j = srcId - 1; j >= 0; j--) { if (newMerged[pos + j] != null) { newMerged[pos + j] = null;
org.spearce.jgit/src/org/spearce/jgit/lib/ObjectWriter.java +0 -7
@@ -25,7 +25,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.security.MessageDigest; -import java.util.Arrays; import java.util.Iterator; import java.util.zip.Deflater; import java.util.zip.DeflaterOutputStream;
@@ -82,12 +81,6 @@ public class ObjectWriter { public ObjectId writeTree(final Tree t) throws IOException { final ByteArrayOutputStream o = new ByteArrayOutputStream(); final TreeEntry[] items = t.members(); - for (int k = items.length - 1; k >= 0; k--) { - if (items[k] instanceof Tree) { - Arrays.sort(items, SubtreeSorter.INSTANCE); - break; - } - } for (int k = 0; k < items.length; k++) { final TreeEntry e = items[k]; final ObjectId id = e.getId();
org.spearce.jgit/src/org/spearce/jgit/lib/SubtreeSorter.java deleted +0 -40
@@ -1,40 +0,0 @@ -package org.spearce.jgit.lib; - -import java.util.Comparator; - -public class SubtreeSorter implements Comparator { - public static final SubtreeSorter INSTANCE = new SubtreeSorter(); - - public int compare(final Object o1, final Object o2) { - final TreeEntry a = (TreeEntry) o1; - final TreeEntry b = (TreeEntry) o2; - final byte[] aName = a.getNameUTF8(); - final byte[] bName = b.getNameUTF8(); - - for (int k = 0; k < aName.length && k < bName.length; k++) { - if (aName[k] < bName[k]) - return -1; - else if (aName[k] > bName[k]) - return 1; - } - - if (aName.length < bName.length) { - if (a instanceof Tree && '/' > bName[aName.length]) - return 1; - return -1; - } else if (aName.length == bName.length) { - if (a instanceof Tree && b instanceof Tree) - return 0; - else if (a instanceof Tree) - return 1; - else if (b instanceof Tree) - return -1; - else - return 0; - } else { - if (b instanceof Tree && aName[bName.length] < '/') - return -1; - return 1; - } - } -}
org.spearce.jgit/src/org/spearce/jgit/lib/Tree.java +59 -26
190 lines not on this page · raw message
org.spearce.jgit/src/org/spearce/jgit/lib/TreeEntry.java +8 -1
@@ -126,10 +126,17 @@ public abstract class TreeEntry implements Comparable { if (this == o) return 0; if (o instanceof TreeEntry) - return Tree.compareNames(nameUTF8, ((TreeEntry) o).nameUTF8); + return Tree.compareNames(nameUTF8, ((TreeEntry) o).nameUTF8, lastChar(this), lastChar((TreeEntry)o)); return -1; } + final public static int lastChar(TreeEntry treeEntry) { + if (treeEntry instanceof FileTreeEntry) + return '\0'; + else + return '/'; + } + public void accept(final TreeVisitor tv) throws IOException { accept(tv, 0); }
org.spearce.jgit/tst/org/spearce/jgit/lib/T0002_Tree.java +17 -16
@@ -38,7 +38,8 @@ public class T0002_Tree extends RepositoryTestCase { assertTrue("no id", t.getId() == null); assertTrue("tree is self", t.getTree() == t); assertTrue("database is r", t.getRepository() == db); - assertTrue("no foo child", t.findMember("foo") == null); + assertTrue("no foo child", t.findTreeMember("foo") == null); + assertTrue("no foo child", t.findBlobMember("foo") == null); } public void test002_addFile() throws IOException {
@@ -57,7 +58,7 @@ public class T0002_Tree extends RepositoryTestCase { assertTrue("no id", f.getId() == null); assertTrue("is modified", t.isModified()); assertTrue("has no id", t.getId() == null); - assertTrue("found bob", t.findMember(f.getName()) == f); + assertTrue("found bob", t.findBlobMember(f.getName()) == f); final TreeEntry[] i = t.members(); assertTrue("iterator is not empty", i != null && i.length > 0);
@@ -87,7 +88,7 @@ public class T0002_Tree extends RepositoryTestCase { assertTrue("tree is self", f.getTree() == f); assertTrue("parent is modified", t.isModified()); assertTrue("parent has no id", t.getId() == null); - assertTrue("found bob child", t.findMember(f.getName()) == f); + assertTrue("found bob child", t.findTreeMember(f.getName()) == f); final TreeEntry[] i = t.members(); assertTrue("iterator is not empty", i.length > 0);
@@ -145,14 +146,14 @@ public class T0002_Tree extends RepositoryTestCase { assertTrue("t not modified.", !t.isModified()); assertEquals("full path of h ok", "f/g/h", h.getFullName()); - assertTrue("Can find h", t.findMember(h.getFullName()) == h); - assertTrue("Can't find f/z", t.findMember("f/z") == null); - assertTrue("Can't find y/z", t.findMember("y/z") == null); + assertTrue("Can find h", t.findTreeMember(h.getFullName()) == h); + assertTrue("Can't find f/z", t.findBlobMember("f/z") == null); + assertTrue("Can't find y/z", t.findBlobMember("y/z") == null); final FileTreeEntry i = h.addFile("i"); assertNotNull(i); assertEquals("full path of i ok", "f/g/h/i", i.getFullName()); - assertTrue("Can find i", t.findMember(i.getFullName()) == i); + assertTrue("Can find i", t.findBlobMember(i.getFullName()) == i); assertTrue("h modified", h.isModified()); assertTrue("g modified", g.isModified()); assertTrue("f modified", f.isModified());
@@ -190,17 +191,17 @@ public class T0002_Tree extends RepositoryTestCase { public void test008_SubtreeInternalSorting() throws IOException { final Tree t = new Tree(db); - final FileTreeEntry e0 = t.addFile("a-"); - final FileTreeEntry e1 = t.addFile("a-b"); - final Tree e2 = t.addTree("a"); - final FileTreeEntry e3 = t.addFile("a="); - final FileTreeEntry e4 = t.addFile("a=b"); + final FileTreeEntry e0 = t.addFile("a-b"); + final FileTreeEntry e1 = t.addFile("a-"); + final FileTreeEntry e2 = t.addFile("a=b"); + final Tree e3 = t.addTree("a"); + final FileTreeEntry e4 = t.addFile("a="); final TreeEntry[] ents = t.members(); - assertSame(e2, ents[0]); + assertSame(e1, ents[0]); assertSame(e0, ents[1]); - assertSame(e1, ents[2]); - assertSame(e3, ents[3]); - assertSame(e4, ents[4]); + assertSame(e3, ents[2]); + assertSame(e4, ents[3]); + assertSame(e2, ents[4]); } }
org.spearce.jgit/tst/org/spearce/jgit/lib/T0006_DeepSpeedTest.java +1 -1
@@ -39,7 +39,7 @@ public class T0006_DeepSpeedTest extends SpeedTestBase { if (parent.size() > 0) { ObjectId parentId = (ObjectId) parent.get(0); commit = db.mapCommit(parentId); - TreeEntry m = commit.getTree().findMember("net/netfilter/nf_queue.c"); + TreeEntry m = commit.getTree().findBlobMember("net/netfilter/nf_queue.c"); if (m != null) commit.getCommitId().toString(); ++n;
Re: [EGIT PATCH 2/4] Use the Git sort order.
Oops, lost the decoration here.
-- robin
org.spearce.egit.core/src/org/spearce/egit renamed from org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java +0 -0
/core/project/GitProjectData.java
index 0c4683e..5c250c0 100644
org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java +3 -3
@@ -274,11 +274,11 @@ public class GitProjectData { return (RepositoryMapping) c2mapping.get(r); } - public TreeEntry[] getActiveDiffTreeEntries(IResource r) + public TreeEntry[] getActiveDiffTreeEntries(IResource res) throws CoreException { String s = null; RepositoryMapping m = null; - + IResource r = res; while (r != null) { m = getRepositoryMapping(r); if (m != null) {
@@ -296,7 +296,7 @@ public class GitProjectData { if (s != null && m != null && m.getActiveDiff() != null) { try { - if (r.getType() == IResource.FILE) + if (res.getType() == IResource.FILE) return m.getActiveDiff().findBlobMember(s); else return m.getActiveDiff().findTreeMember(s);
Re: [EGIT PATCH 2/4] Use the Git sort order.
Quoted 1 line · Robin Rosenberg
Oops, lost the decoration here.
Thanks, I applied all 6 patches. Good stuff.
Unfortunately this particular patch was totally damaged beyond repair. What happened to it? I redid the changes by hand, as even after fixing the line wrapping on the diff --git header line git-am -3 --whitespace=strip was unable to apply the patch to 0c4683e. The patch doesn't apply, at all, to that blob.
Quoted 28 lines
org.spearce.egit.core/src/org/spearce/egit renamed from org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java +0
-0/core/project/GitProjectData.java
index 0c4683e..5c250c0 100644org.spearce.egit.core/src/org/spearce/egit/core/project/GitProjectData.java +3
-3@@ -274,11 +274,11 @@ public class GitProjectData { return (RepositoryMapping) c2mapping.get(r); } - public TreeEntry[] getActiveDiffTreeEntries(IResource r) + public TreeEntry[] getActiveDiffTreeEntries(IResource res) throws CoreException { String s = null; RepositoryMapping m = null; - + IResource r = res; while (r != null) { m = getRepositoryMapping(r); if (m != null) {@@ -296,7 +296,7 @@ public class GitProjectData { if (s != null && m != null && m.getActiveDiff() != null) { try { - if (r.getType() == IResource.FILE) + if (res.getType() == IResource.FILE) return m.getActiveDiff().findBlobMember(s); else return m.getActiveDiff().findTreeMember(s);
Signature · 1 line
Shawn.
PATCH 3/4 Add writeRef method and make writeSymref public.
In reply to Robin RosenbergThe writeRef method is for creating tags and branches. writeSymref is for creating symbols like HEAD.
---
.../src/org/spearce/jgit/lib/Repository.java | 31 ++++++++++++++++++++++- 1 files changed, 30 insertions(+), 1 deletions(-)
org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java +30 -1
@@ -349,7 +349,36 @@ public class Repository { } } - private void writeSymref(final String name, final String target) + public void writeRef(String name, ObjectId id) throws IOException { + File f = new File(gitDir, name); + File t = File.createTempFile("ref", null, gitDir); + FileWriter w = new FileWriter(t); + try { + w.write(id.toString()); + w.write('\n'); + w.close(); + w = null; + if (!t.renameTo(f)) { + f.getParentFile().mkdirs(); + if (!t.renameTo(f)) { + f.delete(); + if (!t.renameTo(f)) { + t.delete(); + throw new ObjectWritingException("Unable to" + + " write ref " + name + " to point to " + + id.toString()); + } + } + } + } finally { + if (w != null) { + w.close(); + t.delete(); + } + } + } + + public void writeSymref(final String name, final String target) throws IOException { final File s = new File(gitDir, name); final File t = File.createTempFile("srf", null, gitDir);
PATCH 4/4 Add a JUnit test project for egit.
In reply to Robin Rosenberg---
org.spearce.egit.core.test/.classpath | 7 org.spearce.egit.core.test/.project | 28 ++ .../.settings/org.eclipse.jdt.core.prefs | 320 +++++++++++++++++++++++ .../.settings/org.eclipse.jdt.ui.prefs | 10 + org.spearce.egit.core.test/META-INF/MANIFEST.MF | 19 + org.spearce.egit.core.test/build.properties | 4 .../org.spearce.egit.core--All-Tests.launch | 39 +++ .../egit/core/internal/mapping/T0002_history.java | 108 ++++++++ .../op/T0001_ConnectProviderOperationTest.java | 118 ++++++++ .../src/org/spearce/egit/core/test/Activator.java | 50 ++++ .../org/spearce/egit/core/test/GitTestCase.java | 46 +++ .../org/spearce/egit/core/test/TestProject.java | 169 ++++++++++++ 12 files changed, 918 insertions(+), 0 deletions(-)
org.spearce.egit.core.test/.classpath new file +7 -0
@@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="output" path="bin"/> +</classpath>
org.spearce.egit.core.test/.project new file +28 -0
@@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.spearce.egit.core.test</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription>
org.spearce.egit.core.test/.settings/org.eclipse.jdt.core.prefs new file +320 -0
320 lines not on this page · raw message
org.spearce.egit.core.test/.settings/org.eclipse.jdt.ui.prefs new file +10 -0
@@ -0,0 +1,10 @@ +#Mon Jan 29 20:38:19 EST 2007 +eclipse.preferences.version=1 +formatter_profile=_EGit +formatter_settings_version=10 +internal.default.compliance=user +org.eclipse.jdt.ui.ignorelowercasenames=true +org.eclipse.jdt.ui.importorder=java;javax;org;com; +org.eclipse.jdt.ui.ondemandthreshold=99 +org.eclipse.jdt.ui.staticondemandthreshold=99 +org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates/>
org.spearce.egit.core.test/META-INF/MANIFEST.MF new file +19 -0
@@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Test Plug-in +Bundle-SymbolicName: org.spearce.egit.core.test +Bundle-Version: 0.2.0 +Bundle-Activator: org.spearce.egit.core.test.Activator +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.team.core, + org.junit, + org.spearce.egit.core, + org.spearce.egit.ui, + org.spearce.jgit, + org.eclipse.core.filesystem +Eclipse-LazyStart: true +Import-Package: org.eclipse.core.resources, + org.eclipse.jdt.core, + org.eclipse.jdt.junit, + org.eclipse.jdt.launching +Export-Package: org.spearce.egit.core.internal.mapping
org.spearce.egit.core.test/build.properties new file +4 -0
@@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .
org.spearce.egit.core.test/org.spearce.egit.core--All-Tests.launch new file +39 -0
@@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<launchConfiguration type="org.eclipse.pde.ui.JunitLaunchConfig"> +<stringAttribute key="product" value="org.eclipse.sdk.ide"/> +<stringAttribute key="bootstrap" value=""/> +<booleanAttribute key="useProduct" value="true"/> +<booleanAttribute key="tracing" value="false"/> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> +<listEntry value="4"/> +</listAttribute> +<listAttribute key="org.eclipse.debug.ui.favoriteGroups"> +<listEntry value="org.eclipse.debug.ui.launchGroup.run"/> +<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/> +</listAttribute> +<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.spearce.egit.core.test"/> +<booleanAttribute key="automaticValidate" value="false"/> +<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> +<booleanAttribute key="automaticAdd" value="true"/> +<stringAttribute key="checked" value="[NONE]"/> +<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/> +<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/> +<booleanAttribute key="clearws" value="true"/> +<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/> +<stringAttribute key="pde.version" value="3.3"/> +<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-ea"/> +<booleanAttribute key="default" value="true"/> +<booleanAttribute key="clearConfig" value="true"/> +<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> +<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/> +<booleanAttribute key="useDefaultConfigArea" value="false"/> +<booleanAttribute key="useDefaultConfig" value="true"/> +<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.spearce.egit.core.test"/> +<booleanAttribute key="askclear" value="false"/> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> +<listEntry value="/org.spearce.egit.core.test"/> +</listAttribute> +<booleanAttribute key="includeOptional" value="true"/> +<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/> +</launchConfiguration>
org.spearce.egit.core.test/src/org/spearce/egit/core/internal/mapping/T0002_history.java new file +108 -0
108 lines not on this page · raw message
org.spearce.egit.core.test/src/org/spearce/egit/core/op/T0001_ConnectProviderOperationTest.java new file +118 -0
118 lines not on this page · raw message
org.spearce.egit.core.test/src/org/spearce/egit/core/test/Activator.java new file +50 -0
50 lines not on this page · raw message
org.spearce.egit.core.test/src/org/spearce/egit/core/test/GitTestCase.java new file +46 -0
46 lines not on this page · raw message
org.spearce.egit.core.test/src/org/spearce/egit/core/test/TestProject.java new file +169 -0
169 lines not on this page · raw message
Re: [EGIT PATCH 4/4] Add a JUnit test project for egit.
Match the version number of this plugin.
-- robin
org.spearce.egit.core.test/META-INF/MANIFEST.MF +1 -1
@@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Test Plug-in Bundle-SymbolicName: org.spearce.egit.core.test -Bundle-Version: 0.2.0 +Bundle-Version: 0.2.1.qualifier Bundle-Activator: org.spearce.egit.core.test.Activator Require-Bundle: org.eclipse.core.runtime, org.eclipse.team.core,