Class BundleWriter
Bundles generated by this class can be later read in from a file URI using
the bundle transport, or from an application controlled buffer by the more
generic TransportBundleStream
.
Applications creating bundles need to call one or more include
calls to reflect which objects should be available as refs in the bundle for
the other side to fetch. At least one include is required to create a valid
bundle file, and duplicate names are not permitted.
Optional assume
calls can be made to declare commits which the
recipient must have in order to fetch from the bundle file. Objects reachable
from these assumed commits can be used as delta bases in order to reduce the
overall bundle size.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<CachedPack>
private ObjectCountCallback
private final Repository
private PackConfig
private final ObjectReader
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a writer for a bundle.BundleWriter
(Repository repo) Create a writer for a bundle. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addObjectsAsIs
(Collection<? extends CachedPack> c) Add objects to the bundle file.void
Assume a commit is available on the recipient's side.void
include
(String name, AnyObjectId id) Include an object (and everything reachable from it) in the bundle.void
Include a single ref (a name/object pair) in the bundle.private PackWriter
setObjectCountCallback
(ObjectCountCallback callback) Set theObjectCountCallback
.void
Set the configuration used by the pack generator.void
writeBundle
(ProgressMonitor monitor, OutputStream os) Generate and write the bundle to the output stream.
-
Field Details
-
db
-
reader
-
include
-
assume
-
tagTargets
-
cachedPacks
-
packConfig
-
callback
-
-
Constructor Details
-
BundleWriter
Create a writer for a bundle.- Parameters:
repo
- repository where objects are stored.
-
BundleWriter
Create a writer for a bundle.- Parameters:
or
- reader for reading objects. Will be closed at the end ofwriteBundle(ProgressMonitor, OutputStream)
, but readers may be reused after closing.- Since:
- 4.8
-
-
Method Details
-
setPackConfig
Set the configuration used by the pack generator.- Parameters:
pc
- configuration controlling packing parameters. If null the source repository's settings will be used, or the default settings if constructed without a repo.
-
include
Include an object (and everything reachable from it) in the bundle.- Parameters:
name
- name the recipient can discover this object as from the bundle's list of advertised refs . The name must be a valid ref format and must not have already been included in this bundle writer.id
- object to pack. Multiple refs may point to the same object.
-
include
Include a single ref (a name/object pair) in the bundle.This is a utility function for:
include(r.getName(), r.getObjectId())
.- Parameters:
r
- the ref to include.
-
addObjectsAsIs
Add objects to the bundle file.When this method is used, object traversal is disabled and specified pack files are directly saved to the Git bundle file.
Unlike
include
, this doesn't affect the refs. Even if the objects are not reachable from any ref, they will be included in the bundle file.- Parameters:
c
- pack to include- Since:
- 5.9
-
assume
Assume a commit is available on the recipient's side.In order to fetch from a bundle the recipient must have any assumed commit. Each assumed commit is explicitly recorded in the bundle header to permit the recipient to validate it has these objects.
- Parameters:
c
- the commit to assume being available. This commit should be parsed and not disposed in order to maximize the amount of debugging information available in the bundle stream.
-
writeBundle
Generate and write the bundle to the output stream.This method can only be called once per BundleWriter instance.
- Parameters:
monitor
- progress monitor to report bundle writing status to.os
- the stream the bundle is written to. The stream should be buffered by the caller. The caller is responsible for closing the stream.- Throws:
IOException
- an error occurred reading a local object's data to include in the bundle, or writing compressed object data to the output stream.
-
newPackWriter
-
setObjectCountCallback
Set theObjectCountCallback
.It should be set before calling
writeBundle(ProgressMonitor, OutputStream)
.This callback will be passed on to
PackWriter.setObjectCountCallback(org.eclipse.jgit.transport.ObjectCountCallback)
.- Parameters:
callback
- the callback to set- Returns:
- this object for chaining.
- Since:
- 4.1
-