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.
threads / patch / 20935
patchAdding update-server-info functionality
Subject: [PATCH JGit] Adding update-server-info functionality
[PATCH JGit 01/19] adding tests for ObjectDirectory
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../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
Show changes to org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java +80 −0
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java new file mode 100644 index 0000000..fe019af --- /dev/null +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java @@ -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(); + } + +}
-- 1.6.4.2
[PATCH JGit 02/19] Create abstract method on ObjectDatabase for accessing the list of local pack files.
From: mike.gaffney <mike.gaffney@asolutions.com>
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(-)
Show changes to 3 files +21 −1
org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java, org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java, org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java index ee4c4cf..68ad488 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java @@ -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(); + } } diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java index a547052..722c802 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java @@ -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? * diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java index 859824d..fe219c6 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java @@ -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)); + } }
-- 1.6.4.2
[PATCH JGit 03/19] Add abstract method for updating the object db's info cache Implemented passthrough on Alternate for the update of infocache
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../jgit/lib/AlternateRepositoryDatabase.java | 5 +++++ .../src/org/spearce/jgit/lib/ObjectDatabase.java | 7 +++++++ 2 files changed, 12 insertions(+), 0 deletions(-)
Show changes to 2 files +12 −0
org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java, org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java index 68ad488..5cb0579 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java @@ -130,4 +130,9 @@ protected void closeAlternates(final ObjectDatabase[] alt) { public List<PackFile> listLocalPacks() { return odb.listLocalPacks(); } + + @Override + public void updateInfoCache() { + odb.updateInfoCache(); + } } diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java index 722c802..68ff523 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java @@ -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
-- 1.6.4.2
[PATCH JGit 04/19] added utility that generates the contents of the objects/info/packs file as a string from a list of PackFiles
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../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
Show changes to 2 files +58 −0
org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java, org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java new file mode 100644 index 0000000..ef28a26 --- /dev/null +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java @@ -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()); + } + +} diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java new file mode 100644 index 0000000..3dd0418 --- /dev/null +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java @@ -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(); + } + +}
-- 1.6.4.2
[PATCH JGit 05/19] Made tests for listLocalPacks function on ObjectDirectory and made them pass
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../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
Show changes to 5 files +83 −1
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java, org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java, org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java, org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java, org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java index fe019af..8e4d8e5 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java @@ -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(); diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java new file mode 100644 index 0000000..11d183e --- /dev/null +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java @@ -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"); + } + +} diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java index eee0c14..04184d7 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java @@ -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(); } diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java index fe219c6..a90ae00 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java @@ -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(); + } } diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java new file mode 100644 index 0000000..2bceb9e --- /dev/null +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java @@ -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(); + } + +}
-- 1.6.4.2
[PATCH JGit 06/19] added utility for reading the contents of a file as a string
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../tst/org/spearce/jgit/util/JGitTestUtil.java | 20 +++++++++++++++++++- 1 files changed, 19 insertions(+), 1 deletions(-)
Show changes to org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java +19 −1
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java index 04184d7..b958282 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java @@ -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(); }
-- 1.6.4.2
[PATCH JGit 07/19] implemented the packs file update functionality
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../jgit/lib/UpdateDirectoryInfoCacheTest.java | 23 ++++++++++++++++++- .../spearce/jgit/lib/UpdateDirectoryInfoCache.java | 17 +++++++++----- 2 files changed, 32 insertions(+), 8 deletions(-)
Show changes to 2 files +32 −8
org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java, org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java index 11d183e..25b78c5 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java @@ -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)); } } diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java index 2bceb9e..72a315a 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java @@ -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(); } }
-- 1.6.4.2
[PATCH JGit 08/19] changed signature to allow a IOException
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../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(-)
Show changes to 3 files +5 −4
org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java, org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java, org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java index 5cb0579..70ce505 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java @@ -132,7 +132,7 @@ protected void closeAlternates(final ObjectDatabase[] alt) { } @Override - public void updateInfoCache() { + public void updateInfoCache() throws IOException { odb.updateInfoCache(); } } diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java index 68ff523..5ded7bb 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java @@ -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? diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java index a90ae00..95618b9 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java @@ -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(); } }
-- 1.6.4.2
[PATCH JGit 09/19] Didn't like the old name, this is more specific to it just updating the packs info cache
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../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
Show changes to 5 files +58 −58
org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java, org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java, org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java, org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java, org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java new file mode 100644 index 0000000..f5163e4 --- /dev/null +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java @@ -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)); + } + +} diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java deleted file mode 100644 index 25b78c5..0000000 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java +++ /dev/null @@ -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)); - } - -} diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java index 95618b9..71536c9 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java @@ -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(); } } diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java new file mode 100644 index 0000000..3e24cd2 --- /dev/null +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java @@ -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(); + } + +} diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java deleted file mode 100644 index 72a315a..0000000 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java +++ /dev/null @@ -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(); - } - -}
-- 1.6.4.2
[PATCH JGit 10/19] moved test up to a higher level to test actual functionality
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../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
Show changes to 2 files +26 −36
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java, org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java index 8e4d8e5..4ac62fa 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java @@ -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())); + } } diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java deleted file mode 100644 index f5163e4..0000000 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCacheTest.java +++ /dev/null @@ -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)); - } - -}
-- 1.6.4.2
[PATCH JGit 11/19] removed unused import
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../lib/UpdateDirectoryBasedPacksInfoCache.java | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
Show changes to org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java +0 −1
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java index 3e24cd2..e4caa43 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java @@ -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;
-- 1.6.4.2
[PATCH JGit 12/19] moved info/packs into a constant
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../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(-)
Show changes to 3 files +6 −4
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java, org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java, org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java index 4ac62fa..b27f2f8 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java @@ -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(); } diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java index 9afea67..2d78dda 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java @@ -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"; diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java index 71536c9..f4251c1 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java @@ -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(); } }
-- 1.6.4.2
[PATCH JGit 13/19] made the call update the object database's info cache
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../org/spearce/jgit/transport/ReceivePack.java | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
Show changes to org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java +10 −0
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java index eb21254..5865736 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java @@ -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()); } }
-- 1.6.4.2
[PATCH JGit 14/19] pulled out some helper functions that will be useful for other tests
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../org/spearce/jgit/lib/ObjectDirectoryTest.java | 21 ++----------------- .../tst/org/spearce/jgit/util/JGitTestUtil.java | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 19 deletions(-)
Show changes to 2 files +22 −19
org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java, org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java index b27f2f8..4fecce7 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java @@ -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(); } diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java index b958282..7506553 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java @@ -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()); + } }
-- 1.6.4.2
[PATCH JGit 15/19] Adding in a InfoDatabase like ObjectDatabase and and implementation based upon a directory.
From: mike.gaffney <mike.gaffney@asolutions.com>
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
Show changes to 5 files +68 −0
org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java, org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java, org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java, org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java, org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java new file mode 100644 index 0000000..2b7fb5b --- /dev/null +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java @@ -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()); + } +} diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java new file mode 100644 index 0000000..2f1f398 --- /dev/null +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java @@ -0,0 +1,8 @@ +package org.spearce.jgit.lib; + +public abstract class InfoDatabase { + + public void create() { + } + +} diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java new file mode 100644 index 0000000..20d8a70 --- /dev/null +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java @@ -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(); + } + +} diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java index 46b7804..f658b5c 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java @@ -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 diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java index 5865736..baa1dec 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java @@ -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;
-- 1.6.4.2
[PATCH JGit 16/19] added tests for the file based info cache update and made pass
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../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(-)
Show changes to 3 files +60 −0
org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java, org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java, org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java index 2b7fb5b..22972fa 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java @@ -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); + } } diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java index 2f1f398..26f8f22 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java @@ -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; + } diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java index 20d8a70..f95be2f 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java @@ -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(); + } + }
-- 1.6.4.2
[PATCH JGit 17/19] added call to update the info refs file
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../org/spearce/jgit/transport/ReceivePack.java | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
Show changes to org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java +10 −0
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java index baa1dec..0c818d9 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java @@ -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()); } }
-- 1.6.4.2
[PATCH JGit 18/19] Added Copyright Notices
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../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(-)
Show changes to 7 files +254 −3
org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java, org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java, org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java, org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java, org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java, org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java, org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java index 22972fa..3aa0fd6 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java @@ -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; diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java index 4fecce7..e14db75 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java @@ -1,14 +1,49 @@ +/* + * 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; import java.io.IOException; -import java.util.ArrayList; import java.util.List; -import org.spearce.jgit.util.JGitTestUtil; - import junit.framework.TestCase; +import org.spearce.jgit.util.JGitTestUtil; + public class ObjectDirectoryTest extends TestCase { private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f"; private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack"); diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java index ef28a26..8dc9109 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java @@ -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; diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java index 26f8f22..96a39fc 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java @@ -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; diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java index f95be2f..48f60d1 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java @@ -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; diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java index 3dd0418..0efc244 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java @@ -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; diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java index e4caa43..af61069 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java @@ -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;
-- 1.6.4.2
[PATCH JGit 19/19] changed \r to \n per compliance with real git
From: mike.gaffney <mike.gaffney@asolutions.com>
--- .../jgit/lib/PacksFileContentsCreatorTest.java | 9 +++++---- .../spearce/jgit/lib/PacksFileContentsCreator.java | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-)
Show changes to 2 files +7 −5
org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java, org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java index 8dc9109..bf61a59 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java @@ -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()); } diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java index 0efc244..e8b90a2 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java @@ -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(); }
-- 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
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
söndag 13 september 2009 20:44:23 skrev mr.gaffo@gmail.com:
Show 82 quoted lines
> From: mike.gaffney <mike.gaffney@asolutions.com>
>
> ---
> .../jgit/lib/UpdateDirectoryInfoCacheTest.java | 23 ++++++++++++++++++-
> .../spearce/jgit/lib/UpdateDirectoryInfoCache.java | 17 +++++++++-----
> 2 files changed, 32 insertions(+), 8 deletions(-)
>
> diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java
> index 11d183e..25b78c5 100644
> --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java
> +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java
> @@ -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));
> }
>
> }
> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java
> index 2bceb9e..72a315a 100644
> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java
> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java
> @@ -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();
> }
>
> }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
söndag 13 september 2009 20:44:21 skrev mr.gaffo@gmail.com:
Show 115 quoted lines
> From: mike.gaffney <mike.gaffney@asolutions.com>
>
> ---
> .../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
>
> diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
> index fe019af..8e4d8e5 100644
> --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
> +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
> @@ -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();
> diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java
> new file mode 100644
> index 0000000..11d183e
> --- /dev/null
> +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/UpdateDirectoryInfoCacheTest.java
> @@ -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");
> + }
> +
> +}
> diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
> index eee0c14..04184d7 100644
> --- a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
> +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java
> @@ -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();
> + }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).
Show 12 quoted lines
> private static ClassLoader cl() {
> return JGitTestUtil.class.getClassLoader();
> }
> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
> index fe219c6..a90ae00 100644
> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java
> @@ -511,6 +511,12 @@ boolean tryAgain(final long currLastModified) {
>
> @Override
> public List<PackFile> listLocalPacks() {
> + tryAgain1();mmmm. probably good.
> + 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
Show 15 quoted lines
> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java
> new file mode 100644
> index 0000000..3dd0418
> --- /dev/null
> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java
> @@ -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...)
> + 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.
> + 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.
> + } > + 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
söndag 13 september 2009 20:44:17 skrev mr.gaffo@gmail.com:
Show 28 quoted lines
> From: mike.gaffney <mike.gaffney@asolutions.com>
>
> ---
> .../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
>
> diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
> new file mode 100644
> index 0000000..fe019af
> --- /dev/null
> +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java
> @@ -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());
> + }Good. Now that we're on Java5 we might use this more.
Show 9 quoted lines
> + 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.
Show 16 quoted lines
> + 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();No error checking. If mkdirfails the test probably fails for mysterious reasons,
> + } > + > +}