aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm/src
diff options
context:
space:
mode:
authorJonathan Nieder <jrn@google.com>2012-12-03 16:08:04 -0800
committerJonathan Nieder <jrn@google.com>2012-12-04 15:37:42 -0800
commit78009782cdabdba42841f2a71fbd5867f2ae683f (patch)
treea17f08bb0f076ba41fd019b731083ea7e4a5ae60 /org.eclipse.jgit.pgm/src
parent345ab401ce27e9d4cb4002edd7f8e732b5e2e6fc (diff)
downloadjgit-78009782cdabdba42841f2a71fbd5867f2ae683f.tar.gz
jgit-78009782cdabdba42841f2a71fbd5867f2ae683f.zip
archive: Add tar support
Unlike ZIP files, tar files do not treat symlinks as ordinary files with a different mode, so tar support involves a little more code than would be ideal. Change-Id: Ica2568f4a0e443bf4b955ef0c029bc8eec62d369
Diffstat (limited to 'org.eclipse.jgit.pgm/src')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Archive.java38
1 files changed, 37 insertions, 1 deletions
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 ad32638232..4a5bf1c554 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
@@ -53,6 +53,9 @@ import java.text.MessageFormat;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
+import org.apache.commons.compress.archivers.tar.TarConstants;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.eclipse.jgit.lib.FileMode;
@@ -111,7 +114,8 @@ class Archive extends TextBuiltin {
}
public enum Format {
- ZIP
+ ZIP,
+ TAR
};
private static interface Archiver {
@@ -149,6 +153,38 @@ class Archive extends TextBuiltin {
out.closeArchiveEntry();
}
});
+ fmts.put(Format.TAR, new Archiver() {
+ @Override
+ public ArchiveOutputStream createArchiveOutputStream(OutputStream s) {
+ return new TarArchiveOutputStream(s);
+ }
+
+ @Override
+ public void putEntry(String path, FileMode mode, //
+ ObjectLoader loader, ArchiveOutputStream out) //
+ throws IOException {
+ if (mode == FileMode.SYMLINK) {
+ final TarArchiveEntry entry = new TarArchiveEntry( //
+ path, TarConstants.LF_SYMLINK);
+ entry.setLinkName(new String( //
+ loader.getCachedBytes(100), "UTF-8"));
+ out.putArchiveEntry(entry);
+ out.closeArchiveEntry();
+ return;
+ }
+
+ final TarArchiveEntry entry = new TarArchiveEntry(path);
+ if (mode == FileMode.REGULAR_FILE ||
+ mode == FileMode.EXECUTABLE_FILE)
+ entry.setMode(mode.getBits());
+ else
+ warnArchiveEntryModeIgnored(path);
+ entry.setSize(loader.getSize());
+ out.putArchiveEntry(entry);
+ loader.copyTo(out);
+ out.closeArchiveEntry();
+ }
+ });
formats = fmts;
}
}