Browse Source

Remove deprecated Repository.mapTree

The mapTree() routines have been deprecated for a long time, and their
sibilings for mapCommit() and mapTag() were already removed from the
main Repository API.

Remove mapTree().  Application callers who only need the tree's name
can use resolve("^{tree}") syntax to resolve to the tree ObjectId, or
fail if the input is not a tree.

Applications that want to read a tree should use DirCache or TreeWalk.

Change-Id: I85726413790fc87721271c482f6636f81baf8b82
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.12
Shawn O. Pearce 14 years ago
parent
commit
ef822fe3cd
  1. 18
      org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java
  2. 9
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0002_TreeTest.java
  3. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java
  4. 47
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

18
org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java

@ -228,8 +228,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
assertEquals("c696abc3ab8e091c665f49d00eb8919690b3aec3", id.name());
GitIndex index2 = new GitIndex(db);
index2.readTree(db.mapTree(ObjectId.fromString(
"c696abc3ab8e091c665f49d00eb8919690b3aec3")));
index2.readTree(mapTree("c696abc3ab8e091c665f49d00eb8919690b3aec3"));
Entry[] members = index2.getMembers();
assertEquals(3, members.length);
assertEquals("a.b", members[0].getName());
@ -272,8 +271,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
assertEquals("ba78e065e2c261d4f7b8f42107588051e87e18e9", id.name());
GitIndex index2 = new GitIndex(db);
index2.readTree(db.mapTree(ObjectId.fromString(
"ba78e065e2c261d4f7b8f42107588051e87e18e9")));
index2.readTree(mapTree("ba78e065e2c261d4f7b8f42107588051e87e18e9"));
Entry[] members = index2.getMembers();
assertEquals(6, members.length);
assertEquals("a.b", members[0].getName());
@ -341,8 +339,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
GitIndex index2 = new GitIndex(db);
assertEquals(0, index2.getMembers().length);
index2.readTree(db.mapTree(ObjectId.fromString(
"c696abc3ab8e091c665f49d00eb8919690b3aec3")));
index2.readTree(mapTree("c696abc3ab8e091c665f49d00eb8919690b3aec3"));
index2.checkout(trash);
assertEquals("data:a/b", read(aslashb));
@ -375,7 +372,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
index.filemode = Boolean.TRUE; // TODO: we need a way to set this using config
index.add(trash, execFile);
index.add(trash, nonexecFile);
Tree tree = db.mapTree(index.writeTree());
Tree tree = mapTree(index.writeTree().name());
assertEquals(FileMode.EXECUTABLE_FILE, tree.findBlobMember(execFile.getName()).getMode());
assertEquals(FileMode.REGULAR_FILE, tree.findBlobMember(nonexecFile.getName()).getMode());
@ -431,7 +428,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
index.filemode = Boolean.FALSE; // TODO: we need a way to set this using config
index.add(trash, execFile);
index.add(trash, nonexecFile);
Tree tree = db.mapTree(index.writeTree());
Tree tree = mapTree(index.writeTree().name());
assertEquals(FileMode.REGULAR_FILE, tree.findBlobMember(execFile.getName()).getMode());
assertEquals(FileMode.REGULAR_FILE, tree.findBlobMember(nonexecFile.getName()).getMode());
@ -476,4 +473,9 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
write(path, body);
return path;
}
private Tree mapTree(String name) throws IOException {
ObjectId id = db.resolve(name + "^{tree}");
return new Tree(db, id, db.open(id).getCachedBytes());
}
}

9
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0002_TreeTest.java

@ -303,9 +303,14 @@ public class T0002_TreeTest extends SampleDataRepositoryTestCase {
@Test
public void test009_SymlinkAndGitlink() throws IOException {
final Tree symlinkTree = db.mapTree("symlink");
final Tree symlinkTree = mapTree("symlink");
assertTrue("Symlink entry exists", symlinkTree.existsBlob("symlink.txt"));
final Tree gitlinkTree = db.mapTree("gitlink");
final Tree gitlinkTree = mapTree("gitlink");
assertTrue("Gitlink entry exists", gitlinkTree.existsBlob("submodule"));
}
private Tree mapTree(String name) throws IOException {
ObjectId id = db.resolve(name + "^{tree}");
return new Tree(db, id, db.open(id).getCachedBytes());
}
}

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java

@ -71,7 +71,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
Merger ourMerger = MergeStrategy.OURS.newMerger(db);
boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a"), db.resolve("c") });
assertTrue(merge);
assertEquals(db.mapTree("a").getId(), ourMerger.getResultTreeId());
assertEquals(db.resolve("a^{tree}"), ourMerger.getResultTreeId());
}
@Test
@ -79,7 +79,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
Merger ourMerger = MergeStrategy.THEIRS.newMerger(db);
boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a"), db.resolve("c") });
assertTrue(merge);
assertEquals(db.mapTree("c").getId(), ourMerger.getResultTreeId());
assertEquals(db.resolve("c^{tree}"), ourMerger.getResultTreeId());
}
@Test
@ -103,7 +103,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
Merger ourMerger = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
boolean merge = ourMerger.merge(new ObjectId[] { db.resolve("a^0^0^0"), db.resolve("a^0^0^1") });
assertTrue(merge);
assertEquals(db.mapTree("a^0^0").getId(), ourMerger.getResultTreeId());
assertEquals(db.resolve("a^0^0^{tree}"), ourMerger.getResultTreeId());
}
@Test

47
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

@ -270,53 +270,6 @@ public abstract class Repository {
return getObjectDatabase().open(objectId, typeHint);
}
/**
* Access a Tree object using a symbolic reference. This reference may
* be a SHA-1 or ref in combination with a number of symbols translating
* from one ref or SHA1-1 to another, such as HEAD^{tree} etc.
*
* @param revstr a reference to a git commit object
* @return a Tree named by the specified string
* @throws IOException
*
* @see #resolve(String)
* @deprecated Use {@link #resolve(String)} and pass its return value to
* {@link org.eclipse.jgit.treewalk.TreeWalk#addTree(AnyObjectId)}.
*/
@Deprecated
public Tree mapTree(final String revstr) throws IOException {
final ObjectId id = resolve(revstr);
return id != null ? mapTree(id) : null;
}
/**
* Access a Tree by SHA'1 id.
* @param id
* @return Tree or null
* @throws IOException for I/O error or unexpected object type.
* @deprecated Use {@link org.eclipse.jgit.treewalk.TreeWalk#addTree(AnyObjectId)}.
*/
@Deprecated
public Tree mapTree(final ObjectId id) throws IOException {
final ObjectLoader or;
try {
or = open(id);
} catch (MissingObjectException notFound) {
return null;
}
final byte[] raw = or.getCachedBytes();
switch (or.getType()) {
case Constants.OBJ_TREE:
return new Tree(this, id, raw);
case Constants.OBJ_COMMIT:
return mapTree(ObjectId.fromString(raw, 5));
default:
throw new IncorrectObjectTypeException(id, Constants.TYPE_TREE);
}
}
/**
* Create a command to update, create or delete a ref in this repository.
*

Loading…
Cancel
Save