From 1e84e8ad935aa22ca0f6f1d00dfed4a07878ef6f Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 5 Oct 2009 11:25:43 -0700 Subject: [PATCH] Refactor RepositoryTestCase to use LocalDiskRepository instead Change-Id: I07014d1b8cc2fab0761d644a12e4ae04f0adf3ef Signed-off-by: Shawn O. Pearce --- org.eclipse.jgit.test/META-INF/MANIFEST.MF | 1 + org.eclipse.jgit.test/pom.xml | 5 + .../jgit/lib/ConcurrentRepackTest.java | 8 +- .../eclipse/jgit/lib/MockSystemReader.java | 97 -------- .../eclipse/jgit/lib/ReflogConfigTest.java | 13 +- .../eclipse/jgit/lib/RepositoryCacheTest.java | 4 +- .../jgit/lib/RepositoryConfigTest.java | 11 +- .../eclipse/jgit/lib/RepositoryTestCase.java | 234 ++---------------- .../tst/org/eclipse/jgit/lib/T0003_Basic.java | 51 ++-- .../eclipse/jgit/revwalk/RevWalkTestCase.java | 6 +- .../jgit/transport/BundleWriterTest.java | 8 +- 11 files changed, 79 insertions(+), 359 deletions(-) delete mode 100644 org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MockSystemReader.java diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF index 225611ba9..32d5efdfc 100644 --- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF @@ -10,6 +10,7 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: com.jcraft.jsch, junit.framework, junit.textui, + org.eclipse.jgit.junit, org.eclipse.jgit.diff, org.eclipse.jgit.dircache, org.eclipse.jgit.errors, diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml index 2eb8f9aa7..6938ea60a 100644 --- a/org.eclipse.jgit.test/pom.xml +++ b/org.eclipse.jgit.test/pom.xml @@ -67,6 +67,11 @@ org.eclipse.jgit org.eclipse.jgit + + + org.eclipse.jgit + org.eclipse.jgit.junit + diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConcurrentRepackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConcurrentRepackTest.java index 644c7b366..9e83aa0e1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConcurrentRepackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConcurrentRepackTest.java @@ -72,7 +72,7 @@ public void testObjectInNewPack() throws IncorrectObjectTypeException, IOException { // Create a new object in a new pack, and test that it is present. // - final Repository eden = createNewEmptyRepo(); + final Repository eden = createBareRepository(); final RevObject o1 = writeBlob(eden, "o1"); pack(eden, o1); assertEquals(o1.name(), parse(o1).name()); @@ -84,7 +84,7 @@ public void testObjectMovedToNewPack1() // object into a different pack file, with some other object. We // still should be able to access the objects. // - final Repository eden = createNewEmptyRepo(); + final Repository eden = createBareRepository(); final RevObject o1 = writeBlob(eden, "o1"); final File[] out1 = pack(eden, o1); assertEquals(o1.name(), parse(o1).name()); @@ -108,7 +108,7 @@ public void testObjectMovedWithinPack() throws IncorrectObjectTypeException, IOException { // Create an object and pack it. // - final Repository eden = createNewEmptyRepo(); + final Repository eden = createBareRepository(); final RevObject o1 = writeBlob(eden, "o1"); final File[] out1 = pack(eden, o1); assertEquals(o1.name(), parse(o1).name()); @@ -141,7 +141,7 @@ public void testObjectMovedToNewPack2() // object into a different pack file, with some other object. We // still should be able to access the objects. // - final Repository eden = createNewEmptyRepo(); + final Repository eden = createBareRepository(); final RevObject o1 = writeBlob(eden, "o1"); final File[] out1 = pack(eden, o1); assertEquals(o1.name(), parse(o1).name()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MockSystemReader.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MockSystemReader.java deleted file mode 100644 index 2e94632ce..000000000 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/MockSystemReader.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2009, Google Inc. - * Copyright (C) 2009, Robin Rosenberg - * Copyright (C) 2009, Yann Simon - * and other copyright owners as documented in the project's IP log. - * - * This program and the accompanying materials are made available - * under the terms of the Eclipse Distribution License v1.0 which - * accompanies this distribution, is reproduced below, and is - * available at http://www.eclipse.org/org/documents/edl-v10.php - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * - Neither the name of the Eclipse Foundation, Inc. nor the - * names of its contributors may be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.eclipse.jgit.lib; - -import java.util.HashMap; -import java.util.Map; -import java.util.TimeZone; - -import org.eclipse.jgit.util.SystemReader; - -class MockSystemReader extends SystemReader { - final Map values = new HashMap(); - - FileBasedConfig userGitConfig; - - MockSystemReader() { - init(Constants.OS_USER_NAME_KEY); - init(Constants.GIT_AUTHOR_NAME_KEY); - init(Constants.GIT_AUTHOR_EMAIL_KEY); - init(Constants.GIT_COMMITTER_NAME_KEY); - init(Constants.GIT_COMMITTER_EMAIL_KEY); - userGitConfig = new FileBasedConfig(null); - } - - private void init(final String n) { - values.put(n, n); - } - - public String getenv(String variable) { - return values.get(variable); - } - - public String getProperty(String key) { - return values.get(key); - } - - public FileBasedConfig openUserConfig() { - return userGitConfig; - } - - public String getHostname() { - return "fake.host.example.com"; - } - - @Override - public long getCurrentTime() { - return 1250379778668L; // Sat Aug 15 20:12:58 GMT-03:30 2009 - } - - @Override - public int getTimezone(long when) { - return TimeZone.getTimeZone("GMT-3:30").getOffset(when); - } -} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java index e72b7e215..f3b150fa4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java @@ -1,6 +1,7 @@ /* * Copyright (C) 2009, Christian Halstrick * Copyright (C) 2009, Christian Halstrick, Matthias Sohn, SAP AG + * Copyright (C) 2009, Google Inc. * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -61,8 +62,8 @@ public void testlogAllRefUpdates() throws Exception { // written final Tree t = new Tree(db); addFileToTree(t, "i-am-a-file", "and this is the data in me\n"); - commit(t, "A Commit\n", new PersonIdent(jauthor, commitTime, tz), - new PersonIdent(jcommitter, commitTime, tz)); + commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz), + new PersonIdent(committer, commitTime, tz)); commitTime += 100; assertTrue( "Reflog for HEAD still contain no entry", @@ -74,8 +75,8 @@ public void testlogAllRefUpdates() throws Exception { // do one commit and check that reflog size is increased to 1 addFileToTree(t, "i-am-another-file", "and this is other data in me\n"); - commit(t, "A Commit\n", new PersonIdent(jauthor, commitTime, tz), - new PersonIdent(jcommitter, commitTime, tz)); + commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz), + new PersonIdent(committer, commitTime, tz)); commitTime += 100; assertTrue( "Reflog for HEAD should contain one entry", @@ -88,8 +89,8 @@ public void testlogAllRefUpdates() throws Exception { // do one commit and check that reflog size is 2 addFileToTree(t, "i-am-anotheranother-file", "and this is other other data in me\n"); - commit(t, "A Commit\n", new PersonIdent(jauthor, commitTime, tz), - new PersonIdent(jcommitter, commitTime, tz)); + commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz), + new PersonIdent(committer, commitTime, tz)); assertTrue( "Reflog for HEAD should contain two entries", db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 2); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java index c0591755f..f05889308 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java @@ -64,7 +64,7 @@ public void testNonBareFileKey() { } public void testBareFileKey() throws IOException { - Repository bare = createNewEmptyRepo(true); + Repository bare = createBareRepository(); File gitdir = bare.getDirectory(); File parent = gitdir.getParentFile(); String name = gitdir.getName(); @@ -92,7 +92,7 @@ public void testFileKeyOpenExisting() throws IOException { } public void testFileKeyOpenNew() throws IOException { - final Repository n = createNewEmptyRepo(true); + final Repository n = createBareRepository(); final File gitdir = n.getDirectory(); n.close(); recursiveDelete(gitdir); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java index 08e701ab5..2cbfc682c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryConfigTest.java @@ -53,6 +53,7 @@ import junit.framework.TestCase; import org.eclipse.jgit.errors.ConfigInvalidException; +import org.eclipse.jgit.junit.MockSystemReader; import org.eclipse.jgit.util.SystemReader; /** @@ -115,9 +116,9 @@ public void test007_readUserConfig() { final MockSystemReader mockSystemReader = new MockSystemReader(); SystemReader.setInstance(mockSystemReader); final String hostname = mockSystemReader.getHostname(); - final Config userGitConfig = mockSystemReader.userGitConfig; + final Config userGitConfig = mockSystemReader.openUserConfig(); final Config localConfig = new Config(userGitConfig); - mockSystemReader.values.clear(); + mockSystemReader.clearProperties(); String authorName; String authorEmail; @@ -129,7 +130,7 @@ public void test007_readUserConfig() { assertEquals(Constants.UNKNOWN_USER_DEFAULT + "@" + hostname, authorEmail); // the system user name is defined - mockSystemReader.values.put(Constants.OS_USER_NAME_KEY, "os user name"); + mockSystemReader.setProperty(Constants.OS_USER_NAME_KEY, "os user name"); localConfig.uncache(UserConfig.KEY); authorName = localConfig.get(UserConfig.KEY).getAuthorName(); assertEquals("os user name", authorName); @@ -140,8 +141,8 @@ public void test007_readUserConfig() { } // the git environment variables are defined - mockSystemReader.values.put(Constants.GIT_AUTHOR_NAME_KEY, "git author name"); - mockSystemReader.values.put(Constants.GIT_AUTHOR_EMAIL_KEY, "author@email"); + mockSystemReader.setProperty(Constants.GIT_AUTHOR_NAME_KEY, "git author name"); + mockSystemReader.setProperty(Constants.GIT_AUTHOR_EMAIL_KEY, "author@email"); localConfig.uncache(UserConfig.KEY); authorName = localConfig.get(UserConfig.KEY).getAuthorName(); authorEmail = localConfig.get(UserConfig.KEY).getAuthorEmail(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java index ac8881b1f..ecbb7e073 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java @@ -1,6 +1,9 @@ /* + * Copyright (C) 2009, Google Inc. + * Copyright (C) 2008-2009, Jonas Fonseca * Copyright (C) 2007-2009, Robin Rosenberg - * Copyright (C) 2007, Shawn O. Pearce + * Copyright (C) 2006-2007, Shawn O. Pearce + * Copyright (C) 2009, Yann Simon * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -49,117 +52,18 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; -import java.io.OutputStreamWriter; import java.io.Reader; -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; +import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.util.JGitTestUtil; -import org.eclipse.jgit.util.SystemReader; /** * Base class for most JGit unit tests. * * Sets up a predefined test repository and has support for creating additional * repositories and destroying them when the tests are finished. - * - * A system property jgit.junit.usemmap defines whether memory mapping - * is used. Memory mapping has an effect on the file system, in that memory - * mapped files in java cannot be deleted as long as they mapped arrays have not - * been reclaimed by the garbage collector. The programmer cannot control this - * with precision, though hinting using {@link java.lang.System#gc} - * often helps. */ -public abstract class RepositoryTestCase extends TestCase { - - protected final File trashParent = new File("trash"); - - protected File trash; - - protected File trash_git; - - protected static final PersonIdent jauthor; - - protected static final PersonIdent jcommitter; - - static { - jauthor = new PersonIdent("J. Author", "jauthor@example.com"); - jcommitter = new PersonIdent("J. Committer", "jcommitter@example.com"); - } - - protected boolean packedGitMMAP; - - /** - * Configure JGit before setting up test repositories. - */ - protected void configure() { - final WindowCacheConfig c = new WindowCacheConfig(); - c.setPackedGitLimit(128 * WindowCacheConfig.KB); - c.setPackedGitWindowSize(8 * WindowCacheConfig.KB); - c.setPackedGitMMAP("true".equals(System.getProperty("jgit.junit.usemmap"))); - c.setDeltaBaseCacheLimit(8 * WindowCacheConfig.KB); - WindowCache.reconfigure(c); - } - - /** - * Utility method to delete a directory recursively. It is - * also used internally. If a file or directory cannot be removed - * it throws an AssertionFailure. - * - * @param dir - */ - protected void recursiveDelete(final File dir) { - recursiveDelete(dir, false, getClass().getName() + "." + getName(), true); - } - - protected static boolean recursiveDelete(final File dir, boolean silent, - final String name, boolean failOnError) { - assert !(silent && failOnError); - if (!dir.exists()) - return silent; - final File[] ls = dir.listFiles(); - if (ls != null) { - for (int k = 0; k < ls.length; k++) { - final File e = ls[k]; - if (e.isDirectory()) { - silent = recursiveDelete(e, silent, name, failOnError); - } else { - if (!e.delete()) { - if (!silent) { - reportDeleteFailure(name, failOnError, e); - } - silent = !failOnError; - } - } - } - } - if (!dir.delete()) { - if (!silent) { - reportDeleteFailure(name, failOnError, dir); - } - silent = !failOnError; - } - return silent; - } - - private static void reportDeleteFailure(final String name, - boolean failOnError, final File e) { - String severity; - if (failOnError) - severity = "Error"; - else - severity = "Warning"; - String msg = severity + ": Failed to delete " + e; - if (name != null) - msg += " in " + name; - if (failOnError) - fail(msg); - else - System.out.println(msg); - } - +public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { protected static void copyFile(final File src, final File dst) throws IOException { final FileInputStream fis = new FileInputStream(src); @@ -181,18 +85,9 @@ protected static void copyFile(final File src, final File dst) protected File writeTrashFile(final String name, final String data) throws IOException { - File tf = new File(trash, name); - File tfp = tf.getParentFile(); - if (!tfp.exists() && !tf.getParentFile().mkdirs()) - throw new Error("Could not create directory " + tf.getParentFile()); - final OutputStreamWriter fw = new OutputStreamWriter( - new FileOutputStream(tf), "UTF-8"); - try { - fw.write(data); - } finally { - fw.close(); - } - return tf; + File path = new File(db.getWorkDir(), name); + write(path, data); + return path; } protected static void checkFile(File f, final String checkData) @@ -208,46 +103,17 @@ protected static void checkFile(File f, final String checkData) } } + /** Test repository, initialized for this test case. */ protected Repository db; - private static Thread shutdownhook; - private static List shutDownCleanups = new ArrayList(); - private static int testcount; + /** Working directory of {@link #db}. */ + protected File trash; - private ArrayList repositoriesToClose = new ArrayList(); - - public void setUp() throws Exception { + @Override + protected void setUp() throws Exception { super.setUp(); - configure(); - final String name = getClass().getName() + "." + getName(); - recursiveDelete(trashParent, true, name, false); // Cleanup old failed stuff - trash = new File(trashParent,"trash"+System.currentTimeMillis()+"."+(testcount++)); - trash_git = new File(trash, ".git").getCanonicalFile(); - if (shutdownhook == null) { - shutdownhook = new Thread() { - @Override - public void run() { - // This may look superfluous, but is an extra attempt - // to clean up. First GC to release as many resources - // as possible and then try to clean up one test repo - // at a time (to record problems) and finally to drop - // the directory containing all test repositories. - System.gc(); - for (Runnable r : shutDownCleanups) - r.run(); - recursiveDelete(trashParent, false, null, false); - } - }; - Runtime.getRuntime().addShutdownHook(shutdownhook); - } - - final MockSystemReader mockSystemReader = new MockSystemReader(); - mockSystemReader.userGitConfig = new FileBasedConfig(new File( - trash_git, "usergitconfig")); - SystemReader.setInstance(mockSystemReader); - - db = new Repository(trash_git); - db.create(); + db = createWorkRepository(); + trash = db.getWorkDir(); final String[] packs = { "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f", @@ -259,70 +125,12 @@ public void run() { "pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12" }; final File packDir = new File(db.getObjectsDirectory(), "pack"); - for (int k = 0; k < packs.length; k++) { - copyFile(JGitTestUtil.getTestResourceFile(packs[k] + ".pack"), new File(packDir, - packs[k] + ".pack")); - copyFile(JGitTestUtil.getTestResourceFile(packs[k] + ".idx"), new File(packDir, - packs[k] + ".idx")); + for (String n : packs) { + copyFile(JGitTestUtil.getTestResourceFile(n + ".pack"), new File(packDir, n + ".pack")); + copyFile(JGitTestUtil.getTestResourceFile(n + ".idx"), new File(packDir, n + ".idx")); } - copyFile(JGitTestUtil.getTestResourceFile("packed-refs"), new File(trash_git,"packed-refs")); - } - - protected void tearDown() throws Exception { - RepositoryCache.clear(); - db.close(); - for (Repository r : repositoriesToClose) - r.close(); - - // Since memory mapping is controlled by the GC we need to - // tell it this is a good time to clean up and unlock - // memory mapped files. - if (packedGitMMAP) - System.gc(); - - final String name = getClass().getName() + "." + getName(); - recursiveDelete(trash, false, name, true); - for (Repository r : repositoriesToClose) - recursiveDelete(r.getWorkDir(), false, name, true); - repositoriesToClose.clear(); - - super.tearDown(); - } - - /** - * Helper for creating extra empty repos - * - * @return a new empty git repository for testing purposes - * - * @throws IOException - */ - protected Repository createNewEmptyRepo() throws IOException { - return createNewEmptyRepo(false); - } - - /** - * Helper for creating extra empty repos - * - * @param bare if true, create a bare repository. - * @return a new empty git repository for testing purposes - * - * @throws IOException - */ - protected Repository createNewEmptyRepo(boolean bare) throws IOException { - final File newTestRepo = new File(trashParent, "new" - + System.currentTimeMillis() + "." + (testcount++) - + (bare ? "" : "/") + ".git").getCanonicalFile(); - assertFalse(newTestRepo.exists()); - final Repository newRepo = new Repository(newTestRepo); - newRepo.create(); - final String name = getClass().getName() + "." + getName(); - shutDownCleanups.add(new Runnable() { - public void run() { - recursiveDelete(newTestRepo, false, name, false); - } - }); - repositoriesToClose.add(newRepo); - return newRepo; + copyFile(JGitTestUtil.getTestResourceFile("packed-refs"), new File(db + .getDirectory(), "packed-refs")); } } 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 74e98f1d8..f7346a61f 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 @@ -83,7 +83,7 @@ public void test002_WriteEmptyTree() throws IOException { // open when we create it we won't write the object file out as a loose // object (as it already exists in the pack). // - final Repository newdb = createNewEmptyRepo(); + final Repository newdb = createBareRepository(); final Tree t = new Tree(newdb); t.accept(new WriteTree(trash, newdb), TreeEntry.MODIFIED_ONLY); assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", t.getId() @@ -101,7 +101,8 @@ public void test002_WriteEmptyTree2() throws IOException { t.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", t.getId() .name()); - final File o = new File(new File(new File(trash_git, "objects"), "4b"), + final File o = new File(new File( + new File(db.getDirectory(), "objects"), "4b"), "825dc642cb6eb9a060e54bf8d69288fbee4904"); assertFalse("Exists " + o, o.isFile()); } @@ -115,12 +116,12 @@ public void test003_WriteShouldBeEmptyTree() throws IOException { .name()); File o; - o = new File(new File(new File(trash_git, "objects"), "7b"), + o = new File(new File(new File(db.getDirectory(), "objects"), "7b"), "b943559a305bdd6bdee2cef6e5df2413c3d30a"); assertTrue("Exists " + o, o.isFile()); assertTrue("Read-only " + o, !o.canWrite()); - o = new File(new File(new File(trash_git, "objects"), "e6"), + o = new File(new File(new File(db.getDirectory(), "objects"), "e6"), "9de29bb2d1d6434b8b29ae775ad8c2e48c5391"); assertTrue("Exists " + o, o.isFile()); assertTrue("Read-only " + o, !o.canWrite()); @@ -202,8 +203,8 @@ public void test009_CreateCommitOldFormat() throws IOException, t.getTreeId()); final Commit c = new Commit(db); - c.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); - c.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60)); + c.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); + c.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60)); c.setMessage("A Commit\n"); c.setTree(t); assertEquals(t.getTreeId(), c.getTreeId()); @@ -258,7 +259,7 @@ public void test020_createBlobTag() throws IOException { t.setObjId(emptyId); t.setType("blob"); t.setTag("test020"); - t.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); + t.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); t.setMessage("test020 tagged\n"); t.tag(); assertEquals("6759556b09fbb4fd8ae5e315134481cc25d46954", t.getTagId().name()); @@ -266,7 +267,7 @@ public void test020_createBlobTag() throws IOException { Tag mapTag = db.mapTag("test020"); assertEquals("blob", mapTag.getType()); assertEquals("test020 tagged\n", mapTag.getMessage()); - assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag.getAuthor()); + assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.getAuthor()); assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag.getObjId().name()); } @@ -292,7 +293,7 @@ public void test021_createTreeTag() throws IOException { t.setObjId(almostEmptyTreeId); t.setType("tree"); t.setTag("test021"); - t.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); + t.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); t.setMessage("test021 tagged\n"); t.tag(); assertEquals("b0517bc8dbe2096b419d42424cd7030733f4abe5", t.getTagId().name()); @@ -300,7 +301,7 @@ public void test021_createTreeTag() throws IOException { Tag mapTag = db.mapTag("test021"); assertEquals("tree", mapTag.getType()); assertEquals("test021 tagged\n", mapTag.getMessage()); - assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag.getAuthor()); + assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.getAuthor()); assertEquals("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag.getObjId().name()); } @@ -310,8 +311,8 @@ public void test022_createCommitTag() throws IOException { almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false)); final ObjectId almostEmptyTreeId = new ObjectWriter(db).writeTree(almostEmptyTree); final Commit almostEmptyCommit = new Commit(db); - almostEmptyCommit.setAuthor(new PersonIdent(jauthor, 1154236443000L, -2 * 60)); // not exactly the same - almostEmptyCommit.setCommitter(new PersonIdent(jauthor, 1154236443000L, -2 * 60)); + almostEmptyCommit.setAuthor(new PersonIdent(author, 1154236443000L, -2 * 60)); // not exactly the same + almostEmptyCommit.setCommitter(new PersonIdent(author, 1154236443000L, -2 * 60)); almostEmptyCommit.setMessage("test022\n"); almostEmptyCommit.setTreeId(almostEmptyTreeId); ObjectId almostEmptyCommitId = new ObjectWriter(db).writeCommit(almostEmptyCommit); @@ -319,7 +320,7 @@ public void test022_createCommitTag() throws IOException { t.setObjId(almostEmptyCommitId); t.setType("commit"); t.setTag("test022"); - t.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); + t.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); t.setMessage("test022 tagged\n"); t.tag(); assertEquals("0ce2ebdb36076ef0b38adbe077a07d43b43e3807", t.getTagId().name()); @@ -327,7 +328,7 @@ public void test022_createCommitTag() throws IOException { Tag mapTag = db.mapTag("test022"); assertEquals("commit", mapTag.getType()); assertEquals("test022 tagged\n", mapTag.getMessage()); - assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag.getAuthor()); + assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.getAuthor()); assertEquals("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag.getObjId().name()); } @@ -392,19 +393,19 @@ public void test025_packedRefs() throws IOException { assertNotNull("have tag test020", mapTag20); assertEquals("blob", mapTag20.getType()); assertEquals("test020 tagged\n", mapTag20.getMessage()); - assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag20.getAuthor()); + assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag20.getAuthor()); assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag20.getObjId().name()); Tag mapTag21 = db.mapTag("test021"); assertEquals("tree", mapTag21.getType()); assertEquals("test021 tagged\n", mapTag21.getMessage()); - assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag21.getAuthor()); + assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag21.getAuthor()); assertEquals("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag21.getObjId().name()); Tag mapTag22 = db.mapTag("test022"); assertEquals("commit", mapTag22.getType()); assertEquals("test022 tagged\n", mapTag22.getMessage()); - assertEquals(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag22.getAuthor()); + assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag22.getAuthor()); assertEquals("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag22.getObjId().name()); } @@ -426,8 +427,8 @@ public void test026_CreateCommitMultipleparents() throws IOException { t.getTreeId()); final Commit c1 = new Commit(db); - c1.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); - c1.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60)); + c1.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); + c1.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60)); c1.setMessage("A Commit\n"); c1.setTree(t); assertEquals(t.getTreeId(), c1.getTreeId()); @@ -437,8 +438,8 @@ public void test026_CreateCommitMultipleparents() throws IOException { assertEquals(cmtid1, c1.getCommitId()); final Commit c2 = new Commit(db); - c2.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); - c2.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60)); + c2.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); + c2.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60)); c2.setMessage("A Commit 2\n"); c2.setTree(t); assertEquals(t.getTreeId(), c2.getTreeId()); @@ -458,8 +459,8 @@ public void test026_CreateCommitMultipleparents() throws IOException { assertEquals(c1.getCommitId(), rm2.getParentIds()[0]); final Commit c3 = new Commit(db); - c3.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); - c3.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60)); + c3.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); + c3.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60)); c3.setMessage("A Commit 3\n"); c3.setTree(t); assertEquals(t.getTreeId(), c3.getTreeId()); @@ -480,8 +481,8 @@ public void test026_CreateCommitMultipleparents() throws IOException { assertEquals(c2.getCommitId(), rm3.getParentIds()[1]); final Commit c4 = new Commit(db); - c4.setAuthor(new PersonIdent(jauthor, 1154236443000L, -4 * 60)); - c4.setCommitter(new PersonIdent(jcommitter, 1154236443000L, -4 * 60)); + c4.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); + c4.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60)); c4.setMessage("A Commit 4\n"); c4.setTree(t); assertEquals(t.getTreeId(), c3.getTreeId()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java index 50fbce41a..312fc00b1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java @@ -147,8 +147,8 @@ protected RevCommit commit(final int secDelta, final RevTree tree, final Commit c = new Commit(db); c.setTreeId(tree); c.setParentIds(parents); - c.setAuthor(new PersonIdent(jauthor, new Date(nowTick))); - c.setCommitter(new PersonIdent(jcommitter, new Date(nowTick))); + c.setAuthor(new PersonIdent(author, new Date(nowTick))); + c.setCommitter(new PersonIdent(committer, new Date(nowTick))); c.setMessage(""); return rw.lookupCommit(ow.writeCommit(c)); } @@ -159,7 +159,7 @@ protected RevTag tag(final String name, final RevObject dst) t.setType(Constants.typeString(dst.getType())); t.setObjId(dst.toObjectId()); t.setTag(name); - t.setTagger(new PersonIdent(jcommitter, new Date(nowTick))); + t.setTagger(new PersonIdent(committer, new Date(nowTick))); t.setMessage(""); return (RevTag) rw.lookupAny(ow.writeTag(t), Constants.OBJ_TAG); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java index 6a6b63cab..39ea2f2e4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, Google Inc. + * Copyright (C) 2008-2009, Google Inc. * Copyright (C) 2008, Mike Ralphson * Copyright (C) 2008, Robin Rosenberg * and other copyright owners as documented in the project's IP log. @@ -74,7 +74,7 @@ public void testWrite0() throws Exception { // Then we clone a new repo from that bundle and do a simple test. This // makes sure // we could read the bundle we created. - Repository newRepo = createNewEmptyRepo(); + Repository newRepo = createBareRepository(); FetchResult fetchResult = fetchFromBundle(newRepo, bundle); Ref advertisedRef = fetchResult .getAdvertisedRef("refs/heads/firstcommit"); @@ -101,7 +101,7 @@ public void testWrite1() throws Exception { // Then we clone a new repo from that bundle and do a simple test. This // makes sure // we could read the bundle we created. - Repository newRepo = createNewEmptyRepo(); + Repository newRepo = createBareRepository(); FetchResult fetchResult = fetchFromBundle(newRepo, bundle); Ref advertisedRef = fetchResult.getAdvertisedRef("refs/heads/aa"); @@ -123,7 +123,7 @@ public void testWrite1() throws Exception { try { // Check that we actually needed the first bundle - Repository newRepo2 = createNewEmptyRepo(); + Repository newRepo2 = createBareRepository(); fetchResult = fetchFromBundle(newRepo2, bundle); fail("We should not be able to fetch from bundle with prerequisites that are not fulfilled"); } catch (MissingBundlePrerequisiteException e) {