From: mr.gaffo@gmail.com
To: git@vger.kernel.org
Cc: "mike.gaffney" <mike.gaffney@asolutions.com>,
Mike Gaffney <mr.gaffo@gmail.com>
Subject: [PATCH JGit 2/5] Create abstract method on ObjectDatabase for accessing the list of local pack files.
Date: Tue, 15 Sep 2009 19:48:33 -0500 [thread overview]
Message-ID: <1253062116-13830-3-git-send-email-mr.gaffo@gmail.com> (raw)
In-Reply-To: <1253062116-13830-2-git-send-email-mr.gaffo@gmail.com>
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.
Signed-off-by: Mike Gaffney <mr.gaffo@gmail.com>
---
.../org/spearce/jgit/lib/ObjectDirectoryTest.java | 22 ++++++++++++++++++++
.../tst/org/spearce/jgit/util/JGitTestUtil.java | 21 ++++++++++++++++++-
.../jgit/lib/AlternateRepositoryDatabase.java | 6 +++++
.../src/org/spearce/jgit/lib/ObjectDatabase.java | 11 +++++++++-
.../src/org/spearce/jgit/lib/ObjectDirectory.java | 6 +++++
5 files changed, 64 insertions(+), 2 deletions(-)
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 5b1fc0f..c27580f 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
@@ -38,6 +38,7 @@
import java.io.File;
import java.io.IOException;
+import java.util.List;
import java.util.UUID;
import org.spearce.jgit.util.JGitTestUtil;
@@ -45,6 +46,9 @@
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;
@@ -97,6 +101,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());
+ }
+
private void createTestDir(){
if (!testDir.mkdir()){
fail("unable to create test directory");
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 446c674..785922a 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;
@@ -63,11 +69,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/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..cbe132d 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,10 @@ boolean tryAgain(final long currLastModified) {
return true;
}
}
+
+ @Override
+ public List<PackFile> listLocalPacks() {
+ tryAgain1();
+ return new ArrayList<PackFile>(Arrays.asList(packList.get().packs));
+ }
}
--
1.6.4.2
next prev parent reply other threads:[~2009-09-16 0:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-16 0:48 [PATCH JGit] Adding update-server-info functionality try2 mr.gaffo
2009-09-16 0:48 ` [PATCH JGit 1/5] adding tests for ObjectDirectory mr.gaffo
2009-09-16 0:48 ` mr.gaffo [this message]
2009-09-16 0:48 ` [PATCH JGit 3/5] Implemented directory based info cache for objects/info/packs mr.gaffo
2009-09-16 0:48 ` [PATCH JGit 4/5] Adding in a InfoDatabase like ObjectDatabase and and implementation based upon a directory mr.gaffo
2009-09-16 0:48 ` [PATCH JGit 5/5] added tests for the file based info cache update and made pass mr.gaffo
2009-10-08 17:12 ` Shawn O. Pearce
2009-10-08 17:05 ` [PATCH JGit 4/5] Adding in a InfoDatabase like ObjectDatabase and and implementation based upon a directory Shawn O. Pearce
2009-10-08 17:00 ` [PATCH JGit 3/5] Implemented directory based info cache for objects/info/packs Shawn O. Pearce
2009-09-21 19:40 ` [PATCH JGit 2/5] Create abstract method on ObjectDatabase for accessing the list of local pack files Shawn O. Pearce
2009-09-21 19:51 ` Michael Gaffney
2009-09-21 19:30 ` [PATCH JGit 1/5] adding tests for ObjectDirectory Shawn O. Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1253062116-13830-3-git-send-email-mr.gaffo@gmail.com \
--to=mr.gaffo@gmail.com \
--cc=git@vger.kernel.org \
--cc=mike.gaffney@asolutions.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).