org.eclipse.jgit.transport
Class IndexPack

java.lang.Object
  extended by org.eclipse.jgit.transport.IndexPack

public class IndexPack
extends java.lang.Object

Indexes Git pack files for local use.


Field Summary
static int BUFFER_SIZE
          Size of the internal stream buffer.
static java.lang.String PROGRESS_DOWNLOAD
          Progress message when reading raw data from the pack.
static java.lang.String PROGRESS_RESOLVE_DELTA
          Progress message when computing names of delta compressed objects.
 
Constructor Summary
IndexPack(Repository db, java.io.InputStream src, java.io.File dstBase)
          Create a new pack indexer utility.
 
Method Summary
static IndexPack create(Repository db, java.io.InputStream is)
          Create an index pack instance to load a new pack into a repository.
 void index(ProgressMonitor progress)
          Consume data from the input stream until the packfile is indexed.
 void renameAndOpenPack()
          Rename the pack to it's final name and location and open it.
 PackLock renameAndOpenPack(java.lang.String lockMessage)
          Rename the pack to it's final name and location and open it.
 void setFixThin(boolean fix)
          Configure this index pack instance to make a thin pack complete.
 void setIndexVersion(int version)
          Set the pack index file format version this instance will create.
 void setKeepEmpty(boolean empty)
          Configure this index pack instance to keep an empty pack.
 void setObjectChecker(ObjectChecker oc)
          Configure the checker used to validate received objects.
 void setObjectChecking(boolean on)
          Configure the checker used to validate received objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROGRESS_DOWNLOAD

public static final java.lang.String PROGRESS_DOWNLOAD
Progress message when reading raw data from the pack.

See Also:
Constant Field Values

PROGRESS_RESOLVE_DELTA

public static final java.lang.String PROGRESS_RESOLVE_DELTA
Progress message when computing names of delta compressed objects.

See Also:
Constant Field Values

BUFFER_SIZE

public static final int BUFFER_SIZE
Size of the internal stream buffer.

If callers are going to be supplying IndexPack a BufferedInputStream they should use this buffer size as the size of the buffer for that BufferedInputStream, and any other its may be wrapping. This way the buffers will cascade efficiently and only the IndexPack buffer will be receiving the bulk of the data stream.

See Also:
Constant Field Values
Constructor Detail

IndexPack

public IndexPack(Repository db,
                 java.io.InputStream src,
                 java.io.File dstBase)
          throws java.io.IOException
Create a new pack indexer utility.

Parameters:
db -
src - stream to read the pack data from. If the stream is buffered use BUFFER_SIZE as the buffer size for the stream.
dstBase -
Throws:
java.io.IOException - the output packfile could not be created.
Method Detail

create

public static IndexPack create(Repository db,
                               java.io.InputStream is)
                        throws java.io.IOException
Create an index pack instance to load a new pack into a repository.

The received pack data and generated index will be saved to temporary files within the repository's objects directory. To use the data contained within them call renameAndOpenPack() once the indexing is complete.

Parameters:
db - the repository that will receive the new pack.
is - stream to read the pack data from. If the stream is buffered use BUFFER_SIZE as the buffer size for the stream.
Returns:
a new index pack instance.
Throws:
java.io.IOException - a temporary file could not be created.

setIndexVersion

public void setIndexVersion(int version)
Set the pack index file format version this instance will create.

Parameters:
version - the version to write. The special version 0 designates the oldest (most compatible) format available for the objects.
See Also:
PackIndexWriter

setFixThin

public void setFixThin(boolean fix)
Configure this index pack instance to make a thin pack complete.

Thin packs are sometimes used during network transfers to allow a delta to be sent without a base object. Such packs are not permitted on disk. They can be fixed by copying the base object onto the end of the pack.

Parameters:
fix - true to enable fixing a thin pack.

setKeepEmpty

public void setKeepEmpty(boolean empty)
Configure this index pack instance to keep an empty pack.

By default an empty pack (a pack with no objects) is not kept, as doing so is completely pointless. With no objects in the pack there is no data stored by it, so the pack is unnecessary.

Parameters:
empty - true to enable keeping an empty pack.

setObjectChecker

public void setObjectChecker(ObjectChecker oc)
Configure the checker used to validate received objects.

Usually object checking isn't necessary, as Git implementations only create valid objects in pack files. However, additional checking may be useful if processing data from an untrusted source.

Parameters:
oc - the checker instance; null to disable object checking.

setObjectChecking

public void setObjectChecking(boolean on)
Configure the checker used to validate received objects.

Usually object checking isn't necessary, as Git implementations only create valid objects in pack files. However, additional checking may be useful if processing data from an untrusted source.

This is shorthand for:

 setObjectChecker(on ? new ObjectChecker() : null);
 

Parameters:
on - true to enable the default checker; false to disable it.

index

public void index(ProgressMonitor progress)
           throws java.io.IOException
Consume data from the input stream until the packfile is indexed.

Parameters:
progress - progress feedback
Throws:
java.io.IOException

renameAndOpenPack

public void renameAndOpenPack()
                       throws java.io.IOException
Rename the pack to it's final name and location and open it.

If the call completes successfully the repository this IndexPack instance was created with will have the objects in the pack available for reading and use, without needing to scan for packs.

Throws:
java.io.IOException - The pack could not be inserted into the repository's objects directory. The pack no longer exists on disk, as it was removed prior to throwing the exception to the caller.

renameAndOpenPack

public PackLock renameAndOpenPack(java.lang.String lockMessage)
                           throws java.io.IOException
Rename the pack to it's final name and location and open it.

If the call completes successfully the repository this IndexPack instance was created with will have the objects in the pack available for reading and use, without needing to scan for packs.

Parameters:
lockMessage - message to place in the pack-*.keep file. If null, no lock will be created, and this method returns null.
Returns:
the pack lock object, if lockMessage is not null.
Throws:
java.io.IOException - The pack could not be inserted into the repository's objects directory. The pack no longer exists on disk, as it was removed prior to throwing the exception to the caller.