summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorJonathan Nieder2013-05-23 19:53:57 (EDT)
committer Jonathan Nieder2013-05-23 21:09:13 (EDT)
commitcfc15dd9dce2252baad9dc8ce0828203a205c2cf (patch)
treeec76d96562d1ff5c864f20169a79ea5268f3ef3a
parentd8177d6e195fad752de69f9bdeacbf6f6e004d2b (diff)
downloadjgit-cfc15dd9dce2252baad9dc8ce0828203a205c2cf.zip
jgit-cfc15dd9dce2252baad9dc8ce0828203a205c2cf.tar.gz
jgit-cfc15dd9dce2252baad9dc8ce0828203a205c2cf.tar.bz2
Drop dependency by ArchiveCommand.Format interface on commons-compressrefs/changes/62/12562/4
Otherwise, anyone trying to implement a new format would have to depend on commons-compress, even if using a different underlying library to write the archive. Change-Id: I301a1997e3b48aa7e32d693fd8f4b2d436c9b3a7
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ArchiveCommand.java41
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/TarFormat.java2
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ZipFormat.java2
3 files changed, 27 insertions, 18 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ArchiveCommand.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ArchiveCommand.java
index ad1daeb..437c613 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ArchiveCommand.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ArchiveCommand.java
@@ -42,13 +42,13 @@
*/
package org.eclipse.jgit.pgm.archive;
+import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;
import java.text.MessageFormat;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.GitCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
@@ -103,7 +103,7 @@ public class ArchiveCommand extends GitCommand<OutputStream> {
*
* Usage:
* Repository repo = git.getRepository();
- * ArchiveOutputStream out = format.createArchiveOutputStream(System.out);
+ * T out = format.createArchiveOutputStream(System.out);
* try {
* for (...) {
* format.putEntry(out, path, mode, repo.open(objectId));
@@ -112,9 +112,9 @@ public class ArchiveCommand extends GitCommand<OutputStream> {
* out.close();
* }
*/
- public static interface Format {
- ArchiveOutputStream createArchiveOutputStream(OutputStream s);
- void putEntry(ArchiveOutputStream out, String path, FileMode mode,
+ public static interface Format<T extends Closeable> {
+ T createArchiveOutputStream(OutputStream s);
+ void putEntry(T out, String path, FileMode mode,
ObjectLoader loader) throws IOException;
}
@@ -143,16 +143,20 @@ public class ArchiveCommand extends GitCommand<OutputStream> {
}
}
- private static final ConcurrentMap<String, Format> formats =
- new ConcurrentHashMap<String, Format>();
+ /**
+ * Available archival formats (corresponding to values for
+ * the --format= option)
+ */
+ private static final ConcurrentMap<String, Format<?>> formats =
+ new ConcurrentHashMap<String, Format<?>>();
static {
formats.put("zip", new ZipFormat());
formats.put("tar", new TarFormat());
}
- private static Format lookupFormat(String formatName) throws UnsupportedFormatException {
- Format fmt = formats.get(formatName);
+ private static Format<?> lookupFormat(String formatName) throws UnsupportedFormatException {
+ Format<?> fmt = formats.get(formatName);
if (fmt == null)
throw new UnsupportedFormatException(formatName);
return fmt;
@@ -180,14 +184,10 @@ public class ArchiveCommand extends GitCommand<OutputStream> {
walk.release();
}
- /**
- * @return the stream to which the archive has been written
- */
- @Override
- public OutputStream call() throws GitAPIException {
+ private <T extends Closeable>
+ OutputStream writeArchive(Format<T> fmt) throws GitAPIException {
final MutableObjectId idBuf = new MutableObjectId();
- final Format fmt = lookupFormat(format);
- final ArchiveOutputStream outa = fmt.createArchiveOutputStream(out);
+ final T outa = fmt.createArchiveOutputStream(out);
final ObjectReader reader = walk.getObjectReader();
try {
@@ -218,6 +218,15 @@ public class ArchiveCommand extends GitCommand<OutputStream> {
}
/**
+ * @return the stream to which the archive has been written
+ */
+ @Override
+ public OutputStream call() throws GitAPIException {
+ final Format<?> fmt = lookupFormat(format);
+ return writeArchive(fmt);
+ }
+
+ /**
* @param tree
* the tag, commit, or tree object to produce an archive for
* @return this
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/TarFormat.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/TarFormat.java
index a0bbd52..5225259 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/TarFormat.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/TarFormat.java
@@ -52,7 +52,7 @@ import org.apache.commons.compress.archivers.tar.TarConstants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectLoader;
-class TarFormat implements ArchiveCommand.Format {
+class TarFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
public ArchiveOutputStream createArchiveOutputStream(OutputStream s) {
return new TarArchiveOutputStream(s);
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ZipFormat.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ZipFormat.java
index a85ae3b..d264161 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ZipFormat.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/archive/ZipFormat.java
@@ -51,7 +51,7 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectLoader;
-class ZipFormat implements ArchiveCommand.Format {
+class ZipFormat implements ArchiveCommand.Format<ArchiveOutputStream> {
public ArchiveOutputStream createArchiveOutputStream(OutputStream s) {
return new ZipArchiveOutputStream(s);
}