Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce2010-06-24 22:45:51 +0000
committerShawn O. Pearce2010-06-26 00:46:40 +0000
commit89d4a7377fc578524dd87289afc367287fd9e653 (patch)
treeb1c06be20f533c9b263ded8cc7ee5f3dae6259ee /org.eclipse.jgit.junit
parent4c14b7623dd2ff943350eb0f80d899b00450794f (diff)
downloadjgit-89d4a7377fc578524dd87289afc367287fd9e653.tar.gz
jgit-89d4a7377fc578524dd87289afc367287fd9e653.tar.xz
jgit-89d4a7377fc578524dd87289afc367287fd9e653.zip
Use FileRepository where we assume other file semantics
When the surrounding code is already heavily based upon the assumption that we have a FileRepository (e.g. because it created that type of repository) keep the type around and use it directly. This permits us to continue to do things like save the configuration file. Change-Id: Ib783f0f6a11acd6aa305c16d61ccc368b46beecc Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.junit')
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java8
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java102
2 files changed, 59 insertions, 51 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
index 100b632ae3..6920e91886 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
@@ -260,7 +260,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
* @throws IOException
* the repository could not be created in the temporary area
*/
- protected Repository createBareRepository() throws IOException {
+ protected FileRepository createBareRepository() throws IOException {
return createRepository(true /* bare */);
}
@@ -271,7 +271,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
* @throws IOException
* the repository could not be created in the temporary area
*/
- protected Repository createWorkRepository() throws IOException {
+ protected FileRepository createWorkRepository() throws IOException {
return createRepository(false /* not bare */);
}
@@ -285,11 +285,11 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
* @throws IOException
* the repository could not be created in the temporary area
*/
- private Repository createRepository(boolean bare) throws IOException {
+ private FileRepository createRepository(boolean bare) throws IOException {
String uniqueId = System.currentTimeMillis() + "_" + (testCount++);
String gitdirName = "test" + uniqueId + (bare ? "" : "/") + Constants.DOT_GIT;
File gitdir = new File(trash, gitdirName).getCanonicalFile();
- Repository db = new FileRepository(gitdir);
+ FileRepository db = new FileRepository(gitdir);
assertFalse(gitdir.exists());
db.create();
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
index 59504aa780..279762ac67 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
@@ -73,10 +73,10 @@ import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
+import org.eclipse.jgit.lib.FileRepository;
import org.eclipse.jgit.lib.LockFile;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectChecker;
-import org.eclipse.jgit.lib.ObjectDatabase;
import org.eclipse.jgit.lib.ObjectDirectory;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectWriter;
@@ -99,8 +99,13 @@ import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
-/** Wrapper to make creating test data easier. */
-public class TestRepository {
+/**
+ * Wrapper to make creating test data easier.
+ *
+ * @param <R>
+ * type of Repository the test data is stored on.
+ */
+public class TestRepository<R extends Repository> {
private static final PersonIdent author;
private static final PersonIdent committer;
@@ -119,7 +124,7 @@ public class TestRepository {
committer = new PersonIdent(cn, ce, now, tz);
}
- private final Repository db;
+ private final R db;
private final RevWalk pool;
@@ -132,9 +137,9 @@ public class TestRepository {
*
* @param db
* the test repository to write into.
- * @throws Exception
+ * @throws IOException
*/
- public TestRepository(Repository db) throws Exception {
+ public TestRepository(R db) throws IOException {
this(db, new RevWalk(db));
}
@@ -145,9 +150,9 @@ public class TestRepository {
* the test repository to write into.
* @param rw
* the RevObject pool to use for object lookup.
- * @throws Exception
+ * @throws IOException
*/
- public TestRepository(Repository db, RevWalk rw) throws Exception {
+ public TestRepository(R db, RevWalk rw) throws IOException {
this.db = db;
this.pool = rw;
this.writer = new ObjectWriter(db);
@@ -155,7 +160,7 @@ public class TestRepository {
}
/** @return the repository this helper class operates against. */
- public Repository getRepository() {
+ public R getRepository() {
return db;
}
@@ -443,25 +448,27 @@ public class TestRepository {
* @throws Exception
*/
public void updateServerInfo() throws Exception {
- final ObjectDatabase odb = db.getObjectDatabase();
- if (odb instanceof ObjectDirectory) {
- RefWriter rw = new RefWriter(db.getAllRefs().values()) {
+ if (db instanceof FileRepository) {
+ final FileRepository fr = (FileRepository) db;
+ RefWriter rw = new RefWriter(fr.getAllRefs().values()) {
@Override
protected void writeFile(final String name, final byte[] bin)
throws IOException {
- TestRepository.this.writeFile(name, bin);
+ File path = new File(fr.getDirectory(), name);
+ TestRepository.this.writeFile(path, bin);
}
};
rw.writePackedRefs();
rw.writeInfoRefs();
final StringBuilder w = new StringBuilder();
- for (PackFile p : ((ObjectDirectory) odb).getPacks()) {
+ for (PackFile p : fr.getObjectDatabase().getPacks()) {
w.append("P ");
w.append(p.getPackFile().getName());
w.append('\n');
}
- writeFile("objects/info/packs", Constants.encodeASCII(w.toString()));
+ writeFile(new File(new File(fr.getObjectDatabase().getDirectory(),
+ "info"), "packs"), Constants.encodeASCII(w.toString()));
}
}
@@ -563,38 +570,40 @@ public class TestRepository {
* @throws Exception
*/
public void packAndPrune() throws Exception {
- final ObjectDirectory odb = (ObjectDirectory) db.getObjectDatabase();
- final PackWriter pw = new PackWriter(db, NullProgressMonitor.INSTANCE);
-
- Set<ObjectId> all = new HashSet<ObjectId>();
- for (Ref r : db.getAllRefs().values())
- all.add(r.getObjectId());
- pw.preparePack(all, Collections.<ObjectId> emptySet());
-
- final ObjectId name = pw.computeName();
- OutputStream out;
+ if (db.getObjectDatabase() instanceof ObjectDirectory) {
+ ObjectDirectory odb = (ObjectDirectory) db.getObjectDatabase();
+ PackWriter pw = new PackWriter(db, NullProgressMonitor.INSTANCE);
- final File pack = nameFor(odb, name, ".pack");
- out = new BufferedOutputStream(new FileOutputStream(pack));
- try {
- pw.writePack(out);
- } finally {
- out.close();
- }
- pack.setReadOnly();
+ Set<ObjectId> all = new HashSet<ObjectId>();
+ for (Ref r : db.getAllRefs().values())
+ all.add(r.getObjectId());
+ pw.preparePack(all, Collections.<ObjectId> emptySet());
+
+ final ObjectId name = pw.computeName();
+ OutputStream out;
+
+ final File pack = nameFor(odb, name, ".pack");
+ out = new BufferedOutputStream(new FileOutputStream(pack));
+ try {
+ pw.writePack(out);
+ } finally {
+ out.close();
+ }
+ pack.setReadOnly();
+
+ final File idx = nameFor(odb, name, ".idx");
+ out = new BufferedOutputStream(new FileOutputStream(idx));
+ try {
+ pw.writeIndex(out);
+ } finally {
+ out.close();
+ }
+ idx.setReadOnly();
- final File idx = nameFor(odb, name, ".idx");
- out = new BufferedOutputStream(new FileOutputStream(idx));
- try {
- pw.writeIndex(out);
- } finally {
- out.close();
+ odb.openPack(pack, idx);
+ updateServerInfo();
+ prunePacked(odb);
}
- idx.setReadOnly();
-
- odb.openPack(pack, idx);
- updateServerInfo();
- prunePacked(odb);
}
private void prunePacked(ObjectDirectory odb) {
@@ -609,9 +618,8 @@ public class TestRepository {
return new File(packdir, "pack-" + name.name() + t);
}
- private void writeFile(final String name, final byte[] bin)
- throws IOException, ObjectWritingException {
- final File p = new File(db.getDirectory(), name);
+ private void writeFile(final File p, final byte[] bin) throws IOException,
+ ObjectWritingException {
final LockFile lck = new LockFile(p);
if (!lck.lock())
throw new ObjectWritingException("Can't write " + p);

Back to the top