Package org.eclipse.jgit.api
Class ArchiveCommand
- All Implemented Interfaces:
Callable<OutputStream>
Create an archive of files from a named tree.
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"); }
- Since:
- 3.1
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
ArchiveCommand.Format<T extends Closeable>
Archival format.private static class
static class
Signals an attempt to use an archival format that ArchiveCommand doesn't know about (for example due to a typo). -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
private static final Map<String,
ArchiveCommand.FormatEntry> Available archival formats (corresponding to values for the --format= option)private OutputStream
private String
private String
Filename suffix, for automatically choosing a format.private ObjectId
Fields inherited from class org.eclipse.jgit.api.GitCommand
repo
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncall()
private static ArchiveCommand.Format<?>
formatBySuffix
(String filenameSuffix) private RevTree
private static ArchiveCommand.Format<?>
lookupFormat
(String formatName) static void
registerFormat
(String name, ArchiveCommand.Format<?> fmt) Adds support for an additional archival format.private static <K,
V> boolean Replaces the entry for a key only if currently mapped to a given value.setFilename
(String filename) Set the intended filename for the produced archive.Set archive formatsetFormatOptions
(Map<String, Object> options) Set archive format optionsSet output streamSet an optional parameter path.Set string prefixed to filenames in archiveSet the tag, commit, or tree object to produce an archive forstatic 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.private <T extends Closeable>
OutputStreamwriteArchive
(ArchiveCommand.Format<T> fmt) Methods inherited from class org.eclipse.jgit.api.GitCommand
checkCallable, getRepository, setCallable
-
Field Details
-
formats
Available archival formats (corresponding to values for the --format= option) -
out
-
tree
-
prefix
-
format
-
formatOptions
-
paths
-
suffix
Filename suffix, for automatically choosing a format.
-
-
Constructor Details
-
ArchiveCommand
Constructor for ArchiveCommand- Parameters:
repo
- theRepository
-
-
Method Details
-
replace
Replaces the entry for a key only if currently mapped to a given value.- Parameters:
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).- Returns:
- true if the value was replaced
-
registerFormat
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.
- Parameters:
name
- name of a format (e.g., "tar" or "zip").fmt
- archiver for that format- Throws:
JGitInternalException
- A different archival format with that name was already registered.
-
unregisterFormat
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.
- Parameters:
name
- name of format (e.g., "tar" or "zip").- Throws:
JGitInternalException
- No such archival format was registered.
-
formatBySuffix
private static ArchiveCommand.Format<?> formatBySuffix(String filenameSuffix) throws ArchiveCommand.UnsupportedFormatException -
lookupFormat
private static ArchiveCommand.Format<?> lookupFormat(String formatName) throws ArchiveCommand.UnsupportedFormatException -
writeArchive
-
call
Execute the command
- Specified by:
call
in interfaceCallable<OutputStream>
- Specified by:
call
in classGitCommand<OutputStream>
- Throws:
GitAPIException
-
setTree
Set the tag, commit, or tree object to produce an archive for- Parameters:
tree
- the tag, commit, or tree object to produce an archive for- Returns:
- this
-
setPrefix
Set string prefixed to filenames in archive- Parameters:
prefix
- string prefixed to filenames in archive (e.g., "master/"). null means to not use any leading prefix.- Returns:
- this
- Since:
- 3.3
-
setFilename
Set the intended filename for the produced archive. Currently the only effect is to determine the default archive format when none is specified withsetFormat(String)
.- Parameters:
filename
- intended filename for the archive- Returns:
- this
-
setOutputStream
Set output stream- Parameters:
out
- the stream to which to write the archive- Returns:
- this
-
setFormat
Set archive format- Parameters:
fmt
- archive format (e.g., "tar" or "zip"). null means to choose automatically based on the archive filename.- Returns:
- this
-
setFormatOptions
Set archive format options- Parameters:
options
- archive format options (e.g., level=9 for zip compression).- Returns:
- this
- Since:
- 4.0
-
setPaths
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.- Parameters:
paths
- file names (e.gfile1.c
) or directory names (e.g.dir
to adddir/file1
anddir/file2
) can also be given to add all files in the directory, recursively. Fileglobs (e.g. *.c) are not yet supported.- Returns:
- this
- Since:
- 3.4
-
getTree
- Throws:
IncorrectObjectTypeException
-