[PATCH JGit 04/19] added utility that generates the contents of the objects/info/packs file as a string from a list of PackFiles

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: mike.gaffney <mike.gaffney@xxxxxxxxxxxxxx>

---
 .../jgit/lib/PacksFileContentsCreatorTest.java     |   37 ++++++++++++++++++++
 .../spearce/jgit/lib/PacksFileContentsCreator.java |   21 +++++++++++
 2 files changed, 58 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java
new file mode 100644
index 0000000..ef28a26
--- /dev/null
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PacksFileContentsCreatorTest.java
@@ -0,0 +1,37 @@
+package org.spearce.jgit.lib;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.spearce.jgit.util.JGitTestUtil;
+
+import junit.framework.TestCase;
+
+public class PacksFileContentsCreatorTest extends TestCase {
+	private static final String PACK_NAME = "pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f";
+	private static final File TEST_PACK = JGitTestUtil.getTestResourceFile(PACK_NAME + ".pack");
+	private static final File TEST_IDX = JGitTestUtil.getTestResourceFile(PACK_NAME + ".idx");
+
+	public void testGettingPacksContentsSinglePack() throws Exception {
+		List<PackFile> packs = new ArrayList<PackFile>();
+		packs.add(new PackFile(TEST_IDX, TEST_PACK));
+		
+		assertEquals("P " + TEST_PACK.getName() + '\r', new PacksFileContentsCreator(packs).toString());
+	}
+	
+	public void testGettingPacksContentsMultiplePacks() throws Exception {
+		List<PackFile> packs = new ArrayList<PackFile>();
+		packs.add(new PackFile(TEST_IDX, TEST_PACK));
+		packs.add(new PackFile(TEST_IDX, TEST_PACK));
+		packs.add(new PackFile(TEST_IDX, TEST_PACK));
+		
+		StringBuilder expected = new StringBuilder();
+		expected.append("P ").append(TEST_PACK.getName()).append("\r");
+		expected.append("P ").append(TEST_PACK.getName()).append("\r");
+		expected.append("P ").append(TEST_PACK.getName()).append("\r");
+		
+		assertEquals(expected.toString(), new PacksFileContentsCreator(packs).toString());
+	}
+	
+}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java b/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java
new file mode 100644
index 0000000..3dd0418
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/PacksFileContentsCreator.java
@@ -0,0 +1,21 @@
+package org.spearce.jgit.lib;
+
+import java.util.List;
+
+public class PacksFileContentsCreator {
+
+	private List<PackFile> packs;
+
+	public PacksFileContentsCreator(List<PackFile> packs) {
+		this.packs = packs;
+	}
+	
+	public String toString(){
+		StringBuilder builder = new StringBuilder();
+		for (PackFile packFile : packs) {
+			builder.append("P ").append(packFile.getPackFile().getName()).append('\r');
+		}
+		return builder.toString();
+	}
+
+}
-- 
1.6.4.2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]