Adding update-server-info functionality
PATCH 1/1 Adding update-server-info functionality
This patch series implements update-server-info functionality in JGit and integrates it with ReceivePack so that repositories hosted by git-http can also be hosted by JGit.
PATCH 1/19 adding tests for ObjectDirectory
From: mike.gaffney <[email protected]>
--- .../org/spearce/jgit/lib/ObjectDirectoryTest.java | 80 ++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 deletions(-) create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java new file +80 -0
@@ -0,0 +1,80 @@ +package org.spearce.jgit.lib; + +import java.io.File; +import java.util.UUID; + +import junit.framework.TestCase; + +public class ObjectDirectoryTest extends TestCase { + + private File testDir; + + @Override + protected void setUp() throws Exception { + testDir = new File(new File(System.getProperty("java.io.tmpdir")), UUID.randomUUID().toString()); + } + + @Override + protected void tearDown() throws Exception { + if (testDir.exists()){ + deleteDir(testDir); + } + } + + public void testCanGetDirectory() throws Exception { + ObjectDirectory od = new ObjectDirectory(testDir); + assertEquals(testDir, od.getDirectory()); + } + + public void testExistsWithExistingDirectory() throws Exception { + createTestDir(); + ObjectDirectory od = new ObjectDirectory(testDir); + assertTrue(od.exists()); + } + + public void testExistsWithNonExistantDirectory() throws Exception { + assertFalse(new ObjectDirectory(new File("/some/nonexistant/file")).exists()); + } + + public void testCreateMakesCorrectDirectories() throws Exception { + assertFalse(testDir.exists()); + new ObjectDirectory(testDir).create(); + assertTrue(testDir.exists()); + + File infoDir = new File(testDir, "info"); + assertTrue(infoDir.exists()); + assertTrue(infoDir.isDirectory()); + + File packDir = new File(testDir, "pack"); + assertTrue(packDir.exists()); + assertTrue(packDir.isDirectory()); + } + + public void testGettingObjectFile() throws Exception { + ObjectDirectory od = new ObjectDirectory(testDir); + assertEquals(new File(testDir, "02/829ae153935095e4223f30cfc98c835de71bee"), + od.fileFor(ObjectId.fromString("02829ae153935095e4223f30cfc98c835de71bee"))); + assertEquals(new File(testDir, "b0/52a1272310d8df34de72f60204dee7e28a43d0"), + od.fileFor(ObjectId.fromString("b052a1272310d8df34de72f60204dee7e28a43d0"))); + } + + public boolean deleteDir(File dir) { + if (dir.isDirectory()) { + String[] children = dir.list(); + for (int i=0; i<children.length; i++) { + boolean success = deleteDir(new File(dir, children[i])); + if (!success) { + return false; + } + } + } + + // The directory is now empty so delete it + return dir.delete(); + } + + private void createTestDir(){ + testDir.mkdir(); + } + +}
Signature · 1 line
1.6.4.2
PATCH 2/19 Create abstract method on ObjectDatabase for accessing the list of local pack files.
From: mike.gaffney <[email protected]>
Implemented the method for AlternateRepository database as a passthrough
Implemented the method for ObjectDirectory as a toList of the current cached private PackList.
Hopefully this will allow easier reference to the list of packs for others like the server side of fetch.
--- .../jgit/lib/AlternateRepositoryDatabase.java | 6 ++++++ .../src/org/spearce/jgit/lib/ObjectDatabase.java | 11 ++++++++++- .../src/org/spearce/jgit/lib/ObjectDirectory.java | 5 +++++ 3 files changed, 21 insertions(+), 1 deletions(-)
org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java +6 -0
@@ -39,6 +39,7 @@ import java.io.IOException; import java.util.Collection; +import java.util.List; /** * An ObjectDatabase of another {@link Repository}.
@@ -124,4 +125,9 @@ void openObjectInAllPacks1(final Collection<PackedObjectLoader> out, protected void closeAlternates(final ObjectDatabase[] alt) { // Do nothing; these belong to odb to close, not us. } + + @Override + public List<PackFile> listLocalPacks() { + return odb.listLocalPacks(); + } }
org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java +10 -1
@@ -39,6 +39,7 @@ import java.io.IOException; import java.util.Collection; +import java.util.List; import java.util.concurrent.atomic.AtomicReference; /**
@@ -64,7 +65,15 @@ protected ObjectDatabase() { alternates = new AtomicReference<ObjectDatabase[]>(); } - + + /** + * The list of Packs THIS repo contains + * + * @return List<PackFile> of package names contained in this repo. + * Should be an empty list if there are none. + */ + public abstract List<PackFile> listLocalPacks(); + /** * Does this database exist yet? *
org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java +5 -0
@@ -508,4 +508,9 @@ boolean tryAgain(final long currLastModified) { return true; } } + + @Override + public List<PackFile> listLocalPacks() { + return new ArrayList<PackFile>(Arrays.asList(packList.get().packs)); + } }
Signature · 1 line
1.6.4.2
PATCH 3/19 Add abstract method for updating the object db's info cache Implemented passthrough on Alternate for the update of infocache
From: mike.gaffney <[email protected]>
--- .../jgit/lib/AlternateRepositoryDatabase.java | 5 +++++ .../src/org/spearce/jgit/lib/ObjectDatabase.java | 7 +++++++ 2 files changed, 12 insertions(+), 0 deletions(-)
org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java +5 -0
@@ -130,4 +130,9 @@ protected void closeAlternates(final ObjectDatabase[] alt) { public List<PackFile> listLocalPacks() { return odb.listLocalPacks(); } + + @Override + public void updateInfoCache() { + odb.updateInfoCache(); + } }
org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java +7 -0
@@ -75,6 +75,13 @@ protected ObjectDatabase() { public abstract List<PackFile> listLocalPacks(); /** + * Creates the caches that are typically done by + * update-server-info, namely objects/info/packs and + * info/refs + */ + public abstract void updateInfoCache(); + + /** * Does this database exist yet? * * @return true if this database is already created; false if the caller
Signature · 1 line
1.6.4.2
PATCH 4/19 added utility that generates the contents of the objects/info/packs file as a string from a list of PackFiles
From: mike.gaffney <[email protected]>
--- .../jgit/lib/PacksFileContentsCreatorTest.java | 37 ++++++++++++++++++++ .../spearce/jgit/lib/PacksFileContentsCreator.java | 21 +++++++++++ 2 files changed, 58 insertions(+), 0 deletions(-) create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java
org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java new file +37 -0
@@ -0,0 +1,37 @@ +package org.spearce.jgit.lib; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.spearce.jgit.util.JGitTestUtil; + +import junit.framework.TestCase; + +public class PacksFileContentsCreatorTest extends TestCase { + private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f"; + private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack"); + private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx"); + + public void testGettingPacksContentsSinglePack() throws Exception { + List<PackFile> packs = new ArrayList<PackFile>(); + packs.add(new PackFile(TEST_IDX, TEST_PACK)); + + assertEquals("P " + TEST_PACK.getName() + '\r', new PacksFileContentsCreator(packs).toString()); + } + + public void testGettingPacksContentsMultiplePacks() throws Exception { + List<PackFile> packs = new ArrayList<PackFile>(); + packs.add(new PackFile(TEST_IDX, TEST_PACK)); + packs.add(new PackFile(TEST_IDX, TEST_PACK)); + packs.add(new PackFile(TEST_IDX, TEST_PACK)); + + StringBuilder expected = new StringBuilder(); + expected.append("P ").append(TEST_PACK.getName()).append("\r"); + expected.append("P ").append(TEST_PACK.getName()).append("\r"); + expected.append("P ").append(TEST_PACK.getName()).append("\r"); + + assertEquals(expected.toString(), new PacksFileContentsCreator(packs).toString()); + } + +}
org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java new file +21 -0
@@ -0,0 +1,21 @@ +package org.spearce.jgit.lib; + +import java.util.List; + +public class PacksFileContentsCreator { + + private List<PackFile> packs; + + public PacksFileContentsCreator(List<PackFile> packs) { + this.packs = packs; + } + + public String toString(){ + StringBuilder builder = new StringBuilder(); + for (PackFile packFile : packs) { + builder.append("P ").append(packFile.getPackFile().getName()).append('\r'); + } + return builder.toString(); + } + +}
Signature · 1 line
1.6.4.2
PATCH 5/19 Made tests for listLocalPacks function on ObjectDirectory and made them pass
From: mike.gaffney <[email protected]>
--- .../org/spearce/jgit/lib/ObjectDirectoryTest.java | 24 ++++++++++++++++++++ .../jgit/lib/UpdateDirectoryInfoCacheTest.java | 11 +++++++++ .../tst/org/spearce/jgit/util/JGitTestUtil.java | 21 ++++++++++++++++- .../src/org/spearce/jgit/lib/ObjectDirectory.java | 6 +++++ .../spearce/jgit/lib/UpdateDirectoryInfoCache.java | 22 ++++++++++++++++++ 5 files changed, 83 insertions(+), 1 deletions(-) create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java +24 -0
@@ -1,11 +1,17 @@ package org.spearce.jgit.lib; import java.io.File; +import java.util.List; import java.util.UUID; +import org.spearce.jgit.util.JGitTestUtil; + import junit.framework.TestCase; public class ObjectDirectoryTest extends TestCase { + private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f"; + private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack"); + private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx"); private File testDir;
@@ -58,6 +64,24 @@ public void testGettingObjectFile() throws Exception { od.fileFor(ObjectId.fromString("b052a1272310d8df34de72f60204dee7e28a43d0"))); } + public void testListLocalPacksNotCreated() throws Exception { + assertEquals(0, new ObjectDirectory(testDir).listLocalPacks().size()); + } + + public void testListLocalPacksWhenThereIsAPack() throws Exception { + createTestDir(); + File packsDir = new File(testDir, "pack"); + packsDir.mkdirs(); + + JGitTestUtil.copyFile(TEST_PACK, new File(packsDir, TEST_PACK.getName())); + JGitTestUtil.copyFile(TEST_IDX, new File(packsDir, TEST_IDX.getName())); + + ObjectDirectory od = new ObjectDirectory(testDir); + List<PackFile> localPacks = od.listLocalPacks(); + assertEquals(1, localPacks.size()); + assertEquals(TEST_PACK.getName(), localPacks.get(0).getPackFile().getName()); + } + public boolean deleteDir(File dir) { if (dir.isDirectory()) { String[] children = dir.list();
org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java new file +11 -0
@@ -0,0 +1,11 @@ +package org.spearce.jgit.lib; + +import junit.framework.TestCase; + +public class UpdateDirectoryInfoCacheTest extends TestCase { + + public void testBase() throws Exception { + fail("nyi"); + } + +}
org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java +20 -1
@@ -38,6 +38,12 @@ package org.spearce.jgit.util; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.net.URISyntaxException; import java.net.URL;
@@ -60,11 +66,24 @@ public static File getTestResourceFile(final String fileName) { } try { return new File(url.toURI()); - } catch(URISyntaxException e) { + } catch (URISyntaxException e) { return new File(url.getPath()); } } + public static void copyFile(final File fromFile, final File toFile) throws IOException { + InputStream in = new FileInputStream(fromFile); + OutputStream out = new FileOutputStream(toFile); + + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + in.close(); + out.close(); + } + private static ClassLoader cl() { return JGitTestUtil.class.getClassLoader(); }
org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java +6 -0
@@ -511,6 +511,12 @@ boolean tryAgain(final long currLastModified) { @Override public List<PackFile> listLocalPacks() { + tryAgain1(); return new ArrayList<PackFile>(Arrays.asList(packList.get().packs)); } + + @Override + public void updateInfoCache() { + new UpdateDirectoryInfoCache(this.listLocalPacks(), this.infoDirectory).execute(); + } }
org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java new file +22 -0
@@ -0,0 +1,22 @@ +package org.spearce.jgit.lib; + +import java.io.File; +import java.util.List; + +public class UpdateDirectoryInfoCache { + + private List<PackFile> packsList; + private File infoDirectory; + + public UpdateDirectoryInfoCache(List<PackFile> packsList, + File infoDirectory) { + this.packsList = packsList; + this.infoDirectory = infoDirectory; + } + + public void execute() { +// File objectFile = objectDatabase. +// String packsContents = new PacksFileContentsCreator(this.objectDatabase.listLocalPacks()).toString(); + } + +}
Signature · 1 line
1.6.4.2
PATCH 6/19 added utility for reading the contents of a file as a string
From: mike.gaffney <[email protected]>
--- .../tst/org/spearce/jgit/util/JGitTestUtil.java | 20 +++++++++++++++++++- 1 files changed, 19 insertions(+), 1 deletions(-)
org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java +19 -1
@@ -37,10 +37,12 @@ package org.spearce.jgit.util; +import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream;
@@ -71,7 +73,8 @@ public static File getTestResourceFile(final String fileName) { } } - public static void copyFile(final File fromFile, final File toFile) throws IOException { + public static void copyFile(final File fromFile, final File toFile) + throws IOException { InputStream in = new FileInputStream(fromFile); OutputStream out = new FileOutputStream(toFile);
@@ -84,6 +87,21 @@ public static void copyFile(final File fromFile, final File toFile) throws IOExc out.close(); } + public static String readFileAsString(final File file) + throws java.io.IOException { + StringBuilder fileData = new StringBuilder(1000); + BufferedReader reader = new BufferedReader(new FileReader(file)); + char[] buf = new char[1024]; + int numRead = 0; + while ((numRead = reader.read(buf)) != -1) { + String readData = String.valueOf(buf, 0, numRead); + fileData.append(readData); + buf = new char[1024]; + } + reader.close(); + return fileData.toString(); + } + private static ClassLoader cl() { return JGitTestUtil.class.getClassLoader(); }
Signature · 1 line
1.6.4.2
PATCH 7/19 implemented the packs file update functionality
From: mike.gaffney <[email protected]>
--- .../jgit/lib/UpdateDirectoryInfoCacheTest.java | 23 ++++++++++++++++++- .../spearce/jgit/lib/UpdateDirectoryInfoCache.java | 17 +++++++++----- 2 files changed, 32 insertions(+), 8 deletions(-)
org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java +21 -2
@@ -1,11 +1,30 @@ package org.spearce.jgit.lib; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + import junit.framework.TestCase; +import org.spearce.jgit.util.JGitTestUtil; + public class UpdateDirectoryInfoCacheTest extends TestCase { + private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f"; + private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack"); + private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx"); - public void testBase() throws Exception { - fail("nyi"); + public void testCreatesTheFileAndPutsTheContentsIn() throws Exception { + List<PackFile> packs = new ArrayList<PackFile>(); + packs.add(new PackFile(TEST_IDX, TEST_PACK)); + + File packsFile = File.createTempFile(UpdateDirectoryInfoCacheTest.class.getSimpleName(), "tstdata"); + packsFile.deleteOnExit(); + + String expectedContents = new PacksFileContentsCreator(packs).toString(); + + new UpdateDirectoryInfoCache(packs, packsFile).execute(); + + assertEquals(expectedContents, JGitTestUtil.readFileAsString(packsFile)); } }
org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java +11 -6
@@ -1,22 +1,27 @@ package org.spearce.jgit.lib; +import java.io.BufferedWriter; import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.List; public class UpdateDirectoryInfoCache { private List<PackFile> packsList; - private File infoDirectory; + private File infoPacksFile; public UpdateDirectoryInfoCache(List<PackFile> packsList, - File infoDirectory) { + File infoPacksFile) { this.packsList = packsList; - this.infoDirectory = infoDirectory; + this.infoPacksFile = infoPacksFile; } - public void execute() { -// File objectFile = objectDatabase. -// String packsContents = new PacksFileContentsCreator(this.objectDatabase.listLocalPacks()).toString(); + public void execute() throws IOException { + String packsContents = new PacksFileContentsCreator(packsList).toString(); + FileOutputStream fos = new FileOutputStream(infoPacksFile); + fos.write(packsContents.getBytes()); + fos.close(); } }
Signature · 1 line
1.6.4.2
PATCH 8/19 changed signature to allow a IOException
From: mike.gaffney <[email protected]>
--- .../jgit/lib/AlternateRepositoryDatabase.java | 2 +- .../src/org/spearce/jgit/lib/ObjectDatabase.java | 3 ++- .../src/org/spearce/jgit/lib/ObjectDirectory.java | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-)
org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java +1 -1
@@ -132,7 +132,7 @@ protected void closeAlternates(final ObjectDatabase[] alt) { } @Override - public void updateInfoCache() { + public void updateInfoCache() throws IOException { odb.updateInfoCache(); } }
org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java +2 -1
@@ -78,8 +78,9 @@ protected ObjectDatabase() { * Creates the caches that are typically done by * update-server-info, namely objects/info/packs and * info/refs + * @throws IOException */ - public abstract void updateInfoCache(); + public abstract void updateInfoCache() throws IOException; /** * Does this database exist yet?
org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java +2 -2
@@ -516,7 +516,7 @@ boolean tryAgain(final long currLastModified) { } @Override - public void updateInfoCache() { - new UpdateDirectoryInfoCache(this.listLocalPacks(), this.infoDirectory).execute(); + public void updateInfoCache() throws IOException { + new UpdateDirectoryInfoCache(this.listLocalPacks(), new File(this.infoDirectory, "packs")).execute(); } }
Signature · 1 line
1.6.4.2
PATCH 9/19 Didn't like the old name, this is more specific to it just updating the packs info cache
From: mike.gaffney <[email protected]>
--- .../UpdateDirectoryBasedPacksInfoCacheTest.java | 30 ++++++++++++++++++++ .../jgit/lib/UpdateDirectoryInfoCacheTest.java | 30 -------------------- .../src/org/spearce/jgit/lib/ObjectDirectory.java | 2 +- .../lib/UpdateDirectoryBasedPacksInfoCache.java | 27 ++++++++++++++++++ .../spearce/jgit/lib/UpdateDirectoryInfoCache.java | 27 ------------------ 5 files changed, 58 insertions(+), 58 deletions(-) create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java delete mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java delete mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java
org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java new file +30 -0
@@ -0,0 +1,30 @@ +package org.spearce.jgit.lib; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import org.spearce.jgit.util.JGitTestUtil; + +public class UpdateDirectoryBasedPacksInfoCacheTest extends TestCase { + private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f"; + private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack"); + private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx"); + + public void testCreatesTheFileAndPutsTheContentsIn() throws Exception { + List<PackFile> packs = new ArrayList<PackFile>(); + packs.add(new PackFile(TEST_IDX, TEST_PACK)); + + File packsFile = File.createTempFile(UpdateDirectoryBasedPacksInfoCacheTest.class.getSimpleName(), "tstdata"); + packsFile.deleteOnExit(); + + String expectedContents = new PacksFileContentsCreator(packs).toString(); + + new UpdateDirectoryBasedPacksInfoCache(packs, packsFile).execute(); + + assertEquals(expectedContents, JGitTestUtil.readFileAsString(packsFile)); + } + +}
org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java deleted +0 -30
@@ -1,30 +0,0 @@ -package org.spearce.jgit.lib; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.spearce.jgit.util.JGitTestUtil; - -public class UpdateDirectoryInfoCacheTest extends TestCase { - private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f"; - private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack"); - private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx"); - - public void testCreatesTheFileAndPutsTheContentsIn() throws Exception { - List<PackFile> packs = new ArrayList<PackFile>(); - packs.add(new PackFile(TEST_IDX, TEST_PACK)); - - File packsFile = File.createTempFile(UpdateDirectoryInfoCacheTest.class.getSimpleName(), "tstdata"); - packsFile.deleteOnExit(); - - String expectedContents = new PacksFileContentsCreator(packs).toString(); - - new UpdateDirectoryInfoCache(packs, packsFile).execute(); - - assertEquals(expectedContents, JGitTestUtil.readFileAsString(packsFile)); - } - -}
org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java +1 -1
@@ -517,6 +517,6 @@ boolean tryAgain(final long currLastModified) { @Override public void updateInfoCache() throws IOException { - new UpdateDirectoryInfoCache(this.listLocalPacks(), new File(this.infoDirectory, "packs")).execute(); + new UpdateDirectoryBasedPacksInfoCache(this.listLocalPacks(), new File(this.infoDirectory, "packs")).execute(); } }
org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java new file +27 -0
@@ -0,0 +1,27 @@ +package org.spearce.jgit.lib; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.List; + +public class UpdateDirectoryBasedPacksInfoCache { + + private List<PackFile> packsList; + private File infoPacksFile; + + public UpdateDirectoryBasedPacksInfoCache(List<PackFile> packsList, + File infoPacksFile) { + this.packsList = packsList; + this.infoPacksFile = infoPacksFile; + } + + public void execute() throws IOException { + String packsContents = new PacksFileContentsCreator(packsList).toString(); + FileOutputStream fos = new FileOutputStream(infoPacksFile); + fos.write(packsContents.getBytes()); + fos.close(); + } + +}
org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java deleted +0 -27
@@ -1,27 +0,0 @@ -package org.spearce.jgit.lib; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.List; - -public class UpdateDirectoryInfoCache { - - private List<PackFile> packsList; - private File infoPacksFile; - - public UpdateDirectoryInfoCache(List<PackFile> packsList, - File infoPacksFile) { - this.packsList = packsList; - this.infoPacksFile = infoPacksFile; - } - - public void execute() throws IOException { - String packsContents = new PacksFileContentsCreator(packsList).toString(); - FileOutputStream fos = new FileOutputStream(infoPacksFile); - fos.write(packsContents.getBytes()); - fos.close(); - } - -}
Signature · 1 line
1.6.4.2
PATCH 10/19 moved test up to a higher level to test actual functionality
From: mike.gaffney <[email protected]>
--- .../org/spearce/jgit/lib/ObjectDirectoryTest.java | 32 ++++++++++++++++---- .../UpdateDirectoryBasedPacksInfoCacheTest.java | 30 ------------------ 2 files changed, 26 insertions(+), 36 deletions(-) delete mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java +26 -6
@@ -1,6 +1,8 @@ package org.spearce.jgit.lib; import java.io.File; +import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.UUID;
@@ -69,12 +71,7 @@ public void testListLocalPacksNotCreated() throws Exception { } public void testListLocalPacksWhenThereIsAPack() throws Exception { - createTestDir(); - File packsDir = new File(testDir, "pack"); - packsDir.mkdirs(); - - JGitTestUtil.copyFile(TEST_PACK, new File(packsDir, TEST_PACK.getName())); - JGitTestUtil.copyFile(TEST_IDX, new File(packsDir, TEST_IDX.getName())); + createSamplePacksDir(); ObjectDirectory od = new ObjectDirectory(testDir); List<PackFile> localPacks = od.listLocalPacks();
@@ -82,6 +79,20 @@ public void testListLocalPacksWhenThereIsAPack() throws Exception { assertEquals(TEST_PACK.getName(), localPacks.get(0).getPackFile().getName()); } + public void testUpdateInfoCacheCreatesPacksFile() throws Exception { + createSamplePacksDir(); + + ObjectDirectory od = new ObjectDirectory(testDir); + od.create(); + od.updateInfoCache(); + + String expectedContents = new PacksFileContentsCreator(od.listLocalPacks()).toString(); + File packsFile = new File(od.getDirectory(), "info/packs"); + + assertTrue(packsFile.exists()); + assertEquals(expectedContents, JGitTestUtil.readFileAsString(packsFile)); + } + public boolean deleteDir(File dir) { if (dir.isDirectory()) { String[] children = dir.list();
@@ -100,5 +111,14 @@ public boolean deleteDir(File dir) { private void createTestDir(){ testDir.mkdir(); } + + private void createSamplePacksDir() throws IOException { + createTestDir(); + File packsDir = new File(testDir, "pack"); + packsDir.mkdirs(); + + JGitTestUtil.copyFile(TEST_PACK, new File(packsDir, TEST_PACK.getName())); + JGitTestUtil.copyFile(TEST_IDX, new File(packsDir, TEST_IDX.getName())); + } }
org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java deleted +0 -30
@@ -1,30 +0,0 @@ -package org.spearce.jgit.lib; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.spearce.jgit.util.JGitTestUtil; - -public class UpdateDirectoryBasedPacksInfoCacheTest extends TestCase { - private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f"; - private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack"); - private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx"); - - public void testCreatesTheFileAndPutsTheContentsIn() throws Exception { - List<PackFile> packs = new ArrayList<PackFile>(); - packs.add(new PackFile(TEST_IDX, TEST_PACK)); - - File packsFile = File.createTempFile(UpdateDirectoryBasedPacksInfoCacheTest.class.getSimpleName(), "tstdata"); - packsFile.deleteOnExit(); - - String expectedContents = new PacksFileContentsCreator(packs).toString(); - - new UpdateDirectoryBasedPacksInfoCache(packs, packsFile).execute(); - - assertEquals(expectedContents, JGitTestUtil.readFileAsString(packsFile)); - } - -}
Signature · 1 line
1.6.4.2
PATCH 11/19 removed unused import
From: mike.gaffney <[email protected]>
--- .../lib/UpdateDirectoryBasedPacksInfoCache.java | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java +0 -1
@@ -1,6 +1,5 @@ package org.spearce.jgit.lib; -import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException;
Signature · 1 line
1.6.4.2
PATCH 12/19 moved info/packs into a constant
From: mike.gaffney <[email protected]>
--- .../org/spearce/jgit/lib/ObjectDirectoryTest.java | 5 ++--- .../src/org/spearce/jgit/lib/Constants.java | 3 +++ .../src/org/spearce/jgit/lib/ObjectDirectory.java | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-)
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java +2 -3
@@ -79,7 +79,7 @@ public void testListLocalPacksWhenThereIsAPack() throws Exception { assertEquals(TEST_PACK.getName(), localPacks.get(0).getPackFile().getName()); } - public void testUpdateInfoCacheCreatesPacksFile() throws Exception { + public void testUpdateInfoCacheCreatesPacksAndRefsFile() throws Exception { createSamplePacksDir(); ObjectDirectory od = new ObjectDirectory(testDir);
@@ -87,7 +87,7 @@ public void testUpdateInfoCacheCreatesPacksFile() throws Exception { od.updateInfoCache(); String expectedContents = new PacksFileContentsCreator(od.listLocalPacks()).toString(); - File packsFile = new File(od.getDirectory(), "info/packs"); + File packsFile = new File(od.getDirectory(), Constants.CACHED_PACKS_FILE); assertTrue(packsFile.exists()); assertEquals(expectedContents, JGitTestUtil.readFileAsString(packsFile));
@@ -103,7 +103,6 @@ public boolean deleteDir(File dir) { } } } - // The directory is now empty so delete it return dir.delete(); }
org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java +3 -0
@@ -224,6 +224,9 @@ /** Info refs folder */ public static final String INFO_REFS = "info/refs"; + + /** cached packs file */ + public static final String CACHED_PACKS_FILE = "info/packs"; /** Packed refs file */ public static final String PACKED_REFS = "packed-refs";
org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java +1 -1
@@ -517,6 +517,6 @@ boolean tryAgain(final long currLastModified) { @Override public void updateInfoCache() throws IOException { - new UpdateDirectoryBasedPacksInfoCache(this.listLocalPacks(), new File(this.infoDirectory, "packs")).execute(); + new UpdateDirectoryBasedPacksInfoCache(this.listLocalPacks(), new File(this.getDirectory(), Constants.CACHED_PACKS_FILE)).execute(); } }
Signature · 1 line
1.6.4.2
PATCH 13/19 made the call update the object database's info cache
From: mike.gaffney <[email protected]>
--- .../org/spearce/jgit/transport/ReceivePack.java | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java +10 -0
@@ -521,6 +521,16 @@ void sendString(final String s) throws IOException { } postReceive.onPostReceive(this, filterCommands(Result.OK)); + updateObjectInfoCache(); + } + } + + private void updateObjectInfoCache() { + try{ + getRepository().getObjectDatabase().updateInfoCache(); + } + catch (IOException e){ + sendMessage("error updating server info: " + e.getMessage()); } }
Signature · 1 line
1.6.4.2
PATCH 14/19 pulled out some helper functions that will be useful for other tests
From: mike.gaffney <[email protected]>
--- .../org/spearce/jgit/lib/ObjectDirectoryTest.java | 21 ++----------------- .../tst/org/spearce/jgit/util/JGitTestUtil.java | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 19 deletions(-)
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java +3 -18
@@ -4,7 +4,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.UUID; import org.spearce.jgit.util.JGitTestUtil;
@@ -19,13 +18,13 @@ @Override protected void setUp() throws Exception { - testDir = new File(new File(System.getProperty("java.io.tmpdir")), UUID.randomUUID().toString()); + testDir = JGitTestUtil.generateTempDirectoryFileObject(); } - + @Override protected void tearDown() throws Exception { if (testDir.exists()){ - deleteDir(testDir); + JGitTestUtil.deleteDir(testDir); } }
@@ -93,20 +92,6 @@ public void testUpdateInfoCacheCreatesPacksAndRefsFile() throws Exception { assertEquals(expectedContents, JGitTestUtil.readFileAsString(packsFile)); } - public boolean deleteDir(File dir) { - if (dir.isDirectory()) { - String[] children = dir.list(); - for (int i=0; i<children.length; i++) { - boolean success = deleteDir(new File(dir, children[i])); - if (!success) { - return false; - } - } - } - // The directory is now empty so delete it - return dir.delete(); - } - private void createTestDir(){ testDir.mkdir(); }
org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java +19 -1
@@ -40,7 +40,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException;
@@ -48,6 +47,7 @@ import java.io.OutputStream; import java.net.URISyntaxException; import java.net.URL; +import java.util.UUID; public abstract class JGitTestUtil { public static final String CLASSPATH_TO_RESOURCES = "org/spearce/jgit/test/resources/";
@@ -105,4 +105,22 @@ public static String readFileAsString(final File file) private static ClassLoader cl() { return JGitTestUtil.class.getClassLoader(); } + + public static boolean deleteDir(File dir) { + if (dir.isDirectory()) { + String[] children = dir.list(); + for (int i=0; i<children.length; i++) { + boolean success = deleteDir(new File(dir, children[i])); + if (!success) { + return false; + } + } + } + // The directory is now empty so delete it + return dir.delete(); + } + + public static File generateTempDirectoryFileObject() { + return new File(new File(System.getProperty("java.io.tmpdir")), UUID.randomUUID().toString()); + } }
Signature · 1 line
1.6.4.2
PATCH 15/19 Adding in a InfoDatabase like ObjectDatabase and and implementation based upon a directory.
From: mike.gaffney <[email protected]>
Currently only creates itself.
--- .../jgit/lib/InfoDirectoryDatabaseTest.java | 30 ++++++++++++++++++++ .../src/org/spearce/jgit/lib/InfoDatabase.java | 8 +++++ .../spearce/jgit/lib/InfoDirectoryDatabase.java | 18 ++++++++++++ .../src/org/spearce/jgit/lib/Repository.java | 11 +++++++ .../org/spearce/jgit/transport/ReceivePack.java | 1 + 5 files changed, 68 insertions(+), 0 deletions(-) create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java
org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java new file +30 -0
@@ -0,0 +1,30 @@ +package org.spearce.jgit.lib; + +import java.io.File; + +import org.spearce.jgit.util.JGitTestUtil; + +import junit.framework.TestCase; + +public class InfoDirectoryDatabaseTest extends TestCase { + + private File testDir; + + @Override + protected void setUp() throws Exception { + testDir = JGitTestUtil.generateTempDirectoryFileObject(); + } + + @Override + protected void tearDown() throws Exception { + if (testDir.exists()){ + JGitTestUtil.deleteDir(testDir); + } + } + + public void testCreateCreatesDirectory() throws Exception { + assertFalse(testDir.exists()); + new InfoDirectoryDatabase(testDir).create(); + assertTrue(testDir.exists()); + } +}
org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java new file +8 -0
@@ -0,0 +1,8 @@ +package org.spearce.jgit.lib; + +public abstract class InfoDatabase { + + public void create() { + } + +}
org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java new file +18 -0
@@ -0,0 +1,18 @@ +package org.spearce.jgit.lib; + +import java.io.File; + +public class InfoDirectoryDatabase extends InfoDatabase { + + private File info; + + public InfoDirectoryDatabase(final File directory) { + info = directory; + } + + @Override + public void create() { + info.mkdirs(); + } + +}
org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java +11 -0
@@ -97,6 +97,8 @@ private final RefDatabase refs; private final ObjectDirectory objectDatabase; + + private final InfoDatabase infoDatabase; private GitIndex index;
@@ -116,6 +118,7 @@ public Repository(final File d) throws IOException { gitDir = d.getAbsoluteFile(); refs = new RefDatabase(this); objectDatabase = new ObjectDirectory(FS.resolve(gitDir, "objects")); + infoDatabase = new InfoDirectoryDatabase(FS.resolve(gitDir, "info")); final FileBasedConfig userConfig; userConfig = SystemReader.getInstance().openUserConfig();
@@ -177,6 +180,7 @@ public void create(boolean bare) throws IOException { gitDir.mkdirs(); refs.create(); objectDatabase.create(); + infoDatabase.create(); new File(gitDir, "branches").mkdir(); new File(gitDir, "remotes").mkdir();
@@ -210,6 +214,13 @@ public File getObjectsDirectory() { public ObjectDatabase getObjectDatabase() { return objectDatabase; } + + /** + * @return the info database which stores this repository's info + */ + public InfoDatabase getInfoDatabase() { + return infoDatabase; + } /** * @return the configuration of this repository
org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java +1 -0
@@ -62,6 +62,7 @@ import org.spearce.jgit.lib.PersonIdent; import org.spearce.jgit.lib.Ref; import org.spearce.jgit.lib.RefUpdate; +import org.spearce.jgit.lib.RefWriter; import org.spearce.jgit.lib.Repository; import org.spearce.jgit.lib.Config.SectionParser; import org.spearce.jgit.revwalk.ObjectWalk;
Signature · 1 line
1.6.4.2
PATCH 16/19 added tests for the file based info cache update and made pass
From: mike.gaffney <[email protected]>
--- .../jgit/lib/InfoDirectoryDatabaseTest.java | 30 ++++++++++++++++++++ .../src/org/spearce/jgit/lib/InfoDatabase.java | 15 ++++++++++ .../spearce/jgit/lib/InfoDirectoryDatabase.java | 15 ++++++++++ 3 files changed, 60 insertions(+), 0 deletions(-)
org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java +30 -0
@@ -1,6 +1,10 @@ package org.spearce.jgit.lib; import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; import org.spearce.jgit.util.JGitTestUtil;
@@ -27,4 +31,30 @@ public void testCreateCreatesDirectory() throws Exception { new InfoDirectoryDatabase(testDir).create(); assertTrue(testDir.exists()); } + + public void testUpdateInfoCache() throws Exception { + Collection<Ref> refs = new ArrayList<Ref>(); + refs.add(new Ref(Ref.Storage.LOOSE, "refs/heads/master", ObjectId.fromString("32aae7aef7a412d62192f710f2130302997ec883"))); + refs.add(new Ref(Ref.Storage.LOOSE, "refs/heads/development", ObjectId.fromString("184063c9b594f8968d61a686b2f6052779551613"))); + + File expectedFile = new File(testDir, "refs"); + assertFalse(expectedFile.exists()); + + + final StringWriter expectedString = new StringWriter(); + new RefWriter(refs) { + @Override + protected void writeFile(String file, byte[] content) throws IOException { + expectedString.write(new String(content)); + } + }.writeInfoRefs(); + + InfoDirectoryDatabase out = new InfoDirectoryDatabase(testDir); + out.create(); + out.updateInfoCache(refs); + assertTrue(expectedFile.exists()); + + String actual = JGitTestUtil.readFileAsString(expectedFile); + assertEquals(expectedString.toString(), actual); + } }
org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java +15 -0
@@ -1,8 +1,23 @@ package org.spearce.jgit.lib; +import java.io.IOException; +import java.util.Collection; + public abstract class InfoDatabase { + /** + * Create the info database + */ public void create() { } + /** + * Updates the info cache typically done by update-server-info command. + * This writes THIS repository's refs out to the info/refs file. + * @param collection the collections of refs to update the info cache with + * @throws IOException for any type of failure on the local or remote + * data store + */ + public abstract void updateInfoCache(Collection<Ref> collection) throws IOException; + }
org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java +15 -0
@@ -1,6 +1,9 @@ package org.spearce.jgit.lib; import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Collection; public class InfoDirectoryDatabase extends InfoDatabase {
@@ -15,4 +18,16 @@ public void create() { info.mkdirs(); } + @Override + public void updateInfoCache(Collection<Ref> refs) throws IOException { + new RefWriter(refs) { + @Override + protected void writeFile(String file, byte[] content) throws IOException { + FileOutputStream fos = new FileOutputStream(new File(info, "refs")); + fos.write(content); + fos.close(); + } + }.writeInfoRefs(); + } + }
Signature · 1 line
1.6.4.2
PATCH 17/19 added call to update the info refs file
From: mike.gaffney <[email protected]>
--- .../org/spearce/jgit/transport/ReceivePack.java | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java +10 -0
@@ -523,6 +523,16 @@ void sendString(final String s) throws IOException { postReceive.onPostReceive(this, filterCommands(Result.OK)); updateObjectInfoCache(); + updateInfoRefsCache(); + } + } + + private void updateInfoRefsCache() { + try{ + getRepository().getInfoDatabase().updateInfoCache(getRepository().getAllRefs().values()); + } + catch (IOException e){ + sendMessage("error updating info/refs: " + e.getMessage()); } }
Signature · 1 line
1.6.4.2
PATCH 18/19 Added Copyright Notices
From: mike.gaffney <[email protected]>
--- .../jgit/lib/InfoDirectoryDatabaseTest.java | 36 +++++++++++++++++ .../org/spearce/jgit/lib/ObjectDirectoryTest.java | 41 ++++++++++++++++++- .../jgit/lib/PacksFileContentsCreatorTest.java | 36 +++++++++++++++++ .../src/org/spearce/jgit/lib/InfoDatabase.java | 36 +++++++++++++++++ .../spearce/jgit/lib/InfoDirectoryDatabase.java | 36 +++++++++++++++++ .../spearce/jgit/lib/PacksFileContentsCreator.java | 36 +++++++++++++++++ .../lib/UpdateDirectoryBasedPacksInfoCache.java | 36 +++++++++++++++++ 7 files changed, 254 insertions(+), 3 deletions(-)
org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java +36 -0
@@ -1,3 +1,39 @@ +/* + * Copyright (C) 2009, Mike Gaffney. + * + * 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 Git Development Community 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.spearce.jgit.lib; import java.io.File;
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java +38 -3
52 lines not on this page · raw message
org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java +36 -0
@@ -1,3 +1,39 @@ +/* + * Copyright (C) 2009, Mike Gaffney. + * + * 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 Git Development Community 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.spearce.jgit.lib; import java.io.File;
org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java +36 -0
@@ -1,3 +1,39 @@ +/* + * Copyright (C) 2009, Mike Gaffney. + * + * 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 Git Development Community 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.spearce.jgit.lib; import java.io.IOException;
org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java +36 -0
@@ -1,3 +1,39 @@ +/* + * Copyright (C) 2009, Mike Gaffney. + * + * 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 Git Development Community 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.spearce.jgit.lib; import java.io.File;
org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java +36 -0
@@ -1,3 +1,39 @@ +/* + * Copyright (C) 2009, Mike Gaffney. + * + * 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 Git Development Community 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.spearce.jgit.lib; import java.util.List;
org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java +36 -0
@@ -1,3 +1,39 @@ +/* + * Copyright (C) 2009, Mike Gaffney. + * + * 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 Git Development Community 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.spearce.jgit.lib; import java.io.File;
Signature · 1 line
1.6.4.2
PATCH 19/19 changed \r to \n per compliance with real git
From: mike.gaffney <[email protected]>
--- .../jgit/lib/PacksFileContentsCreatorTest.java | 9 +++++---- .../spearce/jgit/lib/PacksFileContentsCreator.java | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-)
org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java +5 -4
@@ -53,7 +53,7 @@ public void testGettingPacksContentsSinglePack() throws Exception { List<PackFile> packs = new ArrayList<PackFile>(); packs.add(new PackFile(TEST_IDX, TEST_PACK)); - assertEquals("P " + TEST_PACK.getName() + '\r', new PacksFileContentsCreator(packs).toString()); + assertEquals("P " + TEST_PACK.getName() + "\n\n", new PacksFileContentsCreator(packs).toString()); } public void testGettingPacksContentsMultiplePacks() throws Exception {
@@ -63,9 +63,10 @@ public void testGettingPacksContentsMultiplePacks() throws Exception { packs.add(new PackFile(TEST_IDX, TEST_PACK)); StringBuilder expected = new StringBuilder(); - expected.append("P ").append(TEST_PACK.getName()).append("\r"); - expected.append("P ").append(TEST_PACK.getName()).append("\r"); - expected.append("P ").append(TEST_PACK.getName()).append("\r"); + expected.append("P ").append(TEST_PACK.getName()).append('\n'); + expected.append("P ").append(TEST_PACK.getName()).append('\n'); + expected.append("P ").append(TEST_PACK.getName()).append('\n'); + expected.append('\n'); assertEquals(expected.toString(), new PacksFileContentsCreator(packs).toString()); }
org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java +2 -1
@@ -49,8 +49,9 @@ public PacksFileContentsCreator(List<PackFile> packs) { public String toString(){ StringBuilder builder = new StringBuilder(); for (PackFile packFile : packs) { - builder.append("P ").append(packFile.getPackFile().getName()).append('\r'); + builder.append("P ").append(packFile.getPackFile().getName()).append('\n'); } + builder.append('\n'); return builder.toString(); }
Signature · 1 line
1.6.4.2
Re: [PATCH JGit 09/19] Didn't like the old name, this is more specific to it just updating the packs info cache
In reply to [email protected]Ok, I stop reading here. Clean up and resubmit. Could you also set your real in the patches name like the rest of us, i.e. Mike Gaffney instead of mike.gaffney and add the Signed-Off-by and everything else mentioned in the SUBMITTING_PATCHES document at the root of the JGit repo.
-- robin
Re: [PATCH JGit 07/19] implemented the packs file update functionality
In reply to [email protected]söndag 13 september 2009 20:44:23 skrev [email protected]:
Quoted 72 lines
From: mike.gaffney <[email protected]>
--- .../jgit/lib/UpdateDirectoryInfoCacheTest.java | 23 ++++++++++++++++++- .../spearce/jgit/lib/UpdateDirectoryInfoCache.java | 17 +++++++++----- 2 files changed, 32 insertions(+), 8 deletions(-)org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java +21
-2@@ -1,11 +1,30 @@ package org.spearce.jgit.lib; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + import junit.framework.TestCase; +import org.spearce.jgit.util.JGitTestUtil; + public class UpdateDirectoryInfoCacheTest extends TestCase { + private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f"; + private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack"); + private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx"); - public void testBase() throws Exception { - fail("nyi"); + public void testCreatesTheFileAndPutsTheContentsIn() throws Exception { + List<PackFile> packs = new ArrayList<PackFile>(); + packs.add(new PackFile(TEST_IDX, TEST_PACK)); + + File packsFile = File.createTempFile(UpdateDirectoryInfoCacheTest.class.getSimpleName(), "tstdata"); + packsFile.deleteOnExit(); + + String expectedContents = new PacksFileContentsCreator(packs).toString(); + + new UpdateDirectoryInfoCache(packs, packsFile).execute(); + + assertEquals(expectedContents, JGitTestUtil.readFileAsString(packsFile)); } }org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java +6
-4@@ -1,22 +1,27 @@ package org.spearce.jgit.lib; +import java.io.BufferedWriter; import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.List; public class UpdateDirectoryInfoCache { private List<PackFile> packsList; - private File infoDirectory; + private File infoPacksFile; public UpdateDirectoryInfoCache(List<PackFile> packsList, - File infoDirectory) { + File infoPacksFile) { this.packsList = packsList; - this.infoDirectory = infoDirectory; + this.infoPacksFile = infoPacksFile; } - public void execute() {
org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java line 27
Quoted 10 lines
org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java +5
-2-// File objectFile = objectDatabase. -// String packsContents = new PacksFileContentsCreator(this.objectDatabase.listLocalPacks()).toString(); + public void execute() throws IOException { + String packsContents = new PacksFileContentsCreator(packsList).toString(); + FileOutputStream fos = new FileOutputStream(infoPacksFile); + fos.write(packsContents.getBytes()); + fos.close(); } }
These cleanups could have been done by rewriting the patch set before submitting.
-- robin
Re: [PATCH JGit 05/19] Made tests for listLocalPacks function on ObjectDirectory and made them pass
In reply to [email protected]söndag 13 september 2009 20:44:21 skrev [email protected]:
Quoted 105 lines
From: mike.gaffney <[email protected]>
--- .../org/spearce/jgit/lib/ObjectDirectoryTest.java | 24 ++++++++++++++++++++ .../jgit/lib/UpdateDirectoryInfoCacheTest.java | 11 +++++++++ .../tst/org/spearce/jgit/util/JGitTestUtil.java | 21 ++++++++++++++++- .../src/org/spearce/jgit/lib/ObjectDirectory.java | 6 +++++ .../spearce/jgit/lib/UpdateDirectoryInfoCache.java | 22 ++++++++++++++++++ 5 files changed, 83 insertions(+), 1 deletions(-) create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.javaorg.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java +24
-0@@ -1,11 +1,17 @@ package org.spearce.jgit.lib; import java.io.File; +import java.util.List; import java.util.UUID; +import org.spearce.jgit.util.JGitTestUtil; + import junit.framework.TestCase; public class ObjectDirectoryTest extends TestCase { + private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f"; + private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack"); + private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx"); private File testDir;@@ -58,6 +64,24 @@ public void testGettingObjectFile() throws Exception { od.fileFor(ObjectId.fromString("b052a1272310d8df34de72f60204dee7e28a43d0"))); } + public void testListLocalPacksNotCreated() throws Exception { + assertEquals(0, new ObjectDirectory(testDir).listLocalPacks().size()); + } + + public void testListLocalPacksWhenThereIsAPack() throws Exception { + createTestDir(); + File packsDir = new File(testDir, "pack"); + packsDir.mkdirs(); + + JGitTestUtil.copyFile(TEST_PACK, new File(packsDir, TEST_PACK.getName())); + JGitTestUtil.copyFile(TEST_IDX, new File(packsDir, TEST_IDX.getName())); + + ObjectDirectory od = new ObjectDirectory(testDir); + List<PackFile> localPacks = od.listLocalPacks(); + assertEquals(1, localPacks.size()); + assertEquals(TEST_PACK.getName(), localPacks.get(0).getPackFile().getName()); + } + public boolean deleteDir(File dir) { if (dir.isDirectory()) { String[] children = dir.list();org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java new file +11
-0@@ -0,0 +1,11 @@ +package org.spearce.jgit.lib; + +import junit.framework.TestCase; + +public class UpdateDirectoryInfoCacheTest extends TestCase { + + public void testBase() throws Exception { + fail("nyi"); + } + +}org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java +9
-1@@ -38,6 +38,12 @@ package org.spearce.jgit.util; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.net.URISyntaxException; import java.net.URL;@@ -60,11 +66,24 @@ public static File getTestResourceFile(final String fileName) { } try { return new File(url.toURI()); - } catch(URISyntaxException e) { + } catch (URISyntaxException e) { return new File(url.getPath()); } } + public static void copyFile(final File fromFile, final File toFile) throws IOException { + InputStream in = new FileInputStream(fromFile);
org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java public static File getTestResourceFile(final String fileName) { · line 85
Quoted 10 lines
org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java +10
-0+ OutputStream out = new FileOutputStream(toFile); + + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + in.close(); + out.close(); + }
You need to check for short reads, i.e. read could retrieve
fewer bytes than requested, Less important, a larger buffer size could perhaps be used too (like 8192 which is the default BufferedReader buffer size).
org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java boolean tryAgain(final long currLastModified) { · line 514
Quoted 12 lines
org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java +0
-0private static ClassLoader cl() { return JGitTestUtil.class.getClassLoader(); }org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java +1
-0@@ -511,6 +511,12 @@ boolean tryAgain(final long currLastModified) { @Override public List<PackFile> listLocalPacks() { + tryAgain1();
mmmm. probably good.
org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java boolean tryAgain(final long currLastModified) { · line 517
Quoted 3 lines
org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java +3
-0+ public void execute() { +// File objectFile = objectDatabase. +// String packsContents = new PacksFileContentsCreator(this.objectDatabase.listLocalPacks()).toString();
Out commented code is a no-no.
-- robin
Re: [PATCH JGit 04/19] added utility that generates the contents of the objects/info/packs file as a string from a list of PackFiles
In reply to [email protected]Quoted 6 lines
org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java new file +0
-0
org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java line 9
Quoted 9 lines
org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java new file +9
-0@@ -0,0 +1,21 @@ +package org.spearce.jgit.lib; + +import java.util.List; + +public class PacksFileContentsCreator { + + private List<PackFile> packs; + + public PacksFileContentsCreator(List<PackFile> packs) {
We want good javadocs for (at least) all public and protected methods and classes. (We enforce this for Eclipse users). If we had similar configuration files for, perhaps netbeans we might have those too. (not finished thinking about that proposition...)
org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java line 13
Quoted 4 lines
org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java new file +4
-0+ this.packs = packs; + } + + public String toString(){
Don't overload toString. Let it be useful for debug like purposes. With this style we cannot make it useful since the application depends on its exact behaviour. You may define a toString anyway that does the exact same thing, but please provide a specific method for assisting with the formatting of the file. A writeTo(OutputStream) is a useful interface in general.
org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java line 16
Quoted 3 lines
org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java new file +3
-0+ StringBuilder builder = new StringBuilder(); + for (PackFile packFile : packs) { + builder.append("P ").append(packFile.getPackFile().getName()).append('\r');
At least my git formats the file with \n as line terminator, so I think JGit should too.. Git ends the file with an extra \n, though I'm not sure it's relevant.
org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java line 19
Quoted 3 lines
org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java new file +3
-0+ } + return builder.toString(); + }
The name is somewhat confusing as the s is hard to spot. The suggestion InfoPacksFileGenerator perhaps. It's a bit uglier by easier not to mix with generation of pack files.
-- robin
Re: [PATCH JGit 01/19] adding tests for ObjectDirectory
In reply to [email protected]söndag 13 september 2009 20:44:17 skrev [email protected]:
Quoted 18 lines
From: mike.gaffney <[email protected]>
--- .../org/spearce/jgit/lib/ObjectDirectoryTest.java | 80 ++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 deletions(-) create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.javaorg.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java new file +5
-0@@ -0,0 +1,80 @@ +package org.spearce.jgit.lib; + +import java.io.File; +import java.util.UUID; +
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java line 15
Quoted 10 lines
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java new file +10
-0+import junit.framework.TestCase; + +public class ObjectDirectoryTest extends TestCase { + + private File testDir; + + @Override + protected void setUp() throws Exception { + testDir = new File(new File(System.getProperty("java.io.tmpdir")), UUID.randomUUID().toString()); + }
Good. Now that we're on Java5 we might use this more.
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java line 61
Quoted 9 lines
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java new file +9
-0+ public void testGettingObjectFile() throws Exception { + ObjectDirectory od = new ObjectDirectory(testDir); + assertEquals(new File(testDir, "02/829ae153935095e4223f30cfc98c835de71bee"), + od.fileFor(ObjectId.fromString("02829ae153935095e4223f30cfc98c835de71bee"))); + assertEquals(new File(testDir, "b0/52a1272310d8df34de72f60204dee7e28a43d0"), + od.fileFor(ObjectId.fromString("b052a1272310d8df34de72f60204dee7e28a43d0"))); + } + + public boolean deleteDir(File dir) {
RepositoryTestcase already contains a recursive delete, including a static one that you can use even without inheritance since you are within the same package. It is rather standalone so it could perhaps move to JGitTestUtil.
Quoted 6 lines
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java new file +6
-0+ if (dir.isDirectory()) { + String[] children = dir.list(); + for (int i=0; i<children.length; i++) { + boolean success = deleteDir(new File(dir, children[i])); + if (!success) { + return false;
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java line 77
Quoted 10 lines
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java new file +10
-0+ } + } + } + + // The directory is now empty so delete it + return dir.delete(); + } + + private void createTestDir(){ + testDir.mkdir();
No error checking. If mkdirfails the test probably fails for mysterious reasons,
Quoted 3 lines
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java new file +3
-0+ } + +}