diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2010-06-24 15:16:32 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-06-25 17:46:40 -0700 |
commit | 4c14b7623dd2ff943350eb0f80d899b00450794f (patch) | |
tree | 14bfff02e4a58ef774e9e9ce6d5344ef7c33f219 /org.eclipse.jgit.test/tst/org/eclipse/jgit | |
parent | 77b39df5ecdcff4d0ef68e7441526426499914e3 (diff) | |
download | jgit-4c14b7623dd2ff943350eb0f80d899b00450794f.tar.gz jgit-4c14b7623dd2ff943350eb0f80d899b00450794f.zip |
Make lib.Repository abstract and lib.FileRepository its implementation
To support other storage models other than just the local filesystem,
we split the Repository class into a nearly abstract interface and
then create a concrete subclass called FileRepository with the file
based IO implementation.
We are using an abstract class for Repository rather than the much
more generic interface, as implementers will want to inherit a large
array of utility functions, such as resolve(String). Having these in
a base class makes it easy to inherit them.
This isn't the final home for lib.FileRepository. Future changes
will rename it into storage.file.FileRepository, but to do that we
need to also move a number of other related class, which we aren't
quite ready to do.
Change-Id: I1bd54ea0500337799a8e792874c272eb14d555f7
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
3 files changed, 31 insertions, 31 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java index 8a9bb52633..161bd3eff1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefUpdateTest.java @@ -664,7 +664,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { // Create new Repository instance, to reread caches and make sure our // assumptions are persistent. - Repository ndb = new Repository(db.getDirectory()); + Repository ndb = new FileRepository(db.getDirectory()); assertEquals(rb2, ndb.resolve("refs/heads/new/name")); assertNull(ndb.resolve("refs/heads/b")); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositorySetupWorkDirTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositorySetupWorkDirTest.java index 6e5e0054b8..e3617305f1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositorySetupWorkDirTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositorySetupWorkDirTest.java @@ -57,12 +57,12 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { public void testIsBare_CreateRepositoryFromArbitraryGitDir() throws Exception { File gitDir = getFile("workdir"); - assertTrue(new Repository(gitDir).isBare()); + assertTrue(new FileRepository(gitDir).isBare()); } public void testNotBare_CreateRepositoryFromDotGitGitDir() throws Exception { File gitDir = getFile("workdir", Constants.DOT_GIT); - Repository repo = new Repository(gitDir); + Repository repo = new FileRepository(gitDir); assertFalse(repo.isBare()); assertWorkdirPath(repo, "workdir"); assertGitdirPath(repo, "workdir", Constants.DOT_GIT); @@ -71,14 +71,14 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { public void testWorkdirIsParentDir_CreateRepositoryFromDotGitGitDir() throws Exception { File gitDir = getFile("workdir", Constants.DOT_GIT); - Repository repo = new Repository(gitDir); + Repository repo = new FileRepository(gitDir); String workdir = repo.getWorkDir().getName(); assertEquals(workdir, "workdir"); } public void testNotBare_CreateRepositoryFromWorkDirOnly() throws Exception { File workdir = getFile("workdir", "repo"); - Repository repo = new Repository(null, workdir); + Repository repo = new FileRepository(null, workdir); assertFalse(repo.isBare()); assertWorkdirPath(repo, "workdir", "repo"); assertGitdirPath(repo, "workdir", "repo", Constants.DOT_GIT); @@ -87,7 +87,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { public void testWorkdirIsDotGit_CreateRepositoryFromWorkDirOnly() throws Exception { File workdir = getFile("workdir", "repo"); - Repository repo = new Repository(null, workdir); + Repository repo = new FileRepository(null, workdir); assertGitdirPath(repo, "workdir", "repo", Constants.DOT_GIT); } @@ -96,7 +96,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { File gitDir = getFile("workdir", "repoWithConfig"); File workTree = getFile("workdir", "treeRoot"); setWorkTree(gitDir, workTree); - Repository repo = new Repository(gitDir, null); + Repository repo = new FileRepository(gitDir, null); assertFalse(repo.isBare()); assertWorkdirPath(repo, "workdir", "treeRoot"); assertGitdirPath(repo, "workdir", "repoWithConfig"); @@ -106,7 +106,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { throws Exception { File gitDir = getFile("workdir", "repoWithConfig"); setBare(gitDir, true); - Repository repo = new Repository(gitDir, null); + Repository repo = new FileRepository(gitDir, null); assertTrue(repo.isBare()); } @@ -114,7 +114,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { throws Exception { File gitDir = getFile("workdir", "repoWithBareConfigTrue", "child"); setBare(gitDir, false); - Repository repo = new Repository(gitDir, null); + Repository repo = new FileRepository(gitDir, null); assertWorkdirPath(repo, "workdir", "repoWithBareConfigTrue"); } @@ -122,7 +122,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { throws Exception { File gitDir = getFile("workdir", "repoWithBareConfigFalse", "child"); setBare(gitDir, false); - Repository repo = new Repository(gitDir, null); + Repository repo = new FileRepository(gitDir, null); assertFalse(repo.isBare()); assertWorkdirPath(repo, "workdir", "repoWithBareConfigFalse"); assertGitdirPath(repo, "workdir", "repoWithBareConfigFalse", "child"); @@ -130,7 +130,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { public void testNotBare_MakeBareUnbareBySetWorkdir() throws Exception { File gitDir = getFile("gitDir"); - Repository repo = new Repository(gitDir); + Repository repo = new FileRepository(gitDir); repo.setWorkDir(getFile("workingDir")); assertFalse(repo.isBare()); assertWorkdirPath(repo, "workingDir"); @@ -140,7 +140,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { public void testExceptionThrown_BareRepoGetWorkDir() throws Exception { File gitDir = getFile("workdir"); try { - new Repository(gitDir).getWorkDir(); + new FileRepository(gitDir).getWorkDir(); fail("Expected IllegalStateException missing"); } catch (IllegalStateException e) { // expected @@ -150,7 +150,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { public void testExceptionThrown_BareRepoGetIndex() throws Exception { File gitDir = getFile("workdir"); try { - new Repository(gitDir).getIndex(); + new FileRepository(gitDir).getIndex(); fail("Expected IllegalStateException missing"); } catch (IllegalStateException e) { // expected @@ -160,7 +160,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { public void testExceptionThrown_BareRepoGetIndexFile() throws Exception { File gitDir = getFile("workdir"); try { - new Repository(gitDir).getIndexFile(); + new FileRepository(gitDir).getIndexFile(); fail("Expected Exception missing"); } catch (IllegalStateException e) { // expected @@ -177,14 +177,14 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase { } private void setBare(File gitDir, boolean bare) throws IOException { - Repository repo = new Repository(gitDir, null); + Repository repo = new FileRepository(gitDir, null); repo.getConfig().setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_BARE, bare); repo.getConfig().save(); } private void setWorkTree(File gitDir, File workTree) throws IOException { - Repository repo = new Repository(gitDir, null); + Repository repo = new FileRepository(gitDir, null); repo.getConfig() .setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_WORKTREE, diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java index d96857498d..b44b9038e9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java @@ -80,7 +80,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { public void test000_openRepoBadArgs() throws IOException { try { - new Repository(null, null); + new FileRepository(null, null); fail("Must pass either GIT_DIR or GIT_WORK_TREE"); } catch (IllegalArgumentException e) { assertEquals( @@ -97,12 +97,12 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { */ public void test000_openrepo_default_gitDirSet() throws IOException { File repo1Parent = new File(trash.getParentFile(), "r1"); - Repository repo1initial = new Repository(new File(repo1Parent, Constants.DOT_GIT)); + Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT)); repo1initial.create(); repo1initial.close(); File theDir = new File(repo1Parent, Constants.DOT_GIT); - Repository r = new Repository(theDir, null); + Repository r = new FileRepository(theDir, null); assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(repo1Parent, r.getWorkDir()); assertEqualsPath(new File(theDir, "index"), r.getIndexFile()); @@ -117,12 +117,12 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { */ public void test000_openrepo_default_gitDirAndWorkTreeSet() throws IOException { File repo1Parent = new File(trash.getParentFile(), "r1"); - Repository repo1initial = new Repository(new File(repo1Parent, Constants.DOT_GIT)); + Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT)); repo1initial.create(); repo1initial.close(); File theDir = new File(repo1Parent, Constants.DOT_GIT); - Repository r = new Repository(theDir, repo1Parent.getParentFile()); + Repository r = new FileRepository(theDir, repo1Parent.getParentFile()); assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(repo1Parent.getParentFile(), r.getWorkDir()); assertEqualsPath(new File(theDir, "index"), r.getIndexFile()); @@ -137,12 +137,12 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { */ public void test000_openrepo_default_workDirSet() throws IOException { File repo1Parent = new File(trash.getParentFile(), "r1"); - Repository repo1initial = new Repository(new File(repo1Parent, Constants.DOT_GIT)); + Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT)); repo1initial.create(); repo1initial.close(); File theDir = new File(repo1Parent, Constants.DOT_GIT); - Repository r = new Repository(null, repo1Parent); + Repository r = new FileRepository(null, repo1Parent); assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(repo1Parent, r.getWorkDir()); assertEqualsPath(new File(theDir, "index"), r.getIndexFile()); @@ -159,7 +159,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { File repo1Parent = new File(trash.getParentFile(), "r1"); File workdir = new File(trash.getParentFile(), "rw"); workdir.mkdir(); - Repository repo1initial = new Repository(new File(repo1Parent, Constants.DOT_GIT)); + Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT)); repo1initial.create(); repo1initial.getConfig().setString("core", null, "worktree", workdir.getAbsolutePath()); @@ -167,7 +167,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { repo1initial.close(); File theDir = new File(repo1Parent, Constants.DOT_GIT); - Repository r = new Repository(theDir, null); + Repository r = new FileRepository(theDir, null); assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(workdir, r.getWorkDir()); assertEqualsPath(new File(theDir, "index"), r.getIndexFile()); @@ -184,7 +184,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { File repo1Parent = new File(trash.getParentFile(), "r1"); File workdir = new File(trash.getParentFile(), "rw"); workdir.mkdir(); - Repository repo1initial = new Repository(new File(repo1Parent, Constants.DOT_GIT)); + Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT)); repo1initial.create(); repo1initial.getConfig() .setString("core", null, "worktree", "../../rw"); @@ -192,7 +192,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { repo1initial.close(); File theDir = new File(repo1Parent, Constants.DOT_GIT); - Repository r = new Repository(theDir, null); + Repository r = new FileRepository(theDir, null); assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(workdir, r.getWorkDir()); assertEqualsPath(new File(theDir, "index"), r.getIndexFile()); @@ -211,12 +211,12 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { File indexFile = new File(trash, "idx"); File objDir = new File(trash, "../obj"); File[] altObjDirs = new File[] { db.getObjectsDirectory() }; - Repository repo1initial = new Repository(new File(repo1Parent, Constants.DOT_GIT)); + Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT)); repo1initial.create(); repo1initial.close(); File theDir = new File(repo1Parent, Constants.DOT_GIT); - Repository r = new Repository(theDir, null, objDir, altObjDirs, + Repository r = new FileRepository(theDir, null, objDir, altObjDirs, indexFile); assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(theDir.getParentFile(), r.getWorkDir()); @@ -321,7 +321,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { } public void test007_Open() throws IOException { - final Repository db2 = new Repository(db.getDirectory()); + final Repository db2 = new FileRepository(db.getDirectory()); assertEquals(db.getDirectory(), db2.getDirectory()); assertEquals(db.getObjectsDirectory(), db2.getObjectsDirectory()); assertNotSame(db.getConfig(), db2.getConfig()); @@ -337,7 +337,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase { pw.close(); try { - new Repository(db.getDirectory()); + new FileRepository(db.getDirectory()); fail("incorrectly opened a bad repository"); } catch (IOException ioe) { assertTrue(ioe.getMessage().indexOf("format") > 0); |