{"thread":{"id":"20959","subject":"[PATCH JGit 1/5] adding tests for ObjectDirectory","startedAt":"2009-09-16T00:48:31Z","lastAt":"2009-10-08T17:12:45Z","messageCount":12,"participants":["mr.gaffo@gmail.com","Shawn O. Pearce","Michael Gaffney"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"123292","messageId":"1253062116-13830-1-git-send-email-mr.gaffo@gmail.com","threadId":"20959","inReplyTo":null,"subject":"[PATCH JGit] Adding update-server-info functionality try2","fromName":"","fromEmail":"mr.gaffo@gmail.com","sentAt":"2009-09-16T00:48:31Z","receivedAt":"2009-09-16T00:48:31Z","isPatch":true,"sender":{"key":"mr.gaffo@gmail.com","avatar":"https://gravatar.com/avatar/5af46a60cbd83f2ddb0c2cf4d02b91db42fd25e2ac568ff0d71f699d852ee79d?d=mp&s=160"},"body":"This patch series implements update-server-info functionality\nin JGit and integrates it with ReceivePack so that repositories\nhosted by git-http can also be hosted by JGit.\n\nIt also incorporates suggesions from RobinRosenberg.\n\nPlease be gentle.\n"},{"id":"123290","messageId":"1253062116-13830-2-git-send-email-mr.gaffo@gmail.com","threadId":"20959","inReplyTo":"1253062116-13830-1-git-send-email-mr.gaffo@gmail.com","subject":"[PATCH JGit 1/5] adding tests for ObjectDirectory","fromName":"","fromEmail":"mr.gaffo@gmail.com","sentAt":"2009-09-16T00:48:32Z","receivedAt":"2009-09-16T00:48:32Z","isPatch":true,"sender":{"key":"mr.gaffo@gmail.com","avatar":"https://gravatar.com/avatar/5af46a60cbd83f2ddb0c2cf4d02b91db42fd25e2ac568ff0d71f699d852ee79d?d=mp&s=160"},"body":"From: mike.gaffney <mike.gaffney@asolutions.com>\n\nSigned-off-by: Mike Gaffney <mr.gaffo@gmail.com>\n---\n .../org/spearce/jgit/lib/ObjectDirectoryTest.java  |  106 ++++++++++++++++++++\n .../org/spearce/jgit/lib/RepositoryTestCase.java   |   58 +----------\n .../tst/org/spearce/jgit/util/JGitTestUtil.java    |   49 +++++++++\n 3 files changed, 161 insertions(+), 52 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java\n\ndiff --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\nnew file mode 100644\nindex 0000000..5b1fc0f\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java\n@@ -0,0 +1,106 @@\n+/*\n+ * Copyright (C) 2009, Mike Gaffney.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+package org.spearce.jgit.lib;\n+\n+import java.io.File;\n+import java.io.IOException;\n+import java.util.UUID;\n+\n+import org.spearce.jgit.util.JGitTestUtil;\n+\n+import junit.framework.TestCase;\n+\n+public class ObjectDirectoryTest extends TestCase {\n+\t\n+\tprivate File testDir;\n+\n+\t@Override\n+\tprotected void setUp() throws Exception {\n+\t\ttestDir = new File(new File(System.getProperty(\"java.io.tmpdir\")), UUID.randomUUID().toString());\n+\t}\n+\t\n+\t@Override\n+\tprotected void tearDown() throws Exception {\n+\t\tif (testDir.exists()){\n+\t\t\tJGitTestUtil.recursiveDelete(testDir, false, getClass().getName() + \".\" + getName(), true);\n+\t\t}\n+\t}\n+\n+\tpublic void testCanGetDirectory() throws Exception {\n+\t\tObjectDirectory od = new ObjectDirectory(testDir);\n+\t\tassertEquals(testDir, od.getDirectory());\n+\t}\n+\t\n+\tpublic void testExistsWithExistingDirectory() throws Exception {\n+\t\tcreateTestDir();\n+\t\tObjectDirectory od = new ObjectDirectory(testDir);\n+\t\tassertTrue(od.exists());\n+\t}\n+\t\n+\tpublic void testExistsWithNonExistantDirectory() throws Exception {\n+\t\tassertFalse(new ObjectDirectory(new File(\"/some/nonexistant/file\")).exists());\n+\t}\n+\t\n+\tpublic void testCreateMakesCorrectDirectories() throws Exception {\n+\t\tassertFalse(testDir.exists());\n+\t\tnew ObjectDirectory(testDir).create();\n+\t\tassertTrue(testDir.exists());\n+\t\t\n+\t\tFile infoDir = new File(testDir, \"info\");\n+\t\tassertTrue(infoDir.exists());\n+\t\tassertTrue(infoDir.isDirectory());\n+\t\t\n+\t\tFile packDir = new File(testDir, \"pack\");\n+\t\tassertTrue(packDir.exists());\n+\t\tassertTrue(packDir.isDirectory());\n+\t}\n+\t\n+\tpublic void testGettingObjectFile() throws Exception {\n+\t\tObjectDirectory od = new ObjectDirectory(testDir);\n+\t\tassertEquals(new File(testDir, \"02/829ae153935095e4223f30cfc98c835de71bee\"), \n+\t\t\t\t\t od.fileFor(ObjectId.fromString(\"02829ae153935095e4223f30cfc98c835de71bee\")));\n+\t\tassertEquals(new File(testDir, \"b0/52a1272310d8df34de72f60204dee7e28a43d0\"), \n+\t\t\t\t od.fileFor(ObjectId.fromString(\"b052a1272310d8df34de72f60204dee7e28a43d0\")));\n+\t}\n+\t\n+\tprivate void createTestDir(){\n+\t\tif (!testDir.mkdir()){\n+\t\t\tfail(\"unable to create test directory\");\n+\t\t}\n+\t}\n+\t\n+}\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java\nindex d1aef78..cfd7d25 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryTestCase.java\n@@ -106,53 +106,7 @@ protected void configure() {\n \t * @param dir\n \t */\n \tprotected void recursiveDelete(final File dir) {\n-\t\trecursiveDelete(dir, false, getClass().getName() + \".\" + getName(), true);\n-\t}\n-\n-\tprotected static boolean recursiveDelete(final File dir, boolean silent,\n-\t\t\tfinal String name, boolean failOnError) {\n-\t\tassert !(silent && failOnError);\n-\t\tif (!dir.exists())\n-\t\t\treturn silent;\n-\t\tfinal File[] ls = dir.listFiles();\n-\t\tif (ls != null) {\n-\t\t\tfor (int k = 0; k < ls.length; k++) {\n-\t\t\t\tfinal File e = ls[k];\n-\t\t\t\tif (e.isDirectory()) {\n-\t\t\t\t\tsilent = recursiveDelete(e, silent, name, failOnError);\n-\t\t\t\t} else {\n-\t\t\t\t\tif (!e.delete()) {\n-\t\t\t\t\t\tif (!silent) {\n-\t\t\t\t\t\t\treportDeleteFailure(name, failOnError, e);\n-\t\t\t\t\t\t}\n-\t\t\t\t\t\tsilent = !failOnError;\n-\t\t\t\t\t}\n-\t\t\t\t}\n-\t\t\t}\n-\t\t}\n-\t\tif (!dir.delete()) {\n-\t\t\tif (!silent) {\n-\t\t\t\treportDeleteFailure(name, failOnError, dir);\n-\t\t\t}\n-\t\t\tsilent = !failOnError;\n-\t\t}\n-\t\treturn silent;\n-\t}\n-\n-\tprivate static void reportDeleteFailure(final String name,\n-\t\t\tboolean failOnError, final File e) {\n-\t\tString severity;\n-\t\tif (failOnError)\n-\t\t\tseverity = \"Error\";\n-\t\telse\n-\t\t\tseverity = \"Warning\";\n-\t\tString msg = severity + \": Failed to delete \" + e;\n-\t\tif (name != null)\n-\t\t\tmsg += \" in \" + name;\n-\t\tif (failOnError)\n-\t\t\tfail(msg);\n-\t\telse\n-\t\t\tSystem.out.println(msg);\n+\t\tJGitTestUtil.recursiveDelete(dir, false, getClass().getName() + \".\" + getName(), true);\n \t}\n \n \tprotected static void copyFile(final File src, final File dst)\n@@ -215,7 +169,7 @@ public void setUp() throws Exception {\n \t\tsuper.setUp();\n \t\tconfigure();\n \t\tfinal String name = getClass().getName() + \".\" + getName();\n-\t\trecursiveDelete(trashParent, true, name, false); // Cleanup old failed stuff\n+\t\tJGitTestUtil.recursiveDelete(trashParent, true, name, false); // Cleanup old failed stuff\n \t\ttrash = new File(trashParent,\"trash\"+System.currentTimeMillis()+\".\"+(testcount++));\n \t\ttrash_git = new File(trash, \".git\").getCanonicalFile();\n \t\tif (shutdownhook == null) {\n@@ -230,7 +184,7 @@ public void run() {\n \t\t\t\t\tSystem.gc();\n \t\t\t\t\tfor (Runnable r : shutDownCleanups)\n \t\t\t\t\t\tr.run();\n-\t\t\t\t\trecursiveDelete(trashParent, false, null, false);\n+\t\t\t\t\tJGitTestUtil.recursiveDelete(trashParent, false, null, false);\n \t\t\t\t}\n \t\t\t};\n \t\t\tRuntime.getRuntime().addShutdownHook(shutdownhook);\n@@ -277,9 +231,9 @@ protected void tearDown() throws Exception {\n \t\t\tSystem.gc();\n \n \t\tfinal String name = getClass().getName() + \".\" + getName();\n-\t\trecursiveDelete(trash, false, name, true);\n+\t\tJGitTestUtil.recursiveDelete(trash, false, name, true);\n \t\tfor (Repository r : repositoriesToClose)\n-\t\t\trecursiveDelete(r.getWorkDir(), false, name, true);\n+\t\t\tJGitTestUtil.recursiveDelete(r.getWorkDir(), false, name, true);\n \t\trepositoriesToClose.clear();\n \n \t\tsuper.tearDown();\n@@ -314,7 +268,7 @@ protected Repository createNewEmptyRepo(boolean bare) throws IOException {\n \t\tfinal String name = getClass().getName() + \".\" + getName();\n \t\tshutDownCleanups.add(new Runnable() {\n \t\t\tpublic void run() {\n-\t\t\t\trecursiveDelete(newTestRepo, false, name, false);\n+\t\t\t\tJGitTestUtil.recursiveDelete(newTestRepo, false, name, false);\n \t\t\t}\n \t\t});\n \t\trepositoriesToClose.add(newRepo);\ndiff --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\nindex eee0c14..446c674 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java\n@@ -41,6 +41,9 @@\n import java.net.URISyntaxException;\n import java.net.URL;\n \n+import junit.framework.AssertionFailedError;\n+\n+\n public abstract class JGitTestUtil {\n \tpublic static final String CLASSPATH_TO_RESOURCES = \"org/spearce/jgit/test/resources/\";\n \n@@ -68,4 +71,50 @@ public static File getTestResourceFile(final String fileName) {\n \tprivate static ClassLoader cl() {\n \t\treturn JGitTestUtil.class.getClassLoader();\n \t}\n+\n+\tpublic static boolean recursiveDelete(final File dir, boolean silent,\n+\t\t\tfinal String name, boolean failOnError) {\n+\t\tassert !(silent && failOnError);\n+\t\tif (!dir.exists())\n+\t\t\treturn silent;\n+\t\tfinal File[] ls = dir.listFiles();\n+\t\tif (ls != null) {\n+\t\t\tfor (int k = 0; k < ls.length; k++) {\n+\t\t\t\tfinal File e = ls[k];\n+\t\t\t\tif (e.isDirectory()) {\n+\t\t\t\t\tsilent = recursiveDelete(e, silent, name, failOnError);\n+\t\t\t\t} else {\n+\t\t\t\t\tif (!e.delete()) {\n+\t\t\t\t\t\tif (!silent) {\n+\t\t\t\t\t\t\tJGitTestUtil.reportDeleteFailure(name, failOnError, e);\n+\t\t\t\t\t\t}\n+\t\t\t\t\t\tsilent = !failOnError;\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t\tif (!dir.delete()) {\n+\t\t\tif (!silent) {\n+\t\t\t\tJGitTestUtil.reportDeleteFailure(name, failOnError, dir);\n+\t\t\t}\n+\t\t\tsilent = !failOnError;\n+\t\t}\n+\t\treturn silent;\n+\t}\n+\n+\tprivate static void reportDeleteFailure(final String name,\n+\t\t\tboolean failOnError, final File e) {\n+\t\tString severity;\n+\t\tif (failOnError)\n+\t\t\tseverity = \"Error\";\n+\t\telse\n+\t\t\tseverity = \"Warning\";\n+\t\tString msg = severity + \": Failed to delete \" + e;\n+\t\tif (name != null)\n+\t\t\tmsg += \" in \" + name;\n+\t\tif (failOnError)\n+\t\t\tthrow new AssertionFailedError(msg);\n+\t\telse\n+\t\t\tSystem.out.println(msg);\n+\t}\n }\n-- \n1.6.4.2\n"},{"id":"123291","messageId":"1253062116-13830-3-git-send-email-mr.gaffo@gmail.com","threadId":"20959","inReplyTo":"1253062116-13830-2-git-send-email-mr.gaffo@gmail.com","subject":"[PATCH JGit 2/5] Create abstract method on ObjectDatabase for accessing the list of local pack files.","fromName":"","fromEmail":"mr.gaffo@gmail.com","sentAt":"2009-09-16T00:48:33Z","receivedAt":"2009-09-16T00:48:33Z","isPatch":true,"sender":{"key":"mr.gaffo@gmail.com","avatar":"https://gravatar.com/avatar/5af46a60cbd83f2ddb0c2cf4d02b91db42fd25e2ac568ff0d71f699d852ee79d?d=mp&s=160"},"body":"From: mike.gaffney <mike.gaffney@asolutions.com>\n\nImplemented the method for AlternateRepository database as a passthrough\n\nImplemented the method for ObjectDirectory as a toList of the current\ncached private PackList.\n\nHopefully this will allow easier reference to the list of packs for\nothers like the server side of fetch.\n\nSigned-off-by: Mike Gaffney <mr.gaffo@gmail.com>\n---\n .../org/spearce/jgit/lib/ObjectDirectoryTest.java  |   22 ++++++++++++++++++++\n .../tst/org/spearce/jgit/util/JGitTestUtil.java    |   21 ++++++++++++++++++-\n .../jgit/lib/AlternateRepositoryDatabase.java      |    6 +++++\n .../src/org/spearce/jgit/lib/ObjectDatabase.java   |   11 +++++++++-\n .../src/org/spearce/jgit/lib/ObjectDirectory.java  |    6 +++++\n 5 files changed, 64 insertions(+), 2 deletions(-)\n\ndiff --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\nindex 5b1fc0f..c27580f 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java\n@@ -38,6 +38,7 @@\n \n import java.io.File;\n import java.io.IOException;\n+import java.util.List;\n import java.util.UUID;\n \n import org.spearce.jgit.util.JGitTestUtil;\n@@ -45,6 +46,9 @@\n import junit.framework.TestCase;\n \n public class ObjectDirectoryTest extends TestCase {\n+\tprivate static final String PACK_NAME = \"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f\";\n+\tprivate static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + \".pack\");\n+\tprivate static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + \".idx\");\n \t\n \tprivate File testDir;\n \n@@ -97,6 +101,24 @@ public void testGettingObjectFile() throws Exception {\n \t\t\t\t od.fileFor(ObjectId.fromString(\"b052a1272310d8df34de72f60204dee7e28a43d0\")));\n \t}\n \t\n+\tpublic void testListLocalPacksNotCreated() throws Exception {\n+\t\tassertEquals(0, new ObjectDirectory(testDir).listLocalPacks().size());\n+\t}\n+\t\n+\tpublic void testListLocalPacksWhenThereIsAPack() throws Exception {\n+\t\tcreateTestDir();\n+\t\tFile packsDir = new File(testDir, \"pack\");\n+\t\tpacksDir.mkdirs();\n+\t\t\n+\t\tJGitTestUtil.copyFile(TEST_PACK, new File(packsDir, TEST_PACK.getName()));\n+\t\tJGitTestUtil.copyFile(TEST_IDX, new File(packsDir, TEST_IDX.getName()));\n+\n+\t\tObjectDirectory od = new ObjectDirectory(testDir);\n+\t\tList<PackFile> localPacks = od.listLocalPacks();\n+\t\tassertEquals(1, localPacks.size());\n+\t\tassertEquals(TEST_PACK.getName(), localPacks.get(0).getPackFile().getName());\n+\t}\n+\n \tprivate void createTestDir(){\n \t\tif (!testDir.mkdir()){\n \t\t\tfail(\"unable to create test directory\");\ndiff --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\nindex 446c674..785922a 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java\n@@ -38,6 +38,12 @@\n package org.spearce.jgit.util;\n \n import java.io.File;\n+import java.io.FileInputStream;\n+import java.io.FileNotFoundException;\n+import java.io.FileOutputStream;\n+import java.io.IOException;\n+import java.io.InputStream;\n+import java.io.OutputStream;\n import java.net.URISyntaxException;\n import java.net.URL;\n \n@@ -63,11 +69,24 @@ public static File getTestResourceFile(final String fileName) {\n \t\t}\n \t\ttry {\n \t\t\treturn new File(url.toURI());\n-\t\t} catch(URISyntaxException e) {\n+\t\t} catch (URISyntaxException e) {\n \t\t\treturn new File(url.getPath());\n \t\t}\n \t}\n \n+\tpublic static void copyFile(final File fromFile, final File toFile) throws IOException {\n+\t\tInputStream in = new FileInputStream(fromFile);\n+\t\tOutputStream out = new FileOutputStream(toFile);\n+\n+\t\tbyte[] buf = new byte[1024];\n+\t\tint len;\n+\t\twhile ((len = in.read(buf)) > 0) {\n+\t\t\tout.write(buf, 0, len);\n+\t\t}\n+\t\tin.close();\n+\t\tout.close();\n+\t}\n+\n \tprivate static ClassLoader cl() {\n \t\treturn JGitTestUtil.class.getClassLoader();\n \t}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java\nindex ee4c4cf..68ad488 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java\n@@ -39,6 +39,7 @@\n \n import java.io.IOException;\n import java.util.Collection;\n+import java.util.List;\n \n /**\n  * An ObjectDatabase of another {@link Repository}.\n@@ -124,4 +125,9 @@ void openObjectInAllPacks1(final Collection<PackedObjectLoader> out,\n \tprotected void closeAlternates(final ObjectDatabase[] alt) {\n \t\t// Do nothing; these belong to odb to close, not us.\n \t}\n+\n+\t@Override\n+\tpublic List<PackFile> listLocalPacks() {\n+\t\treturn odb.listLocalPacks();\n+\t}\n }\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java\nindex a547052..722c802 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java\n@@ -39,6 +39,7 @@\n \n import java.io.IOException;\n import java.util.Collection;\n+import java.util.List;\n import java.util.concurrent.atomic.AtomicReference;\n \n /**\n@@ -64,7 +65,15 @@\n \tprotected ObjectDatabase() {\n \t\talternates = new AtomicReference<ObjectDatabase[]>();\n \t}\n-\n+\t\n+\t/**\n+\t * The list of Packs THIS repo contains\n+\t * \n+\t * @return List<PackFile> of package names contained in this repo. \n+\t * \t\t   Should be an empty list if there are none.\n+\t */\n+\tpublic abstract List<PackFile> listLocalPacks();\n+\t\n \t/**\n \t * Does this database exist yet?\n \t *\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java\nindex 859824d..cbe132d 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java\n@@ -508,4 +508,10 @@ boolean tryAgain(final long currLastModified) {\n \t\t\treturn true;\n \t\t}\n \t}\n+\n+\t@Override\n+\tpublic List<PackFile> listLocalPacks() {\n+\t\ttryAgain1();\n+\t\treturn new ArrayList<PackFile>(Arrays.asList(packList.get().packs));\n+\t}\n }\n-- \n1.6.4.2\n"},{"id":"123294","messageId":"1253062116-13830-4-git-send-email-mr.gaffo@gmail.com","threadId":"20959","inReplyTo":"1253062116-13830-3-git-send-email-mr.gaffo@gmail.com","subject":"[PATCH JGit 3/5] Implemented directory based info cache for objects/info/packs.","fromName":"","fromEmail":"mr.gaffo@gmail.com","sentAt":"2009-09-16T00:48:34Z","receivedAt":"2009-09-16T00:48:34Z","isPatch":true,"sender":{"key":"mr.gaffo@gmail.com","avatar":"https://gravatar.com/avatar/5af46a60cbd83f2ddb0c2cf4d02b91db42fd25e2ac568ff0d71f699d852ee79d?d=mp&s=160"},"body":"From: Mike Gaffney <mr.gaffo@gmail.com>\n\nDetails:\n\nAdd abstract method for updating the object db's info cache to directory.\n\nImplemented passthrough on Alternate for the update of infocache.\n\nAdded utility that generates the contents of the objects/info/packs\nfile as a string from a list of PackFiles.\n\nAdded implementation from ObjectDirectory on down\nfor creating the info cache.\n\nAdded test for creating the info cache\n\nSigned-off-by: Mike Gaffney <mr.gaffo@gmail.com>\n---\n .../CachedPacksInfoFileContentsGeneratorTest.java  |   74 ++++++++++++++++++++\n .../org/spearce/jgit/lib/ObjectDirectoryTest.java  |   36 +++++++---\n .../tst/org/spearce/jgit/util/JGitTestUtil.java    |   26 ++++++-\n .../jgit/lib/AlternateRepositoryDatabase.java      |    5 ++\n .../lib/CachedPacksInfoFileContentsGenerator.java  |   63 +++++++++++++++++\n .../src/org/spearce/jgit/lib/Constants.java        |    3 +\n .../src/org/spearce/jgit/lib/ObjectDatabase.java   |    8 ++\n .../src/org/spearce/jgit/lib/ObjectDirectory.java  |    5 ++\n .../lib/UpdateDirectoryBasedPacksInfoCache.java    |   62 ++++++++++++++++\n .../spearce/jgit/lib/UpdateDirectoryInfoCache.java |   26 +++++++\n .../org/spearce/jgit/transport/ReceivePack.java    |   10 +++\n 11 files changed, 307 insertions(+), 11 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/CachedPacksInfoFileContentsGenerator.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java\nnew file mode 100644\nindex 0000000..bea0b70\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java\n@@ -0,0 +1,74 @@\n+/*\n+ * Copyright (C) 2009, Mike Gaffney.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+package org.spearce.jgit.lib;\n+\n+import java.io.File;\n+import java.util.ArrayList;\n+import java.util.List;\n+\n+import org.spearce.jgit.util.JGitTestUtil;\n+\n+import junit.framework.TestCase;\n+\n+public class CachedPacksInfoFileContentsGeneratorTest extends TestCase {\n+\tprivate static final String PACK_NAME = \"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f\";\n+\tprivate static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + \".pack\");\n+\tprivate static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + \".idx\");\n+\n+\tpublic void testGettingPacksContentsSinglePack() throws Exception {\n+\t\tList<PackFile> packs = new ArrayList<PackFile>();\n+\t\tpacks.add(new PackFile(TEST_IDX, TEST_PACK));\n+\t\t\n+\t\tassertEquals(\"P \" + TEST_PACK.getName() + \"\\n\\n\", new CachedPacksInfoFileContentsGenerator(packs).generateContents());\n+\t}\n+\t\n+\tpublic void testGettingPacksContentsMultiplePacks() throws Exception {\n+\t\tList<PackFile> packs = new ArrayList<PackFile>();\n+\t\tpacks.add(new PackFile(TEST_IDX, TEST_PACK));\n+\t\tpacks.add(new PackFile(TEST_IDX, TEST_PACK));\n+\t\tpacks.add(new PackFile(TEST_IDX, TEST_PACK));\n+\t\t\n+\t\tStringBuilder expected = new StringBuilder();\n+\t\texpected.append(\"P \").append(TEST_PACK.getName()).append(\"\\n\");\n+\t\texpected.append(\"P \").append(TEST_PACK.getName()).append(\"\\n\");\n+\t\texpected.append(\"P \").append(TEST_PACK.getName()).append(\"\\n\");\n+\t\texpected.append(\"\\n\");\n+\t\t\n+\t\tassertEquals(expected.toString(), new CachedPacksInfoFileContentsGenerator(packs).generateContents());\n+\t}\n+\t\n+}\ndiff --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\nindex c27580f..204fb7c 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java\n@@ -38,8 +38,8 @@\n \n import java.io.File;\n import java.io.IOException;\n+import java.util.ArrayList;\n import java.util.List;\n-import java.util.UUID;\n \n import org.spearce.jgit.util.JGitTestUtil;\n \n@@ -54,9 +54,9 @@\n \n \t@Override\n \tprotected void setUp() throws Exception {\n-\t\ttestDir = new File(new File(System.getProperty(\"java.io.tmpdir\")), UUID.randomUUID().toString());\n+\t\ttestDir = JGitTestUtil.generateTempDirectoryFileObject();\n \t}\n-\t\n+\n \t@Override\n \tprotected void tearDown() throws Exception {\n \t\tif (testDir.exists()){\n@@ -106,23 +106,41 @@ public void testListLocalPacksNotCreated() throws Exception {\n \t}\n \t\n \tpublic void testListLocalPacksWhenThereIsAPack() throws Exception {\n-\t\tcreateTestDir();\n-\t\tFile packsDir = new File(testDir, \"pack\");\n-\t\tpacksDir.mkdirs();\n-\t\t\n-\t\tJGitTestUtil.copyFile(TEST_PACK, new File(packsDir, TEST_PACK.getName()));\n-\t\tJGitTestUtil.copyFile(TEST_IDX, new File(packsDir, TEST_IDX.getName()));\n+\t\tcreateSamplePacksDir();\n \n \t\tObjectDirectory od = new ObjectDirectory(testDir);\n \t\tList<PackFile> localPacks = od.listLocalPacks();\n \t\tassertEquals(1, localPacks.size());\n \t\tassertEquals(TEST_PACK.getName(), localPacks.get(0).getPackFile().getName());\n \t}\n+\t\n+\tpublic void testUpdateInfoCacheCreatesPacksAndRefsFile() throws Exception {\n+\t\tcreateSamplePacksDir();\n+\n+\t\tObjectDirectory od = new ObjectDirectory(testDir);\n+\t\tod.create();\n+\t\tod.updateInfoCache();\n+\t\t\n+\t\tString expectedContents = new CachedPacksInfoFileContentsGenerator(od.listLocalPacks()).generateContents();\n+\t\tFile packsFile = new File(od.getDirectory(), Constants.CACHED_PACKS_FILE);\n+\n+\t\tassertTrue(packsFile.exists());\n+\t\tassertEquals(expectedContents, JGitTestUtil.readFileAsString(packsFile));\n+\t}\n \n \tprivate void createTestDir(){\n \t\tif (!testDir.mkdir()){\n \t\t\tfail(\"unable to create test directory\");\n \t\t}\n \t}\n+\n+\tprivate void createSamplePacksDir() throws IOException {\n+\t\tcreateTestDir();\n+\t\tFile packsDir = new File(testDir, \"pack\");\n+\t\tpacksDir.mkdirs();\n+\t\t\n+\t\tJGitTestUtil.copyFile(TEST_PACK, new File(packsDir, TEST_PACK.getName()));\n+\t\tJGitTestUtil.copyFile(TEST_IDX, new File(packsDir, TEST_IDX.getName()));\n+\t}\n \t\n }\ndiff --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\nindex 785922a..44630fd 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java\n@@ -37,15 +37,17 @@\n \n package org.spearce.jgit.util;\n \n+import java.io.BufferedReader;\n import java.io.File;\n import java.io.FileInputStream;\n-import java.io.FileNotFoundException;\n import java.io.FileOutputStream;\n+import java.io.FileReader;\n import java.io.IOException;\n import java.io.InputStream;\n import java.io.OutputStream;\n import java.net.URISyntaxException;\n import java.net.URL;\n+import java.util.UUID;\n \n import junit.framework.AssertionFailedError;\n \n@@ -74,7 +76,8 @@ public static File getTestResourceFile(final String fileName) {\n \t\t}\n \t}\n \n-\tpublic static void copyFile(final File fromFile, final File toFile) throws IOException {\n+\tpublic static void copyFile(final File fromFile, final File toFile)\n+\t\t\tthrows IOException {\n \t\tInputStream in = new FileInputStream(fromFile);\n \t\tOutputStream out = new FileOutputStream(toFile);\n \n@@ -87,6 +90,21 @@ public static void copyFile(final File fromFile, final File toFile) throws IOExc\n \t\tout.close();\n \t}\n \n+\tpublic static String readFileAsString(final File file)\n+\t\t\tthrows java.io.IOException {\n+\t\tStringBuilder fileData = new StringBuilder(1000);\n+\t\tBufferedReader reader = new BufferedReader(new FileReader(file));\n+\t\tchar[] buf = new char[1024];\n+\t\tint numRead = 0;\n+\t\twhile ((numRead = reader.read(buf)) != -1) {\n+\t\t\tString readData = String.valueOf(buf, 0, numRead);\n+\t\t\tfileData.append(readData);\n+\t\t\tbuf = new char[1024];\n+\t\t}\n+\t\treader.close();\n+\t\treturn fileData.toString();\n+\t}\n+\n \tprivate static ClassLoader cl() {\n \t\treturn JGitTestUtil.class.getClassLoader();\n \t}\n@@ -136,4 +154,8 @@ private static void reportDeleteFailure(final String name,\n \t\telse\n \t\t\tSystem.out.println(msg);\n \t}\n+\n+\tpublic static File generateTempDirectoryFileObject() {\n+\t\treturn new File(new File(System.getProperty(\"java.io.tmpdir\")), UUID.randomUUID().toString());\n+\t}\n }\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java\nindex 68ad488..70ce505 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java\n@@ -130,4 +130,9 @@ protected void closeAlternates(final ObjectDatabase[] alt) {\n \tpublic List<PackFile> listLocalPacks() {\n \t\treturn odb.listLocalPacks();\n \t}\n+\n+\t@Override\n+\tpublic void updateInfoCache() throws IOException {\n+\t\todb.updateInfoCache();\n+\t}\n }\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/CachedPacksInfoFileContentsGenerator.java b/org.spearce.jgit/src/org/spearce/jgit/lib/CachedPacksInfoFileContentsGenerator.java\nnew file mode 100644\nindex 0000000..6046c94\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/CachedPacksInfoFileContentsGenerator.java\n@@ -0,0 +1,63 @@\n+/*\n+ * Copyright (C) 2009, Mike Gaffney.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+package org.spearce.jgit.lib;\n+\n+import java.util.List;\n+\n+/**\n+ * This file is used to generate the contents of the file system\n+ * based pack file cache used by the dumb git-http client protocol.\n+ * @author mike\n+ */\n+public class CachedPacksInfoFileContentsGenerator {\n+\n+\tprivate List<PackFile> packs;\n+\n+\tpublic CachedPacksInfoFileContentsGenerator(List<PackFile> packs) {\n+\t\tthis.packs = packs;\n+\t}\n+\t\n+\tpublic String generateContents(){\n+\t\tStringBuilder builder = new StringBuilder();\n+\t\tfor (PackFile packFile : packs) {\n+\t\t\tbuilder.append(\"P \").append(packFile.getPackFile().getName()).append('\\n');\n+\t\t}\n+\t\tbuilder.append('\\n');\n+\t\treturn builder.toString();\n+\t}\n+\t\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java\nindex 9afea67..2d78dda 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java\n@@ -224,6 +224,9 @@\n \n \t/** Info refs folder */\n \tpublic static final String INFO_REFS = \"info/refs\";\n+\t\n+\t/** cached packs file */\n+\tpublic static final String CACHED_PACKS_FILE = \"info/packs\"; \n \n \t/** Packed refs file */\n \tpublic static final String PACKED_REFS = \"packed-refs\";\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java\nindex 722c802..5ded7bb 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java\n@@ -75,6 +75,14 @@ protected ObjectDatabase() {\n \tpublic abstract List<PackFile> listLocalPacks();\n \t\n \t/**\n+\t * Creates the caches that are typically done by \n+\t * update-server-info, namely objects/info/packs and \n+\t * info/refs\n+\t * @throws IOException \n+\t */\n+\tpublic abstract void updateInfoCache() throws IOException;\n+\t\n+\t/**\n \t * Does this database exist yet?\n \t *\n \t * @return true if this database is already created; false if the caller\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java\nindex cbe132d..f4251c1 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java\n@@ -514,4 +514,9 @@ boolean tryAgain(final long currLastModified) {\n \t\ttryAgain1();\n \t\treturn new ArrayList<PackFile>(Arrays.asList(packList.get().packs));\n \t}\n+\n+\t@Override\n+\tpublic void updateInfoCache() throws IOException {\n+\t\tnew UpdateDirectoryBasedPacksInfoCache(this.listLocalPacks(), new File(this.getDirectory(), Constants.CACHED_PACKS_FILE)).execute();\n+\t}\n }\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java\nnew file mode 100644\nindex 0000000..327bb34\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java\n@@ -0,0 +1,62 @@\n+/*\n+ * Copyright (C) 2009, Mike Gaffney.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+package org.spearce.jgit.lib;\n+\n+import java.io.File;\n+import java.io.FileOutputStream;\n+import java.io.IOException;\n+import java.util.List;\n+\n+public class UpdateDirectoryBasedPacksInfoCache {\n+\n+\tprivate List<PackFile> packsList;\n+\tprivate File infoPacksFile;\n+\n+\tpublic UpdateDirectoryBasedPacksInfoCache(List<PackFile> packsList,\n+\t\t\t\t\t\t\t\t\tFile infoPacksFile) {\n+\t\tthis.packsList = packsList;\n+\t\tthis.infoPacksFile = infoPacksFile;\n+\t}\n+\n+\tpublic void execute() throws IOException {\n+\t\tString packsContents = new CachedPacksInfoFileContentsGenerator(packsList).generateContents();\n+\t\tFileOutputStream fos = new FileOutputStream(infoPacksFile);\n+\t\tfos.write(packsContents.getBytes());\n+\t\tfos.close();\n+\t}\n+\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java\nnew file mode 100644\nindex 0000000..b6947ce\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java\n@@ -0,0 +1,26 @@\n+package org.spearce.jgit.lib;\n+\n+import java.io.File;\n+import java.io.FileOutputStream;\n+import java.io.IOException;\n+import java.util.List;\n+\n+public class UpdateDirectoryInfoCache {\n+\n+\tprivate List<PackFile> packsList;\n+\tprivate File infoPacksFile;\n+\n+\tpublic UpdateDirectoryInfoCache(List<PackFile> packsList,\n+\t\t\t\t\t\t\t\t\tFile infoPacksFile) {\n+\t\tthis.packsList = packsList;\n+\t\tthis.infoPacksFile = infoPacksFile;\n+\t}\n+\n+\tpublic void execute() throws IOException {\n+\t\tString packsContents = new CachedPacksInfoFileContentsGenerator(packsList).generateContents();\n+\t\tFileOutputStream fos = new FileOutputStream(infoPacksFile);\n+\t\tfos.write(packsContents.getBytes());\n+\t\tfos.close();\n+\t}\n+\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java\nindex eb21254..5865736 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java\n@@ -521,6 +521,16 @@ void sendString(final String s) throws IOException {\n \t\t\t}\n \n \t\t\tpostReceive.onPostReceive(this, filterCommands(Result.OK));\n+\t\t\tupdateObjectInfoCache();\n+\t\t}\n+\t}\n+\n+\tprivate void updateObjectInfoCache() {\n+\t\ttry{\n+\t\t\tgetRepository().getObjectDatabase().updateInfoCache();\n+\t\t} \n+\t\tcatch (IOException e){\n+\t\t\tsendMessage(\"error updating server info: \" + e.getMessage());\n \t\t}\n \t}\n \n-- \n1.6.4.2\n"},{"id":"123295","messageId":"1253062116-13830-5-git-send-email-mr.gaffo@gmail.com","threadId":"20959","inReplyTo":"1253062116-13830-4-git-send-email-mr.gaffo@gmail.com","subject":"[PATCH JGit 4/5] Adding in a InfoDatabase like ObjectDatabase and and implementation based upon a directory.","fromName":"","fromEmail":"mr.gaffo@gmail.com","sentAt":"2009-09-16T00:48:35Z","receivedAt":"2009-09-16T00:48:35Z","isPatch":true,"sender":{"key":"mr.gaffo@gmail.com","avatar":"https://gravatar.com/avatar/5af46a60cbd83f2ddb0c2cf4d02b91db42fd25e2ac568ff0d71f699d852ee79d?d=mp&s=160"},"body":"From: Mike Gaffney <mr.gaffo@gmail.com>\n\nSigned-off-by: Mike Gaffney <mr.gaffo@gmail.com>\n---\n .../jgit/lib/InfoDirectoryDatabaseTest.java        |   66 ++++++++++++++++++++\n .../org/spearce/jgit/lib/ObjectDirectoryTest.java  |    1 -\n .../src/org/spearce/jgit/lib/InfoDatabase.java     |   44 +++++++++++++\n .../spearce/jgit/lib/InfoDirectoryDatabase.java    |   54 ++++++++++++++++\n .../src/org/spearce/jgit/lib/Repository.java       |   11 +++\n 5 files changed, 175 insertions(+), 1 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java\n\ndiff --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\nnew file mode 100644\nindex 0000000..066473d\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java\n@@ -0,0 +1,66 @@\n+/*\n+ * Copyright (C) 2009, Mike Gaffney.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+package org.spearce.jgit.lib;\n+\n+import java.io.File;\n+\n+import org.spearce.jgit.util.JGitTestUtil;\n+\n+import junit.framework.TestCase;\n+\n+public class InfoDirectoryDatabaseTest extends TestCase {\n+\n+\tprivate File testDir;\n+\n+\t@Override\n+\tprotected void setUp() throws Exception {\n+\t\ttestDir = JGitTestUtil.generateTempDirectoryFileObject();\n+\t}\n+\n+\t@Override\n+\tprotected void tearDown() throws Exception {\n+\t\tif (testDir.exists()){\n+\t\t\tJGitTestUtil.recursiveDelete(testDir, false, getClass().getName() + \".\" + getName(), true);\n+\t\t}\n+\t}\n+\t\n+\tpublic void testCreateCreatesDirectory() throws Exception {\n+\t\tassertFalse(testDir.exists());\n+\t\tnew InfoDirectoryDatabase(testDir).create();\n+\t\tassertTrue(testDir.exists());\n+\t}\n+}\ndiff --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\nindex 204fb7c..8c1d32d 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java\n@@ -38,7 +38,6 @@\n \n import java.io.File;\n import java.io.IOException;\n-import java.util.ArrayList;\n import java.util.List;\n \n import org.spearce.jgit.util.JGitTestUtil;\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java\nnew file mode 100644\nindex 0000000..2a8d88d\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java\n@@ -0,0 +1,44 @@\n+/*\n+ * Copyright (C) 2009, Mike Gaffney.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+package org.spearce.jgit.lib;\n+\n+public abstract class InfoDatabase {\n+\n+\tpublic void create() {\n+\t}\n+\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java\nnew file mode 100644\nindex 0000000..90655e8\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java\n@@ -0,0 +1,54 @@\n+/*\n+ * Copyright (C) 2009, Mike Gaffney.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+package org.spearce.jgit.lib;\n+\n+import java.io.File;\n+\n+public class InfoDirectoryDatabase extends InfoDatabase {\n+\n+\tprivate File info;\n+\n+\tpublic InfoDirectoryDatabase(final File directory) {\n+\t\tinfo = directory;\n+\t}\n+\t\n+\t@Override\n+\tpublic void create() {\n+\t\tinfo.mkdirs();\n+\t}\n+\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\nindex 46b7804..f658b5c 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\n@@ -97,6 +97,8 @@\n \tprivate final RefDatabase refs;\n \n \tprivate final ObjectDirectory objectDatabase;\n+\t\n+\tprivate final InfoDatabase infoDatabase;\n \n \tprivate GitIndex index;\n \n@@ -116,6 +118,7 @@ public Repository(final File d) throws IOException {\n \t\tgitDir = d.getAbsoluteFile();\n \t\trefs = new RefDatabase(this);\n \t\tobjectDatabase = new ObjectDirectory(FS.resolve(gitDir, \"objects\"));\n+\t\tinfoDatabase = new InfoDirectoryDatabase(FS.resolve(gitDir, \"info\"));\n \n \t\tfinal FileBasedConfig userConfig;\n \t\tuserConfig = SystemReader.getInstance().openUserConfig();\n@@ -177,6 +180,7 @@ public void create(boolean bare) throws IOException {\n \t\tgitDir.mkdirs();\n \t\trefs.create();\n \t\tobjectDatabase.create();\n+\t\tinfoDatabase.create();\n \n \t\tnew File(gitDir, \"branches\").mkdir();\n \t\tnew File(gitDir, \"remotes\").mkdir();\n@@ -210,6 +214,13 @@ public File getObjectsDirectory() {\n \tpublic ObjectDatabase getObjectDatabase() {\n \t\treturn objectDatabase;\n \t}\n+\t\n+\t/**\n+\t * @return the info database which stores this repository's info\n+\t */\n+\tpublic InfoDatabase getInfoDatabase() {\n+\t\treturn infoDatabase;\n+\t}\n \n \t/**\n \t * @return the configuration of this repository\n-- \n1.6.4.2\n"},{"id":"123293","messageId":"1253062116-13830-6-git-send-email-mr.gaffo@gmail.com","threadId":"20959","inReplyTo":"1253062116-13830-5-git-send-email-mr.gaffo@gmail.com","subject":"[PATCH JGit 5/5] added tests for the file based info cache update and made pass","fromName":"","fromEmail":"mr.gaffo@gmail.com","sentAt":"2009-09-16T00:48:36Z","receivedAt":"2009-09-16T00:48:36Z","isPatch":true,"sender":{"key":"mr.gaffo@gmail.com","avatar":"https://gravatar.com/avatar/5af46a60cbd83f2ddb0c2cf4d02b91db42fd25e2ac568ff0d71f699d852ee79d?d=mp&s=160"},"body":"From: mike.gaffney <mike.gaffney@asolutions.com>\n\nSigned-off-by: Mike Gaffney <mr.gaffo@gmail.com>\n---\n .../CachedPacksInfoFileContentsGeneratorTest.java  |    8 ++--\n .../jgit/lib/InfoDirectoryDatabaseTest.java        |   30 ++++++++++++++++++++\n .../org/spearce/jgit/lib/ObjectDirectoryTest.java  |    4 +-\n .../src/org/spearce/jgit/lib/InfoDatabase.java     |   15 ++++++++++\n .../spearce/jgit/lib/InfoDirectoryDatabase.java    |   15 ++++++++++\n .../org/spearce/jgit/transport/ReceivePack.java    |   10 ++++++\n 6 files changed, 76 insertions(+), 6 deletions(-)\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java\nindex bea0b70..10ce9e3 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java\n@@ -63,10 +63,10 @@ public void testGettingPacksContentsMultiplePacks() throws Exception {\n \t\tpacks.add(new PackFile(TEST_IDX, TEST_PACK));\n \t\t\n \t\tStringBuilder expected = new StringBuilder();\n-\t\texpected.append(\"P \").append(TEST_PACK.getName()).append(\"\\n\");\n-\t\texpected.append(\"P \").append(TEST_PACK.getName()).append(\"\\n\");\n-\t\texpected.append(\"P \").append(TEST_PACK.getName()).append(\"\\n\");\n-\t\texpected.append(\"\\n\");\n+\t\texpected.append(\"P \").append(TEST_PACK.getName()).append('\\n');\n+\t\texpected.append(\"P \").append(TEST_PACK.getName()).append('\\n');\n+\t\texpected.append(\"P \").append(TEST_PACK.getName()).append('\\n');\n+\t\texpected.append('\\n');\n \t\t\n \t\tassertEquals(expected.toString(), new CachedPacksInfoFileContentsGenerator(packs).generateContents());\n \t}\ndiff --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\nindex 066473d..e31b883 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/InfoDirectoryDatabaseTest.java\n@@ -37,6 +37,10 @@\n package org.spearce.jgit.lib;\n \n import java.io.File;\n+import java.io.IOException;\n+import java.io.StringWriter;\n+import java.util.ArrayList;\n+import java.util.Collection;\n \n import org.spearce.jgit.util.JGitTestUtil;\n \n@@ -63,4 +67,30 @@ public void testCreateCreatesDirectory() throws Exception {\n \t\tnew InfoDirectoryDatabase(testDir).create();\n \t\tassertTrue(testDir.exists());\n \t}\n+\t\n+\tpublic void testUpdateInfoCache() throws Exception {\n+\t\tCollection<Ref> refs = new ArrayList<Ref>();\n+\t\trefs.add(new Ref(Ref.Storage.LOOSE, \"refs/heads/master\", ObjectId.fromString(\"32aae7aef7a412d62192f710f2130302997ec883\")));\n+\t\trefs.add(new Ref(Ref.Storage.LOOSE, \"refs/heads/development\", ObjectId.fromString(\"184063c9b594f8968d61a686b2f6052779551613\")));\n+\n+\t\tFile expectedFile = new File(testDir, \"refs\");\n+\t\tassertFalse(expectedFile.exists());\n+\t\t\n+\t\t\n+\t\tfinal StringWriter expectedString = new StringWriter();\n+\t\tnew RefWriter(refs) {\n+\t\t\t@Override\n+\t\t\tprotected void writeFile(String file, byte[] content) throws IOException {\n+\t\t\t\texpectedString.write(new String(content));\n+\t\t\t}\n+\t\t}.writeInfoRefs();\n+\t\t\n+\t\tInfoDirectoryDatabase out = new InfoDirectoryDatabase(testDir);\n+\t\tout.create();\n+\t\tout.updateInfoCache(refs);\n+\t\tassertTrue(expectedFile.exists());\n+\t\t\n+\t\tString actual = JGitTestUtil.readFileAsString(expectedFile);\n+\t\tassertEquals(expectedString.toString(), actual);\n+\t}\n }\ndiff --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\nindex 8c1d32d..a3f5278 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/ObjectDirectoryTest.java\n@@ -40,10 +40,10 @@\n import java.io.IOException;\n import java.util.List;\n \n-import org.spearce.jgit.util.JGitTestUtil;\n-\n import junit.framework.TestCase;\n \n+import org.spearce.jgit.util.JGitTestUtil;\n+\n public class ObjectDirectoryTest extends TestCase {\n \tprivate static final String PACK_NAME = \"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f\";\n \tprivate static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + \".pack\");\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java\nindex 2a8d88d..96a39fc 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java\n@@ -36,9 +36,24 @@\n  */\n package org.spearce.jgit.lib;\n \n+import java.io.IOException;\n+import java.util.Collection;\n+\n public abstract class InfoDatabase {\n \n+\t/**\n+\t * Create the info database\n+\t */\n \tpublic void create() {\n \t}\n \n+\t/**\n+\t * Updates the info cache typically done by update-server-info command.\n+\t * This writes THIS repository's refs out to the info/refs file.\n+\t * @param collection the collections of refs to update the info cache with\n+\t * @throws IOException for any type of failure on the local or remote \n+\t * \t\t\t\t\t   data store\n+\t */\n+\tpublic abstract void updateInfoCache(Collection<Ref> collection) throws IOException;\n+\n }\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java\nindex 90655e8..48f60d1 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java\n@@ -37,6 +37,9 @@\n package org.spearce.jgit.lib;\n \n import java.io.File;\n+import java.io.FileOutputStream;\n+import java.io.IOException;\n+import java.util.Collection;\n \n public class InfoDirectoryDatabase extends InfoDatabase {\n \n@@ -51,4 +54,16 @@ public void create() {\n \t\tinfo.mkdirs();\n \t}\n \n+\t@Override\n+\tpublic void updateInfoCache(Collection<Ref> refs) throws IOException {\n+\t\tnew RefWriter(refs) {\n+\t\t\t@Override\n+\t\t\tprotected void writeFile(String file, byte[] content) throws IOException {\n+\t\t\t\tFileOutputStream fos = new FileOutputStream(new File(info, \"refs\"));\n+\t\t\t\tfos.write(content);\n+\t\t\t\tfos.close();\n+\t\t\t}\n+\t\t}.writeInfoRefs();\n+\t}\n+\n }\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java\nindex 5865736..23277c9 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java\n@@ -522,6 +522,16 @@ void sendString(final String s) throws IOException {\n \n \t\t\tpostReceive.onPostReceive(this, filterCommands(Result.OK));\n \t\t\tupdateObjectInfoCache();\n+\t\t\tupdateInfoRefsCache();\n+\t\t}\n+\t}\n+\n+\tprivate void updateInfoRefsCache() {\n+\t\ttry{\n+\t\t\tgetRepository().getInfoDatabase().updateInfoCache(getRepository().getAllRefs().values());\n+\t\t}\n+\t\tcatch (IOException e){\n+\t\t\tsendMessage(\"error updating info/refs: \" + e.getMessage());\n \t\t}\n \t}\n \n-- \n1.6.4.2\n"},{"id":"123595","messageId":"20090921193049.GL14660@spearce.org","threadId":"20959","inReplyTo":"1253062116-13830-2-git-send-email-mr.gaffo@gmail.com","subject":"Re: [PATCH JGit 1/5] adding tests for ObjectDirectory","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-09-21T19:30:49Z","receivedAt":"2009-09-21T19:30:49Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"mr.gaffo@gmail.com wrote:\n> 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\n> +\tprivate File testDir;\n> +\n> +\t@Override\n> +\tprotected void setUp() throws Exception {\n> +\t\ttestDir = new File(new File(System.getProperty(\"java.io.tmpdir\")), UUID.randomUUID().toString());\n> +\t}\n\nCan't we use the same logic we use in RepositoryTestCase to create\nthe temporary directory for this test?  I would rather keep the\ntemporary space under target/ when testing under Maven, as it\nmakes it far easier to clean up the directory.  Plus we know we\nhave sufficient write space there.\n\n> +\t@Override\n> +\tprotected void tearDown() throws Exception {\n> +\t\tif (testDir.exists()){\n\nStyle nit: Space between ) and {\n\n> +\tpublic void testExistsWithNonExistantDirectory() throws Exception {\n> +\t\tassertFalse(new ObjectDirectory(new File(\"/some/nonexistant/file\")).exists());\n\nPlease create a path name below your testDir which you know won't\nexist.  I don't want this test to rely upon the fact that some\nabsolute path doesn't exist that is outside of our namespace control.\n\n> +\tprivate void createTestDir(){\n\nYou use this method once, inline it inside\ntestExistsWithExistingDirectory().\n\nOtherwise, the test case is OK, but is still quite sparse with\nregards to functionality of the class being tested.  Was it your\nintention to only cover the most basic parts at this time?  Its more\ncoverage than we have now, so I'm happy, but just wanted to point\nout it certainly isn't complete (e.g. no pack support).\n\n-- \nShawn.\n"},{"id":"123596","messageId":"20090921194035.GM14660@spearce.org","threadId":"20959","inReplyTo":"1253062116-13830-3-git-send-email-mr.gaffo@gmail.com","subject":"Re: [PATCH JGit 2/5] Create abstract method on ObjectDatabase for accessing the list of local pack files.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-09-21T19:40:35Z","receivedAt":"2009-09-21T19:40:35Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"mr.gaffo@gmail.com wrote:\n> 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\n> +\tpublic void testListLocalPacksWhenThereIsAPack() throws Exception {\n> +\t\tcreateTestDir();\n> +\t\tFile packsDir = new File(testDir, \"pack\");\n> +\t\tpacksDir.mkdirs();\n\nWhy not allow the ObjectDirectory code to create the directory\nbefore copying the pack into it?\n\n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java\n> +\t/**\n> +\t * The list of Packs THIS repo contains\n\nDon't you mean the list of packs this object database contains?\nAn object database may not be a git repository.  Though yes, the\ncommon case is that it is a repository.\n\n> +\t * @return List<PackFile> of package names contained in this repo. \n> +\t * \t\t   Should be an empty list if there are none.\n> +\t */\n> +\tpublic abstract List<PackFile> listLocalPacks();\n\nI think you should define this to be an unmodifiable list, not just\nany list.  Its sad that the Java type system didn't support this\nidea back when they added the new collections APIs.\n\n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java\n> +\t@Override\n> +\tpublic List<PackFile> listLocalPacks() {\n> +\t\ttryAgain1();\n> +\t\treturn new ArrayList<PackFile>(Arrays.asList(packList.get().packs));\n\nInstead of copying, why not return an unmodifiableList wrapped\naround the array?  PackList will never modify its internal array.\n\n-- \nShawn.\n"},{"id":"123599","messageId":"4AB7D950.9000600@gmail.com","threadId":"20959","inReplyTo":"20090921194035.GM14660@spearce.org","subject":"Re: [PATCH JGit 2/5] Create abstract method on ObjectDatabase for accessing the list of local pack files.","fromName":"Michael Gaffney","fromEmail":"mr.gaffo@gmail.com","sentAt":"2009-09-21T19:51:44Z","receivedAt":"2009-09-21T19:51:44Z","isPatch":true,"sender":{"key":"mr.gaffo@gmail.com","avatar":"https://gravatar.com/avatar/5af46a60cbd83f2ddb0c2cf4d02b91db42fd25e2ac568ff0d71f699d852ee79d?d=mp&s=160"},"body":"Shawn O. Pearce wrote:\n> Why not allow the ObjectDirectory code to create the directory\n> before copying the pack into it?\n\nGood point, this was one of the first tests I did before I got to that \npart of ObjectDirectory. Will fix.\n\n> Don't you mean the list of packs this object database contains?\n> An object database may not be a git repository.  Though yes, the\n> common case is that it is a repository.\n\nWhat's the difference in terminology? Not aruging, just wanting to know \nwhat we're calling a repo and what we're not so that I use it correctly. \nWill fix.\n\n>> +\tpublic abstract List<PackFile> listLocalPacks();\n> \n> I think you should define this to be an unmodifiable list, not just\n> any list.  Its sad that the Java type system didn't support this\n> idea back when they added the new collections APIs.\n\nShould it be a collection as well instead of a list; what would you \nspecifically suggest?\n\n> Instead of copying, why not return an unmodifiableList wrapped\n> around the array?  PackList will never modify its internal array.\n\nSame as above\n\n\n-Mike\n"},{"id":"124390","messageId":"20091008170019.GF9261@spearce.org","threadId":"20959","inReplyTo":"1253062116-13830-4-git-send-email-mr.gaffo@gmail.com","subject":"Re: [PATCH JGit 3/5] Implemented directory based info cache for objects/info/packs.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-08T17:00:19Z","receivedAt":"2009-10-08T17:00:19Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"mr.gaffo@gmail.com wrote:\n> Add abstract method for updating the object db's info cache to directory.\n> \n> Implemented passthrough on Alternate for the update of infocache.\n> \n> Added utility that generates the contents of the objects/info/packs\n> file as a string from a list of PackFiles.\n> \n> Added implementation from ObjectDirectory on down\n> for creating the info cache.\n> \n> Added test for creating the info cache\n\nReading this message gave me the funny feeling that I'm going to\nsee a lot of unrelated code mashed into one patch.  There doesn't\nseem to be a general theme to the commit, at least as far as the\nmessage is concerned.\n\n[a bit later...] After reading the code itself, I agree with the\noriginal guess on the commit message, there is too much happening\nin this one patch that is unrelated, and there are several problems\nlurking that are harder to spot because its a mash of changes.\nPlease try to break it down to more focused commits.\n \n> diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java\n> new file mode 100644\n> index 0000000..bea0b70\n> --- /dev/null\n> +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java\n> @@ -0,0 +1,74 @@\n\nFYI, our new package space is org.eclipse.jgit and any new changes\nneed to take that into account.\n\n> + * - Neither the name of the Git Development Community nor the\n\nAlso FYI, since our move to the Eclipse Foundation the generic term\n\"Git Development Community\" has been replaced in the license header\nby \"Eclipse Foundation, Inc.\", otherwise the license header remains\nas-is and copyright is still attributed to the contributor.\n\n> +public class CachedPacksInfoFileContentsGeneratorTest extends TestCase {\n...\n> +\tpublic void testGettingPacksContentsMultiplePacks() throws Exception {\n> +\t\tList<PackFile> packs = new ArrayList<PackFile>();\n> +\t\tpacks.add(new PackFile(TEST_IDX, TEST_PACK));\n> +\t\tpacks.add(new PackFile(TEST_IDX, TEST_PACK));\n> +\t\tpacks.add(new PackFile(TEST_IDX, TEST_PACK));\n\nI think we should be testing multiple names here, to ensure the\ngenerator didn't do something stupid like reuse the same array index\nfor pulling the name while looping for the size of the input list.\n\n> 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\n> @@ -54,9 +54,9 @@\n>  \n>  \t@Override\n>  \tprotected void setUp() throws Exception {\n> -\t\ttestDir = new File(new File(System.getProperty(\"java.io.tmpdir\")), UUID.randomUUID().toString());\n> +\t\ttestDir = JGitTestUtil.generateTempDirectoryFileObject();\n\nYea, I'm confused about this hunk.  It isn't strictly necessary\nfor the new feature this commit is adding.  Pull this into its own\ncommit, before the new feature, so you can take advantage of the\nrefactoring in your new tests, but you also don't muddle the new\nfeature addition with old code refactoring.\n\n> 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\n> @@ -74,7 +76,8 @@ public static File getTestResourceFile(final String fileName) {\n>  \t\t}\n>  \t}\n>  \n> -\tpublic static void copyFile(final File fromFile, final File toFile) throws IOException {\n> +\tpublic static void copyFile(final File fromFile, final File toFile)\n> +\t\t\tthrows IOException {\n>  \t\tInputStream in = new FileInputStream(fromFile);\n>  \t\tOutputStream out = new FileOutputStream(toFile);\n\nUnnecessary reformatting hunk; we try to avoid these when possible.\n\n> @@ -87,6 +90,21 @@ public static void copyFile(final File fromFile, final File toFile) throws IOExc\n>  \t\tout.close();\n>  \t}\n>  \n> +\tpublic static String readFileAsString(final File file)\n> +\t\t\tthrows java.io.IOException {\n\nThis method already exists in some form in the RepositoryTest class.\nCan we instead make a commit to refactor it out of there here?\n\n> +\t\tStringBuilder fileData = new StringBuilder(1000);\n> +\t\tBufferedReader reader = new BufferedReader(new FileReader(file));\n\nWe should be more specific about our encoding and not rely on the\nplatform default.\n\n> +\t\tchar[] buf = new char[1024];\n> +\t\tint numRead = 0;\n> +\t\twhile ((numRead = reader.read(buf)) != -1) {\n> +\t\t\tString readData = String.valueOf(buf, 0, numRead);\n> +\t\t\tfileData.append(readData);\n> +\t\t\tbuf = new char[1024];\n\nThere is no need to reallocate the buffer, String.valueOf is required\nto copy the array to ensure the returned String is immutable.\nWorse, you don't need to convert the char array to string, there is\na method on StringBuilder to append a char[] taking char[],int,int.\n\n> @@ -136,4 +154,8 @@ private static void reportDeleteFailure(final String name,\n> +\n> +\tpublic static File generateTempDirectoryFileObject() {\n> +\t\treturn new File(new File(System.getProperty(\"java.io.tmpdir\")), UUID.randomUUID().toString());\n> +\t}\n\nPlease generate temporary directories under the same area that\nRepositoryTest produces them, which makes it easier to cleanup,\nand ensures we aren't treading out of our build area.\n\n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java\n> index 68ad488..70ce505 100644\n> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java\n> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/AlternateRepositoryDatabase.java\n> @@ -130,4 +130,9 @@ protected void closeAlternates(final ObjectDatabase[] alt) {\n>  \tpublic List<PackFile> listLocalPacks() {\n>  \t\treturn odb.listLocalPacks();\n>  \t}\n> +\n> +\t@Override\n> +\tpublic void updateInfoCache() throws IOException {\n> +\t\todb.updateInfoCache();\n> +\t}\n>  }\n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/CachedPacksInfoFileContentsGenerator.java b/org.spearce.jgit/src/org/spearce/jgit/lib/CachedPacksInfoFileContentsGenerator.java\n> + * This file is used to generate the contents of the file system\n> + * based pack file cache used by the dumb git-http client protocol.\n> + * @author mike\n\nWe don't record @author annotations.\n\n> +public class CachedPacksInfoFileContentsGenerator {\n> +\n> +\tprivate List<PackFile> packs;\n> +\n> +\tpublic CachedPacksInfoFileContentsGenerator(List<PackFile> packs) {\n> +\t\tthis.packs = packs;\n> +\t}\n> +\t\n> +\tpublic String generateContents(){\n\nStyle nit: space between () and {.\n\nI also wonder about the value of an instance for this class, if\nall it does is produce one return value as a string, why not just\nuse a static method?\n\n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java\n> index 9afea67..2d78dda 100644\n> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java\n> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Constants.java\n> @@ -224,6 +224,9 @@\n>  \n>  \t/** Info refs folder */\n>  \tpublic static final String INFO_REFS = \"info/refs\";\n> +\t\n> +\t/** cached packs file */\n> +\tpublic static final String CACHED_PACKS_FILE = \"info/packs\"; \n\nI think you should denote in the comment that this is relative to\nthe objects directory, and not the repository.  The INFO_REFS file\nright above you is relative to the repository and something looks\nwrong seeing these together in context.\n  \n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java\n> index 722c802..5ded7bb 100644\n> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java\n> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDatabase.java\n> @@ -75,6 +75,14 @@ protected ObjectDatabase() {\n>  \tpublic abstract List<PackFile> listLocalPacks();\n>  \t\n>  \t/**\n> +\t * Creates the caches that are typically done by \n> +\t * update-server-info, namely objects/info/packs and \n> +\t * info/refs\n\nWhy is the object database updating info/refs?  The info/refs file\nhas nothing to do with the raw object storage.\n\n> +\t * @throws IOException \n> +\t */\n> +\tpublic abstract void updateInfoCache() throws IOException;\n\nI'm not sure I'm happy with this being on ObjectDatabase but there\nmay not be any other choice.  We'd like to eventually have other\ntypes of ObjectDatabase that don't even store packs, in such a\ndatabase updating the info cache makes no sense.  Asking them to\nimplement the operation is silly.  But... we have no other way to\neasily signal the database that it should do this update.\n\nHmmph.  I wonder if it might be better to configure the\nObjectDirectory at creation time to automatically maintain\nthe info/packs file during openPack, and put this method on\nObjectDirectory for explicit invocation in case someone has made\nedits outside of JGit and wants to force the cache to be current\nagain.\n\nI'm not sold either way yet.  I'm still open on the approach.\n\n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java\n> index cbe132d..f4251c1 100644\n> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java\n> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectDirectory.java\n> @@ -514,4 +514,9 @@ boolean tryAgain(final long currLastModified) {\n>  \t\ttryAgain1();\n>  \t\treturn new ArrayList<PackFile>(Arrays.asList(packList.get().packs));\n>  \t}\n> +\n> +\t@Override\n> +\tpublic void updateInfoCache() throws IOException {\n> +\t\tnew UpdateDirectoryBasedPacksInfoCache(this.listLocalPacks(), new File(this.getDirectory(), Constants.CACHED_PACKS_FILE)).execute();\n\nStyle-nit: Line is far too long, we try to wrap at around 80\ncharacters but sometimes allow a line to go longer if its only\nlonger by 1 or 2 characters and the wrapped result would be harder\nto read than the unwrapped result.  This is out at 140, too many\nover the limit.\n\n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryBasedPacksInfoCache.java\n> +public class UpdateDirectoryBasedPacksInfoCache {\n> +\tpublic void execute() throws IOException {\n> +\t\tString packsContents = new CachedPacksInfoFileContentsGenerator(packsList).generateContents();\n> +\t\tFileOutputStream fos = new FileOutputStream(infoPacksFile);\n> +\t\tfos.write(packsContents.getBytes());\n> +\t\tfos.close();\n\nI'm not sure why this 4 line method requires its own top level\nclass and being able to create an instance.  Code bloat?\n\nYou need to specify the character encoding here and not rely on\nthe platform default.\n\nI'm not sure how C Git handles this update, but we probably should be\nsafer about it and use the LockFile class so the update is going to\nbe transactional.  Here you are truncating a live file, which means\nreaders could see an empty content if they happen to request the file\nfrom the web server at the wrong moment.  LockFile does the writing\nto a temporary file and then renames it over, which on a POSIX file\nsystem means there is no way someone can see a partial update.\n\n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UpdateDirectoryInfoCache.java\n> +public class UpdateDirectoryInfoCache {\n> +\tpublic void execute() throws IOException {\n> +\t\tString packsContents = new CachedPacksInfoFileContentsGenerator(packsList).generateContents();\n> +\t\tFileOutputStream fos = new FileOutputStream(infoPacksFile);\n> +\t\tfos.write(packsContents.getBytes());\n> +\t\tfos.close();\n\nUh, isn't this the same as UpdateDirectoryBasedPacksInfoCache?\nTwo top level classes for a 4 line method?\n\n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/ReceivePack.java\n> +\tprivate void updateObjectInfoCache() {\n> +\t\ttry{\n\nStyle-nit: space after try\n\n> +\t\t\tgetRepository().getObjectDatabase().updateInfoCache();\n> +\t\t} \n> +\t\tcatch (IOException e){\n\nStyle-nit: space between ) and {\n\n> +\t\t\tsendMessage(\"error updating server info: \" + e.getMessage());\n\n-- \nShawn.\n"},{"id":"124393","messageId":"20091008170554.GG9261@spearce.org","threadId":"20959","inReplyTo":"1253062116-13830-5-git-send-email-mr.gaffo@gmail.com","subject":"Re: [PATCH JGit 4/5] Adding in a InfoDatabase like ObjectDatabase and and implementation based upon a directory.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-08T17:05:54Z","receivedAt":"2009-10-08T17:05:54Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"mr.gaffo@gmail.com wrote:\n> From: Mike Gaffney <mr.gaffo@gmail.com>\n> Subject: Re: [PATCH JGit 4/5] Adding in a InfoDatabase like ObjectDatabase\n> and and implementation based upon a directory.\n\nTypo on \"and and\".\n\nWe should have a bit more justification for this change, the subject\nsounds aggressive, but there's no rationle for 175 insertions.\nYou and I both can make a reaosnable guess about why, but not\neveryone knows the code or what you are trying to accomplish.\n\n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDatabase.java\n> +public abstract class InfoDatabase {\n> +\n> +\tpublic void create() {\n> +\t}\n\nNew public code should have Javadoc to document its purpose and\nusage, especially for an abstract class that needs to be implemented.\n\nBut, that said, I think this direction is of dubious value.  What we\nreally care about is having the contents of the current RefDatabase\n(that is, packed-refs and files under refs/) written into info/refs.\n\nThere really isn't anything else of value under GIT_DIR/info, other\nthan GIT_DIR/info/exclude, but that is related to ignore processing\nfor a repository with a working directory and isn't something that\na bare repository on a server ever cares about.\n\nIMHO, updating GIT_DIR/info/refs should be part of RefDatabase,\nnot some new InfoDirectoryDatabase class.\n\n-- \nShawn.\n"},{"id":"124394","messageId":"20091008171245.GH9261@spearce.org","threadId":"20959","inReplyTo":"1253062116-13830-6-git-send-email-mr.gaffo@gmail.com","subject":"Re: [PATCH JGit 5/5] added tests for the file based info cache update and made pass","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-10-08T17:12:45Z","receivedAt":"2009-10-08T17:12:45Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"mr.gaffo@gmail.com wrote:\n> From: mike.gaffney <mike.gaffney@asolutions.com>\n> Subject: Re: [PATCH JGit 5/5] added tests for the file based info cache\n>\tupdate and made pass\n\n\"and made pass\" is the sneaky way of saying \"and I actually\nimplemented what I should have implemented in the prior commit,\nbut didn't because ...\" ?\n \n> diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java\n> index bea0b70..10ce9e3 100644\n> --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java\n> +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/CachedPacksInfoFileContentsGeneratorTest.java\n> @@ -63,10 +63,10 @@ public void testGettingPacksContentsMultiplePacks() throws Exception {\n>  \t\tpacks.add(new PackFile(TEST_IDX, TEST_PACK));\n>  \t\t\n>  \t\tStringBuilder expected = new StringBuilder();\n> -\t\texpected.append(\"P \").append(TEST_PACK.getName()).append(\"\\n\");\n> -\t\texpected.append(\"P \").append(TEST_PACK.getName()).append(\"\\n\");\n> -\t\texpected.append(\"P \").append(TEST_PACK.getName()).append(\"\\n\");\n> -\t\texpected.append(\"\\n\");\n> +\t\texpected.append(\"P \").append(TEST_PACK.getName()).append('\\n');\n> +\t\texpected.append(\"P \").append(TEST_PACK.getName()).append('\\n');\n> +\t\texpected.append(\"P \").append(TEST_PACK.getName()).append('\\n');\n> +\t\texpected.append('\\n');\n\nThis should be squashed to the patch that introduced the code,\nnot be twiddled in something that is completely unrelated to it.\n  \t\t\n> 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\n> +\tpublic void testUpdateInfoCache() throws Exception {\n> +\t\tCollection<Ref> refs = new ArrayList<Ref>();\n> +\t\trefs.add(new Ref(Ref.Storage.LOOSE, \"refs/heads/master\", ObjectId.fromString(\"32aae7aef7a412d62192f710f2130302997ec883\")));\n> +\t\trefs.add(new Ref(Ref.Storage.LOOSE, \"refs/heads/development\", ObjectId.fromString(\"184063c9b594f8968d61a686b2f6052779551613\")));\n> +\n> +\t\tFile expectedFile = new File(testDir, \"refs\");\n> +\t\tassertFalse(expectedFile.exists());\n> +\t\t\n> +\t\t\n> +\t\tfinal StringWriter expectedString = new StringWriter();\n> +\t\tnew RefWriter(refs) {\n> +\t\t\t@Override\n> +\t\t\tprotected void writeFile(String file, byte[] content) throws IOException {\n> +\t\t\t\texpectedString.write(new String(content));\n> +\t\t\t}\n> +\t\t}.writeInfoRefs();\n\nThis feels a bit too much like testing the formatting code by\nrelying on the formatting code to produce the correct output.\n\nIts a 2 line file with a very well known format that cannot change\nwithout breaking every Git HTTP client out in the wild.  We will\nnot break those clients anytime in the next few years.  You have\nthe data hardcoded above *anyway*, hardcode the expected result\nhere to ensure we formatted it right.\n\nOh, and IIRC order doesn't matter in the file but I think almost\neveryone assumes the order is as per git ls-remote, which matches the\norder produced by RefComparator.  Which means you want to assert that\ndevelopment comes before master, and that tags come before heads.\n\nAlso, we need to assert that the peeled information for a tag appears\nin the file.  So you need a tag ref with a peeled ObjectId available.\n\n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/InfoDirectoryDatabase.java\n> @@ -51,4 +54,16 @@ public void create() {\n>  \t\tinfo.mkdirs();\n>  \t}\n>  \n> +\t@Override\n> +\tpublic void updateInfoCache(Collection<Ref> refs) throws IOException {\n> +\t\tnew RefWriter(refs) {\n> +\t\t\t@Override\n> +\t\t\tprotected void writeFile(String file, byte[] content) throws IOException {\n> +\t\t\t\tFileOutputStream fos = new FileOutputStream(new File(info, \"refs\"));\n> +\t\t\t\tfos.write(content);\n> +\t\t\t\tfos.close();\n\nI think you need to use a LockFile to avoid races between readers\nand writers.\n\n-- \nShawn.\n"}]}