Examples (git is a org. 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 |
|---|---|
| public static interface | ArchiveCommand.
type representing an archive being created. T extends Closeable>Archival format. |
| private static class | |
| public static class | ArchiveCommand.
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 String | |
| private Map | |
| private static final Map | formats
Available archival formats (corresponding to values for the --format= option) |
| private OutputStream | |
| private List | |
| private String | |
| private String | suffix
Filename suffix, for automatically choosing a format. |
| private ObjectId |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public OutputStream | call()
Implements abstract org. Implements java. Computes a result, or throws an exception if unable to do so. |
| private static ArchiveCommand. | |
| private RevTree | |
| private static ArchiveCommand. | |
| public static void | registerFormat(String
name of a format (e.g., "tar" or "zip"). name, ArchiveCommand.archiver for that format fmtAdds support for an additional archival format. |
| private static <K, V> boolean | Returns: true if the value was replaceda map map, K key with which the specified value is associated key, V expected value for the key (null if should be absent). oldValue, V value to be associated with the key (null to remove). newValue)Replaces the entry for a key only if currently mapped to a given value. |
| public ArchiveCommand | Returns: thisintended filename for the archive filename)Set the intended filename for the produced archive. |
| public ArchiveCommand | |
| public ArchiveCommand | Returns: thisarchive format options (e.g., level=9 for zip compression). options)Set archive format options |
| public ArchiveCommand | Returns: thisthe stream to which to write the archive out)Set output stream |
| public ArchiveCommand | |
| public ArchiveCommand | |
| public ArchiveCommand | |
| public static void | unregisterFormat(String
name of format (e.g., "tar" or "zip"). 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 Closeable> OutputStream |
| format | back to summary |
|---|---|
| private String format | |
| formatOptions | back to summary |
|---|---|
| private Map<String, Object> formatOptions | |
| formats | back to summary |
|---|---|
| private static final Map<String, ArchiveCommand. Available archival formats (corresponding to values for the --format= option) | |
| out | back to summary |
|---|---|
| private OutputStream out | |
| paths | back to summary |
|---|---|
| private List<String> paths | |
| prefix | back to summary |
|---|---|
| private String prefix | |
| suffix | back to summary |
|---|---|
| private String suffix Filename suffix, for automatically choosing a format. | |
| tree | back to summary |
|---|---|
| private ObjectId tree | |
| ArchiveCommand | back to summary |
|---|---|
| public ArchiveCommand(Repository repo) Constructor for ArchiveCommand
| |
| call | back to summary |
|---|---|
| public OutputStream call() throws GitAPIException Implements abstract org. Implements java. Doc from org. Computes a result, or throws an exception if unable to do so. Execute the command
| |
| formatBySuffix | back to summary |
|---|---|
| private static ArchiveCommand. | |
| getTree | back to summary |
|---|---|
| private RevTree getTree(RevObject o) throws IncorrectObjectTypeException | |
| lookupFormat | back to summary |
|---|---|
| private static ArchiveCommand. | |
| registerFormat | back to summary |
|---|---|
| public static void registerFormat(String name, ArchiveCommand. Adds support for an additional archival format. To avoid unnecessary dependencies, ArchiveCommand does not have support for any formats built in; use this function to add them. 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.
| |
| replace | back to summary |
|---|---|
| private static <K, V> boolean replace(Map<K, V> map, K key, V oldValue, V newValue) Replaces the entry for a key only if currently mapped to a given value.
| |
| setFilename | back to summary |
|---|---|
| public ArchiveCommand setFilename(String filename) Set the intended filename for the produced archive. Currently the only
effect is to determine the default archive format when none is specified
with
| |
| setFormat | back to summary |
|---|---|
| public ArchiveCommand setFormat(String fmt) Set archive format
| |
| setFormatOptions | back to summary |
|---|---|
| public ArchiveCommand setFormatOptions(Map<String, Object> options) Set archive format options
| |
| setOutputStream | back to summary |
|---|---|
| public ArchiveCommand setOutputStream(OutputStream out) Set output stream
| |
| setPaths | back to summary |
|---|---|
| public ArchiveCommand setPaths(String... paths) Set an optional parameter path. without an optional path parameter, all files and subdirectories of the current working directory are included in the archive. If one or more paths are specified, only these are included.
| |
| setPrefix | back to summary |
|---|---|
| public ArchiveCommand setPrefix(String prefix) Set string prefixed to filenames in archive
| |
| setTree | back to summary |
|---|---|
| public ArchiveCommand setTree(ObjectId tree) Set the tag, commit, or tree object to produce an archive for
| |
| unregisterFormat | back to summary |
|---|---|
| public static void unregisterFormat(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. In other words, this decrements the reference count for an archival format. If the reference count becomes zero, removes support for that format.
| |
| writeArchive | back to summary |
|---|---|
| private <T extends Closeable> OutputStream writeArchive(ArchiveCommand. | |
| Modifier and Type | Method and Description |
|---|---|
| public T | Returns: new archive object for use in putEntryunderlying output stream to which to write the archive. s)Start a new archive. |
| public T | Returns: new archive object for use in putEntryunderlying output stream to which to write the archive. s, Map<String, Object> options to apply to the underlying output stream. Keys are
option names and values are option values. o)Start a new archive. |
| public void | putEntry(T
archive object from createArchiveOutputStream out, ObjectId the tag, commit, or tree object to produce an archive for tree, String full filename relative to the root of the archive (with
trailing '/' for directories) path, FileMode mode (for example FileMode.REGULAR_FILE or
FileMode.SYMLINK) mode, ObjectLoader blob object with data for this entry (null for
directories) loader)Write an entry to an archive. |
| public Iterable | Returns: this format's suffixesFilename suffixes representing this format (e.g., { ".tar.gz", ".tgz" }). |
| createArchiveOutputStream | back to summary |
|---|---|
| public T createArchiveOutputStream(OutputStream s) throws IOException Start a new archive. Entries can be included in the archive using the putEntry method, and then the archive should be closed using its close method.
| |
| createArchiveOutputStream | back to summary |
|---|---|
| public T createArchiveOutputStream(OutputStream s, Map<String, Object> o) throws IOException Start a new archive. Entries can be included in the archive using the putEntry method, and then the archive should be closed using its close method. In addition options can be applied to the underlying stream. E.g. compression level.
| |
| putEntry | back to summary |
|---|---|
| public void putEntry(T out, ObjectId tree, String path, FileMode mode, ObjectLoader loader) throws IOException Write an entry to an archive.
| |
| suffixes | back to summary |
|---|---|
| public Iterable Filename suffixes representing this format (e.g., { ".tar.gz", ".tgz" }). The behavior is undefined when suffixes overlap (if one format claims suffix ".7z", no other format should take ".tar.7z"). | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final ArchiveCommand. | |
| pack-priv final int | refcnt
Number of times this format has been registered. |
| Access | Constructor and Description |
|---|---|
| public |
| format | back to summary |
|---|---|
| pack-priv final ArchiveCommand. | |
| refcnt | back to summary |
|---|---|
| pack-priv final int refcnt Number of times this format has been registered. | |
| FormatEntry | back to summary |
|---|---|
| public FormatEntry(ArchiveCommand. | |
| Modifier and Type | Field and Description |
|---|---|
| private final String | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String |
| format | back to summary |
|---|---|
| private final String format | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides org. | |
| UnsupportedFormatException | back to summary |
|---|---|
public UnsupportedFormatException(String format)
| |
| getFormat | back to summary |
|---|---|
| public String getFormat() Get the problematic format name
| |