diff options
author | Jonathan Nieder <jrn@google.com> | 2012-12-03 16:08:04 -0800 |
---|---|---|
committer | Jonathan Nieder <jrn@google.com> | 2012-12-04 15:37:42 -0800 |
commit | 78009782cdabdba42841f2a71fbd5867f2ae683f (patch) | |
tree | a17f08bb0f076ba41fd019b731083ea7e4a5ae60 /org.eclipse.jgit.pgm | |
parent | 345ab401ce27e9d4cb4002edd7f8e732b5e2e6fc (diff) | |
download | jgit-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')
3 files changed, 39 insertions, 2 deletions
diff --git a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF index 247f93cb20..b2a988c3a9 100644 --- a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF @@ -7,6 +7,7 @@ Bundle-Vendor: %provider_name Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: org.apache.commons.compress.archivers;version="[1.3,2.0)", + org.apache.commons.compress.archivers.tar;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)", 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 fe70e71329..5586a28200 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 @@ -197,7 +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_archiveFormat=archive format. Currently supported formats: 'tar', '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 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; } } |