public class ArchiveCommand extends GitCommand<java.io.OutputStream>
Examples (git
is a Git
instance):
Create a tarball from HEAD:
ArchiveCommand.registerFormat("tar", new TarFormat()); try { git.archive().setTree(db.resolve("HEAD")).setOutputStream(out).call(); } finally { ArchiveCommand.unregisterFormat("tar"); }
Create a ZIP file from master:
ArchiveCommand.registerFormat("zip", new ZipFormat()); try { git.archive(). .setTree(db.resolve("master")) .setFormat("zip") .setOutputStream(out) .call(); } finally { ArchiveCommand.unregisterFormat("zip"); }
Modifier and Type | Class and Description |
---|---|
static interface |
ArchiveCommand.Format<T extends java.io.Closeable>
Archival format.
|
private static class |
ArchiveCommand.FormatEntry |
static class |
ArchiveCommand.UnsupportedFormatException
Signals an attempt to use an archival format that ArchiveCommand
doesn't know about (for example due to a typo).
|
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
format |
private java.util.Map<java.lang.String,java.lang.Object> |
formatOptions |
private static java.util.concurrent.ConcurrentMap<java.lang.String,ArchiveCommand.FormatEntry> |
formats
Available archival formats (corresponding to values for
the --format= option)
|
private java.io.OutputStream |
out |
private java.util.List<java.lang.String> |
paths |
private java.lang.String |
prefix |
private java.lang.String |
suffix
Filename suffix, for automatically choosing a format.
|
private ObjectId |
tree |
repo
Constructor and Description |
---|
ArchiveCommand(Repository repo)
Constructor for ArchiveCommand
|
Modifier and Type | Method and Description |
---|---|
java.io.OutputStream |
call() |
private static ArchiveCommand.Format<?> |
formatBySuffix(java.lang.String filenameSuffix) |
private RevTree |
getTree(RevObject o) |
private static ArchiveCommand.Format<?> |
lookupFormat(java.lang.String formatName) |
static void |
registerFormat(java.lang.String name,
ArchiveCommand.Format<?> fmt)
Adds support for an additional archival format.
|
private static <K,V> boolean |
replace(java.util.concurrent.ConcurrentMap<K,V> map,
K key,
V oldValue,
V newValue)
Replaces the entry for a key only if currently mapped to a given
value.
|
ArchiveCommand |
setFilename(java.lang.String filename)
Set the intended filename for the produced archive.
|
ArchiveCommand |
setFormat(java.lang.String fmt)
Set archive format
|
ArchiveCommand |
setFormatOptions(java.util.Map<java.lang.String,java.lang.Object> options)
Set archive format options
|
ArchiveCommand |
setOutputStream(java.io.OutputStream out)
Set output stream
|
ArchiveCommand |
setPaths(java.lang.String... paths)
Set an optional parameter path.
|
ArchiveCommand |
setPrefix(java.lang.String prefix)
Set string prefixed to filenames in archive
|
ArchiveCommand |
setTree(ObjectId tree)
Set the tag, commit, or tree object to produce an archive for
|
static void |
unregisterFormat(java.lang.String name)
Marks support for an archival format as no longer needed so its
Format can be garbage collected if no one else is using it either.
|
private <T extends java.io.Closeable> |
writeArchive(ArchiveCommand.Format<T> fmt) |
checkCallable, getRepository, setCallable
private static final java.util.concurrent.ConcurrentMap<java.lang.String,ArchiveCommand.FormatEntry> formats
private java.io.OutputStream out
private ObjectId tree
private java.lang.String prefix
private java.lang.String format
private java.util.Map<java.lang.String,java.lang.Object> formatOptions
private java.util.List<java.lang.String> paths
private java.lang.String suffix
public ArchiveCommand(Repository repo)
repo
- the Repository
private static <K,V> boolean replace(java.util.concurrent.ConcurrentMap<K,V> map, K key, V oldValue, V newValue)
map
- a mapkey
- key with which the specified value is associatedoldValue
- expected value for the key (null if should be absent).newValue
- value to be associated with the key (null to remove).public static void registerFormat(java.lang.String name, ArchiveCommand.Format<?> fmt)
OSGi plugins providing formats should call this function at bundle activation time.
It is okay to register the same archive format with the same name multiple times, but don't forget to unregister it that same number of times, too.
Registering multiple formats with different names and the same or overlapping suffixes results in undefined behavior. TODO: check that suffixes don't overlap.
name
- name of a format (e.g., "tar" or "zip").fmt
- archiver for that formatJGitInternalException
- A different archival format with that name was
already registered.public static void unregisterFormat(java.lang.String name)
In other words, this decrements the reference count for an archival format. If the reference count becomes zero, removes support for that format.
name
- name of format (e.g., "tar" or "zip").JGitInternalException
- No such archival format was registered.private static ArchiveCommand.Format<?> formatBySuffix(java.lang.String filenameSuffix) throws ArchiveCommand.UnsupportedFormatException
private static ArchiveCommand.Format<?> lookupFormat(java.lang.String formatName) throws ArchiveCommand.UnsupportedFormatException
private <T extends java.io.Closeable> java.io.OutputStream writeArchive(ArchiveCommand.Format<T> fmt)
public java.io.OutputStream call() throws GitAPIException
Execute the command
call
in interface java.util.concurrent.Callable<java.io.OutputStream>
call
in class GitCommand<java.io.OutputStream>
GitAPIException
public ArchiveCommand setTree(ObjectId tree)
tree
- the tag, commit, or tree object to produce an archive forpublic ArchiveCommand setPrefix(java.lang.String prefix)
prefix
- string prefixed to filenames in archive (e.g., "master/").
null means to not use any leading prefix.public ArchiveCommand setFilename(java.lang.String filename)
setFormat(String)
.filename
- intended filename for the archivepublic ArchiveCommand setOutputStream(java.io.OutputStream out)
out
- the stream to which to write the archivepublic ArchiveCommand setFormat(java.lang.String fmt)
fmt
- archive format (e.g., "tar" or "zip"). null means to choose
automatically based on the archive filename.public ArchiveCommand setFormatOptions(java.util.Map<java.lang.String,java.lang.Object> options)
options
- archive format options (e.g., level=9 for zip compression).public ArchiveCommand setPaths(java.lang.String... paths)
paths
- file names (e.g file1.c
) or directory names (e.g.
dir
to add dir/file1
and
dir/file2
) can also be given to add all files in
the directory, recursively. Fileglobs (e.g. *.c) are not yet
supported.private RevTree getTree(RevObject o) throws IncorrectObjectTypeException
IncorrectObjectTypeException