|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.eclipse.jgit.lib.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(Collection, Collection), and finally
producing the stream with writePack(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.
| Field Summary | |
|---|---|
static java.lang.String |
COUNTING_OBJECTS_PROGRESS
Title of ProgressMonitor task used during counting objects to
pack. |
static boolean |
DEFAULT_DELTA_BASE_AS_OFFSET
Default value of delta base as offset option. |
static int |
DEFAULT_MAX_DELTA_DEPTH
Default value of maximum delta chain depth. |
static boolean |
DEFAULT_REUSE_DELTAS
Default value of deltas reuse option. |
static boolean |
DEFAULT_REUSE_OBJECTS
Default value of objects reuse option. |
static java.lang.String |
SEARCHING_REUSE_PROGRESS
Title of ProgressMonitor task used during searching for objects
reuse or delta reuse. |
static java.lang.String |
WRITING_OBJECTS_PROGRESS
Title of ProgressMonitor task used during writing out pack
(objects) |
| Constructor Summary | |
|---|---|
PackWriter(Repository repo,
ProgressMonitor monitor)
Create writer for specified repository. |
|
PackWriter(Repository repo,
ProgressMonitor imonitor,
ProgressMonitor wmonitor)
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. |
int |
getMaxDeltaDepth()
Get maximum depth of delta chain set up for this writer. |
int |
getObjectsNumber()
Returns objects number in a pack file that was created by this writer. |
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 |
isReuseDeltas()
Check whether object is configured to reuse deltas existing in repository. |
boolean |
isReuseObjects()
Checks whether object is configured to reuse existing objects representation in repository. |
boolean |
isThin()
|
void |
preparePack(java.util.Collection<? extends ObjectId> interestingObjects,
java.util.Collection<? extends ObjectId> uninterestingObjects)
Prepare the list of objects to be written to the pack stream. |
void |
preparePack(java.util.Iterator<RevObject> objectsSource)
Prepare the list of objects to be written to the pack stream. |
void |
setDeltaBaseAsOffset(boolean deltaBaseAsOffset)
Set writer delta base format. |
void |
setIgnoreMissingUninteresting(boolean ignore)
|
void |
setIndexVersion(int version)
Set the pack index file format version this instance will create. |
void |
setMaxDeltaDepth(int maxDeltaDepth)
Set up maximum depth of delta chain for this writer. |
void |
setReuseDeltas(boolean reuseDeltas)
Set reuse deltas configuration option for this writer. |
void |
setReuseObjects(boolean reuseObjects)
Set reuse objects configuration option for this writer. |
void |
setThin(boolean packthin)
|
boolean |
willInclude(AnyObjectId id)
Determine if the pack file will contain the requested object. |
void |
writeIndex(java.io.OutputStream indexStream)
Create an index file to match the pack file just written. |
void |
writePack(java.io.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 |
| Field Detail |
|---|
public static final java.lang.String COUNTING_OBJECTS_PROGRESS
ProgressMonitor task used during counting objects to
pack.
preparePack(Collection, Collection),
Constant Field Valuespublic static final java.lang.String SEARCHING_REUSE_PROGRESS
ProgressMonitor task used during searching for objects
reuse or delta reuse.
writePack(OutputStream),
Constant Field Valuespublic static final java.lang.String WRITING_OBJECTS_PROGRESS
ProgressMonitor task used during writing out pack
(objects)
writePack(OutputStream),
Constant Field Valuespublic static final boolean DEFAULT_REUSE_DELTAS
setReuseDeltas(boolean),
Constant Field Valuespublic static final boolean DEFAULT_REUSE_OBJECTS
setReuseObjects(boolean),
Constant Field Valuespublic static final boolean DEFAULT_DELTA_BASE_AS_OFFSET
setDeltaBaseAsOffset(boolean),
Constant Field Valuespublic static final int DEFAULT_MAX_DELTA_DEPTH
setMaxDeltaDepth(int),
Constant Field Values| Constructor Detail |
|---|
public PackWriter(Repository repo,
ProgressMonitor monitor)
Objects for packing are specified in preparePack(Iterator) or
preparePack(Collection, Collection).
repo - repository where objects are stored.monitor - operations progress monitor, used within
preparePack(Iterator),
preparePack(Collection, Collection)
, or writePack(OutputStream).
public PackWriter(Repository repo,
ProgressMonitor imonitor,
ProgressMonitor wmonitor)
Objects for packing are specified in preparePack(Iterator) or
preparePack(Collection, Collection).
repo - repository where objects are stored.imonitor - operations progress monitor, used within
preparePack(Iterator),
preparePack(Collection, Collection)wmonitor - operations progress monitor, used within
writePack(OutputStream).| Method Detail |
|---|
public boolean isReuseDeltas()
Default setting: true
public void setReuseDeltas(boolean reuseDeltas)
preparePack(Collection, Collection) and
preparePack(Iterator)) where base object must exist on other
side machine.
When raw delta data is directly copied from a pack file, checksum is computed to verify data.
Default setting: true
reuseDeltas - boolean indicating whether or not try to reuse deltas.public boolean isReuseObjects()
Default setting: true
public void setReuseObjects(boolean reuseObjects)
Default setting: true
reuseObjects - boolean indicating whether or not writer should reuse existing
objects representation.public boolean isDeltaBaseAsOffset()
Default setting: false
public void setDeltaBaseAsOffset(boolean deltaBaseAsOffset)
Default setting: false
deltaBaseAsOffset - boolean indicating whether delta base can be stored as an
offset.public int getMaxDeltaDepth()
Default setting: 50
public void setMaxDeltaDepth(int maxDeltaDepth)
Default setting: 50
maxDeltaDepth - maximum delta chain depth.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 isIgnoreMissingUninteresting()
MissingObjectException
out of preparePack(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
MissingObjectExceptionpublic void setIndexVersion(int version)
version - the version to write. The special version 0 designates the
oldest (most compatible) format available for the objects.PackIndexWriterpublic int getObjectsNumber()
public void preparePack(java.util.Iterator<RevObject> objectsSource)
throws java.io.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.
When iterator returns object that has RevFlag.UNINTERESTING flag,
this object won't be included in an output pack. Instead, it is recorded
as edge-object (known to remote repository) for thin-pack. In such a case
writer may pack objects with delta base object not within set of objects
to pack, but belonging to party repository - those marked with
RevFlag.UNINTERESTING flag. This type of pack is used only for
transport.
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; if object returned by iterator has
RevFlag.UNINTERESTING flag set, it won't be included
in a pack, but is considered as edge-object for thin-pack.
java.io.IOException - when some I/O problem occur during reading objects.
public void preparePack(java.util.Collection<? extends ObjectId> interestingObjects,
java.util.Collection<? extends ObjectId> uninterestingObjects)
throws java.io.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.
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).
java.io.IOException - when some I/O problem occur during reading objects.public boolean willInclude(AnyObjectId id)
id - the object to test the existence of.
public ObjectId computeName()
public void writeIndex(java.io.OutputStream indexStream)
throws java.io.IOException
This method can only be invoked after preparePack(Iterator) or
preparePack(Collection, Collection) 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.
java.io.IOException - the index data could not be written to the supplied stream.
public void writePack(java.io.OutputStream packStream)
throws java.io.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. ProgressMonitor tasks "Compressing objects"
(only if reuseDeltas or reuseObjects is enabled) and
"Writing objects" are updated during packing.
All reused objects data checksum (Adler32/CRC32) is computed and validated against existing checksum.
packStream - output stream of pack data. If the stream is not buffered it
will be buffered by the writer. Caller is responsible for
closing the stream.
java.io.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 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.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||