|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.jgit.storage.pack.PackWriter
public class PackWriter
PackWriter class is responsible for generating pack files from specified set of objects from repository. This implementation produce pack files in format version 2.
Source of objects may be specified in two ways:
RevObject
specifying exact list and
order of objects in packpreparePack(Iterator)
or
preparePack(ProgressMonitor, Collection, Collection)
, and finally
producing the stream with writePack(ProgressMonitor, ProgressMonitor, OutputStream)
.
Class provide set of configurable options and ProgressMonitor
support, as operations may take a long time for big repositories. Deltas
searching algorithm is NOT IMPLEMENTED yet - this implementation
relies only on deltas and objects reuse.
This class is not thread safe, it is intended to be used in one thread, with one instance per created pack. Subsequent calls to writePack result in undefined behavior.
Nested Class Summary | |
---|---|
static interface |
PackWriter.ObjectIdSet
A collection of object ids. |
static class |
PackWriter.PackingPhase
Possible states that a PackWriter can be in. |
class |
PackWriter.State
Summary of the current state of a PackWriter. |
static class |
PackWriter.Statistics
Summary of how PackWriter created the pack. |
Constructor Summary | |
---|---|
PackWriter(ObjectReader reader)
Create a writer to load objects from the specified reader. |
|
PackWriter(PackConfig config,
ObjectReader reader)
Create writer with a specified configuration. |
|
PackWriter(Repository repo)
Create writer for specified repository. |
|
PackWriter(Repository repo,
ObjectReader reader)
Create writer for specified repository. |
Method Summary | |
---|---|
void |
addObject(RevObject object)
Include one object to the output file. |
ObjectId |
computeName()
Computes SHA-1 of lexicographically sorted objects ids written in this pack, as used to name a pack file in repository. |
void |
excludeObjects(PackWriter.ObjectIdSet idx)
Add a pack index whose contents should be excluded from the result. |
ObjectToPack |
get(AnyObjectId id)
Lookup the ObjectToPack object for a given ObjectId. |
static Iterable<PackWriter> |
getInstances()
|
long |
getObjectCount()
Returns objects number in a pack file that was created by this writer. |
ObjectIdOwnerMap<ObjectIdOwnerMap.Entry> |
getObjectSet()
Returns the object ids in the pack file that was created by this writer. |
PackWriter.State |
getState()
|
PackWriter.Statistics |
getStatistics()
|
boolean |
isDeltaBaseAsOffset()
Check whether writer can store delta base as an offset (new style reducing pack size) or should store it as an object id (legacy style, compatible with old readers). |
boolean |
isIgnoreMissingUninteresting()
|
boolean |
isReuseDeltaCommits()
Check if the writer will reuse commits that are already stored as deltas. |
boolean |
isReuseValidatingObjects()
Check if the writer validates objects before copying them. |
boolean |
isThin()
|
boolean |
isUseCachedPacks()
|
void |
preparePack(Iterator<RevObject> objectsSource)
Prepare the list of objects to be written to the pack stream. |
void |
preparePack(ProgressMonitor countingMonitor,
Collection<? extends ObjectId> want,
Collection<? extends ObjectId> have)
Deprecated. to be removed in 2.0; use the Set version of this method. |
void |
preparePack(ProgressMonitor countingMonitor,
ObjectWalk walk,
Collection<? extends ObjectId> interestingObjects,
Collection<? extends ObjectId> uninterestingObjects)
Deprecated. to be removed in 2.0; use the Set version of this method. |
void |
preparePack(ProgressMonitor countingMonitor,
ObjectWalk walk,
Set<? extends ObjectId> interestingObjects,
Set<? extends ObjectId> uninterestingObjects)
Prepare the list of objects to be written to the pack stream. |
void |
preparePack(ProgressMonitor countingMonitor,
Set<? extends ObjectId> want,
Set<? extends ObjectId> have)
Prepare the list of objects to be written to the pack stream. |
void |
release()
Release all resources used by this writer. |
void |
select(ObjectToPack otp,
StoredObjectRepresentation next)
Select an object representation for this writer. |
void |
setDeltaBaseAsOffset(boolean deltaBaseAsOffset)
Set writer delta base format. |
void |
setIgnoreMissingUninteresting(boolean ignore)
|
void |
setReuseDeltaCommits(boolean reuse)
Set the writer to reuse existing delta versions of commits. |
void |
setReuseValidatingObjects(boolean validate)
Enable (or disable) object validation during packing. |
void |
setShallowPack(int depth,
Collection<? extends ObjectId> unshallow)
Configure this pack for a shallow clone. |
void |
setTagTargets(Set<ObjectId> objects)
Set the tag targets that should be hoisted earlier during packing. |
void |
setThin(boolean packthin)
|
void |
setUseCachedPacks(boolean useCached)
|
boolean |
willInclude(AnyObjectId id)
Determine if the pack file will contain the requested object. |
void |
writeIndex(OutputStream indexStream)
Create an index file to match the pack file just written. |
void |
writePack(ProgressMonitor compressMonitor,
ProgressMonitor writeMonitor,
OutputStream packStream)
Write the prepared pack to the supplied stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PackWriter(Repository repo)
Objects for packing are specified in preparePack(Iterator)
or
preparePack(ProgressMonitor, Collection, Collection)
.
repo
- repository where objects are stored.public PackWriter(ObjectReader reader)
Objects for packing are specified in preparePack(Iterator)
or
preparePack(ProgressMonitor, Collection, Collection)
.
reader
- reader to read from the repository with.public PackWriter(Repository repo, ObjectReader reader)
Objects for packing are specified in preparePack(Iterator)
or
preparePack(ProgressMonitor, Collection, Collection)
.
repo
- repository where objects are stored.reader
- reader to read from the repository with.public PackWriter(PackConfig config, ObjectReader reader)
Objects for packing are specified in preparePack(Iterator)
or
preparePack(ProgressMonitor, Collection, Collection)
.
config
- configuration for the pack writer.reader
- reader to read from the repository with.Method Detail |
---|
public static Iterable<PackWriter> getInstances()
public boolean isDeltaBaseAsOffset()
public void setDeltaBaseAsOffset(boolean deltaBaseAsOffset)
deltaBaseAsOffset
- boolean indicating whether delta base can be stored as an
offset.public boolean isReuseDeltaCommits()
public void setReuseDeltaCommits(boolean reuse)
reuse
- if true, the writer will reuse any commits stored as deltas.
By default the writer does not reuse delta commits.public boolean isReuseValidatingObjects()
public void setReuseValidatingObjects(boolean validate)
validate
- if true the pack writer will validate an object before it is
put into the output. This additional validation work may be
necessary to avoid propagating corruption from one local pack
file to another local pack file.public boolean isThin()
public void setThin(boolean packthin)
packthin
- a boolean indicating whether writer may pack objects with
delta base object not within set of objects to pack, but
belonging to party repository (uninteresting/boundary) as
determined by set; this kind of pack is used only for
transport; true - to produce thin pack, false - otherwise.public boolean isUseCachedPacks()
public void setUseCachedPacks(boolean useCached)
useCached
- if set to true and a cached pack is present, it will be
appended onto the end of a thin-pack, reducing the amount of
working set space and CPU used by PackWriter. Enabling this
feature prevents PackWriter from creating an index for the
newly created pack, so its only suitable for writing to a
network client, where the client will make the index.public boolean isIgnoreMissingUninteresting()
MissingObjectException
out of preparePack(ProgressMonitor, Collection, Collection)
if an
uninteresting object is not in the source repository. By default,
true, permitting gracefully ignoring of uninteresting objects.public void setIgnoreMissingUninteresting(boolean ignore)
ignore
- true if writer should ignore non existing uninteresting
objects during construction set of objects to pack; false
otherwise - non existing uninteresting objects may cause
MissingObjectException
public void setTagTargets(Set<ObjectId> objects)
Callers may put objects into this set before invoking any of the preparePack methods to influence where an annotated tag's target is stored within the resulting pack. Typically these will be clustered together, and hoisted earlier in the file even if they are ancient revisions, allowing readers to find tag targets with better locality.
objects
- objects that annotated tags point at.public void setShallowPack(int depth, Collection<? extends ObjectId> unshallow)
depth
- maximum depth to traverse the commit graphunshallow
- objects which used to be shallow on the client, but are being
extended as part of this fetchpublic long getObjectCount() throws IOException
IOException
- a cached pack cannot supply its object count.public ObjectIdOwnerMap<ObjectIdOwnerMap.Entry> getObjectSet() throws IOException
writePack(ProgressMonitor, ProgressMonitor, OutputStream)
has
been invoked and completed successfully.
IOException
- a cached pack cannot supply its object ids.public void excludeObjects(PackWriter.ObjectIdSet idx)
idx
- objects in this index will not be in the output pack.public void preparePack(Iterator<RevObject> objectsSource) throws IOException
Iterator exactly determines which objects are included in a pack and order they appear in pack (except that objects order by type is not needed at input). This order should conform general rules of ordering objects in git - by recency and path (type and delta-base first is internally secured) and responsibility for guaranteeing this order is on a caller side. Iterator must return each id of object to write exactly once.
objectsSource
- iterator of object to store in a pack; order of objects within
each type is important, ordering by type is not needed;
allowed types for objects are Constants.OBJ_COMMIT
,
Constants.OBJ_TREE
, Constants.OBJ_BLOB
and
Constants.OBJ_TAG
; objects returned by iterator may be
later reused by caller as object id and type are internally
copied in each iteration.
IOException
- when some I/O problem occur during reading objects.@Deprecated public void preparePack(ProgressMonitor countingMonitor, Collection<? extends ObjectId> want, Collection<? extends ObjectId> have) throws IOException
Basing on these 2 sets, another set of objects to put in a pack file is
created: this set consists of all objects reachable (ancestors) from
interesting objects, except uninteresting objects and their ancestors.
This method uses class ObjectWalk
extensively to find out that
appropriate set of output objects and their optimal order in output pack.
Order is consistent with general git in-pack rules: sort by object type,
recency, path and delta-base first.
countingMonitor
- progress during object enumeration.want
- collection of objects to be marked as interesting (start
points of graph traversal).have
- collection of objects to be marked as uninteresting (end
points of graph traversal).
IOException
- when some I/O problem occur during reading objects.@Deprecated public void preparePack(ProgressMonitor countingMonitor, ObjectWalk walk, Collection<? extends ObjectId> interestingObjects, Collection<? extends ObjectId> uninterestingObjects) throws IOException
Basing on these 2 sets, another set of objects to put in a pack file is
created: this set consists of all objects reachable (ancestors) from
interesting objects, except uninteresting objects and their ancestors.
This method uses class ObjectWalk
extensively to find out that
appropriate set of output objects and their optimal order in output pack.
Order is consistent with general git in-pack rules: sort by object type,
recency, path and delta-base first.
countingMonitor
- progress during object enumeration.walk
- ObjectWalk to perform enumeration.interestingObjects
- collection of objects to be marked as interesting (start
points of graph traversal).uninterestingObjects
- collection of objects to be marked as uninteresting (end
points of graph traversal).
IOException
- when some I/O problem occur during reading objects.public void preparePack(ProgressMonitor countingMonitor, Set<? extends ObjectId> want, Set<? extends ObjectId> have) throws IOException
Basing on these 2 sets, another set of objects to put in a pack file is
created: this set consists of all objects reachable (ancestors) from
interesting objects, except uninteresting objects and their ancestors.
This method uses class ObjectWalk
extensively to find out that
appropriate set of output objects and their optimal order in output pack.
Order is consistent with general git in-pack rules: sort by object type,
recency, path and delta-base first.
countingMonitor
- progress during object enumeration.want
- collection of objects to be marked as interesting (start
points of graph traversal).have
- collection of objects to be marked as uninteresting (end
points of graph traversal).
IOException
- when some I/O problem occur during reading objects.public void preparePack(ProgressMonitor countingMonitor, ObjectWalk walk, Set<? extends ObjectId> interestingObjects, Set<? extends ObjectId> uninterestingObjects) throws IOException
Basing on these 2 sets, another set of objects to put in a pack file is
created: this set consists of all objects reachable (ancestors) from
interesting objects, except uninteresting objects and their ancestors.
This method uses class ObjectWalk
extensively to find out that
appropriate set of output objects and their optimal order in output pack.
Order is consistent with general git in-pack rules: sort by object type,
recency, path and delta-base first.
countingMonitor
- progress during object enumeration.walk
- ObjectWalk to perform enumeration.interestingObjects
- collection of objects to be marked as interesting (start
points of graph traversal).uninterestingObjects
- collection of objects to be marked as uninteresting (end
points of graph traversal).
IOException
- when some I/O problem occur during reading objects.public boolean willInclude(AnyObjectId id) throws IOException
id
- the object to test the existence of.
IOException
- a cached pack cannot be examined.public ObjectToPack get(AnyObjectId id)
id
- the object to find in the pack.
public ObjectId computeName()
public void writeIndex(OutputStream indexStream) throws IOException
This method can only be invoked after
writePack(ProgressMonitor, ProgressMonitor, OutputStream)
has
been invoked and completed successfully. Writing a corresponding index is
an optional feature that not all pack users may require.
indexStream
- output for the index data. Caller is responsible for closing
this stream.
IOException
- the index data could not be written to the supplied stream.public void writePack(ProgressMonitor compressMonitor, ProgressMonitor writeMonitor, OutputStream packStream) throws IOException
At first, this method collects and sorts objects to pack, then deltas search is performed if set up accordingly, finally pack stream is written.
All reused objects data checksum (Adler32/CRC32) is computed and validated against existing checksum.
compressMonitor
- progress monitor to report object compression work.writeMonitor
- progress monitor to report the number of objects written.packStream
- output stream of pack data. The stream should be buffered by
the caller. The caller is responsible for closing the stream.
IOException
- an error occurred reading a local object's data to include in
the pack, or writing compressed object data to the output
stream.public PackWriter.Statistics getStatistics()
writePack(ProgressMonitor, ProgressMonitor, OutputStream)
public PackWriter.State getState()
public void release()
public void addObject(RevObject object) throws IncorrectObjectTypeException
Objects are written in the order they are added. If the same object is added twice, it may be written twice, creating a larger than necessary file.
object
- the object to add.
IncorrectObjectTypeException
- the object is an unsupported type.public void select(ObjectToPack otp, StoredObjectRepresentation next)
An ObjectReader
implementation should invoke this method once for
each representation available for an object, to allow the writer to find
the most suitable one for the output.
otp
- the object being packed.next
- the next available representation from the repository.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |