aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Nieder2012-12-03 19:06:48 (EST)
committerJonathan Nieder2012-12-04 18:36:32 (EST)
commit345ab401ce27e9d4cb4002edd7f8e732b5e2e6fc (patch)
tree724e9ed6a678ad78790b20c3b9cb5ecaece5c2ac
parent7123cbf470ea2fa39379a4d914f0933063bbbdfe (diff)
downloadjgit-345ab401ce27e9d4cb4002edd7f8e732b5e2e6fc.zip
jgit-345ab401ce27e9d4cb4002edd7f8e732b5e2e6fc.tar.gz
jgit-345ab401ce27e9d4cb4002edd7f8e732b5e2e6fc.tar.bz2
archive: Add --format option that switches between formatsrefs/changes/17/9017/3
Prepare for .tar support. Change-Id: Ieb07702da1a54b41ae764fbb425f70826907b593 Improved-by: Shawn O. Pearce <spearce@spearce.org>
-rw-r--r--org.eclipse.jgit.pgm/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties2
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java79
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java1
4 files changed, 66 insertions, 19 deletions
diff --git a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF
index 57b59af..247f93c 100644
--- a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF
@@ -6,7 +6,8 @@ Bundle-Version: 2.2.0.qualifier
Bundle-Vendor: %provider_name
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Import-Package: org.apache.commons.compress.archivers.zip;version="[1.3,2.0)",
+Import-Package: org.apache.commons.compress.archivers;version="[1.3,2.0)",
+ org.apache.commons.compress.archivers.zip;version="[1.3,2.0)",
org.eclipse.jgit.api;version="[2.2.0,2.3.0)",
org.eclipse.jgit.api.errors;version="[2.2.0,2.3.0)",
org.eclipse.jgit.awtui;version="[2.2.0,2.3.0)",
diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
index 2afaa12..fe70e71 100644
--- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
+++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties
@@ -71,6 +71,7 @@ mergeMadeBy=Merge made by the ''{0}'' strategy.
mergedSquashed=Squash commit -- not updating HEAD\nAutomatic merge went well; stopped before committing as requested
metaVar_DAG=DAG
metaVar_KEY=KEY
+metaVar_archiveFormat=format
metaVar_arg=ARG
metaVar_author=AUTHOR
metaVar_base=base
@@ -196,6 +197,7 @@ usage_addFileContentsToTheIndex=Add file contents to the index
usage_alterTheDetailShown=alter the detail shown
usage_approveDestructionOfRepository=approve destruction of repository
usage_archive=zip up files from the named tree
+usage_archiveFormat=archive format. Currently supported formats: 'zip'
usage_blameLongRevision=show long revision
usage_blameRange=annotate only the given range
usage_blameRawTimestamp=show raw timestamp
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java
index cc2f287..ad32638 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java
@@ -45,8 +45,14 @@ package org.eclipse.jgit.pgm;
import java.lang.String;
import java.lang.System;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.EnumMap;
+import java.util.Map;
import java.text.MessageFormat;
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.eclipse.jgit.lib.FileMode;
@@ -58,18 +64,23 @@ import org.eclipse.jgit.pgm.TextBuiltin;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.kohsuke.args4j.Argument;
+import org.kohsuke.args4j.Option;
@Command(common = true, usage = "usage_archive")
class Archive extends TextBuiltin {
@Argument(index = 0, metaVar = "metaVar_treeish")
private AbstractTreeIterator tree;
+ @Option(name = "--format", metaVar = "metaVar_archiveFormat", usage = "usage_archiveFormat")
+ private Format format = Format.ZIP;
+
@Override
protected void run() throws Exception {
final TreeWalk walk = new TreeWalk(db);
final ObjectReader reader = walk.getObjectReader();
final MutableObjectId idBuf = new MutableObjectId();
- final ZipArchiveOutputStream out = new ZipArchiveOutputStream(outs);
+ final Archiver fmt = formats.get(format);
+ final ArchiveOutputStream out = fmt.createArchiveOutputStream(outs);
if (tree == null)
throw die(CLIText.get().treeIsRequired);
@@ -87,25 +98,57 @@ class Archive extends TextBuiltin {
continue;
walk.getObjectId(idBuf, 0);
- final ZipArchiveEntry entry = new ZipArchiveEntry(name);
- final ObjectLoader loader = reader.open(idBuf);
- entry.setSize(loader.getSize());
-
- if (mode == FileMode.REGULAR_FILE)
- ; // ok
- else if (mode == FileMode.EXECUTABLE_FILE ||
- mode == FileMode.SYMLINK)
- entry.setUnixMode(mode.getBits());
- else
- System.err.println(MessageFormat.format( //
- CLIText.get().archiveEntryModeIgnored, //
- name));
-
- out.putArchiveEntry(entry);
- loader.copyTo(out);
- out.closeArchiveEntry();
+ fmt.putEntry(name, mode, reader.open(idBuf), out);
}
out.close();
}
+
+ static private void warnArchiveEntryModeIgnored(String name) {
+ System.err.println(MessageFormat.format( //
+ CLIText.get().archiveEntryModeIgnored, //
+ name));
+ }
+
+ public enum Format {
+ ZIP
+ };
+
+ private static interface Archiver {
+ ArchiveOutputStream createArchiveOutputStream(OutputStream s);
+ void putEntry(String path, FileMode mode, //
+ ObjectLoader loader, ArchiveOutputStream out) //
+ throws IOException;
+ }
+
+ private static final Map<Format, Archiver> formats;
+ static {
+ Map<Format, Archiver> fmts = new EnumMap<Format, Archiver>(Format.class);
+ fmts.put(Format.ZIP, new Archiver() {
+ @Override
+ public ArchiveOutputStream createArchiveOutputStream(OutputStream s) {
+ return new ZipArchiveOutputStream(s);
+ }
+
+ @Override
+ public void putEntry(String path, FileMode mode, //
+ ObjectLoader loader, ArchiveOutputStream out) //
+ throws IOException {
+ final ZipArchiveEntry entry = new ZipArchiveEntry(path);
+
+ if (mode == FileMode.REGULAR_FILE)
+ ; // ok
+ else if (mode == FileMode.EXECUTABLE_FILE ||
+ mode == FileMode.SYMLINK)
+ entry.setUnixMode(mode.getBits());
+ else
+ warnArchiveEntryModeIgnored(path);
+ entry.setSize(loader.getSize());
+ out.putArchiveEntry(entry);
+ loader.copyTo(out);
+ out.closeArchiveEntry();
+ }
+ });
+ formats = fmts;
+ }
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java
index 2228555..ecf5e8d 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CLIText.java
@@ -139,6 +139,7 @@ public class CLIText extends TranslationBundle {
/***/ public String mergeMadeBy;
/***/ public String mergedSquashed;
/***/ public String metaVar_KEY;
+ /***/ public String metaVar_archiveFormat;
/***/ public String metaVar_arg;
/***/ public String metaVar_author;
/***/ public String metaVar_bucket;