Top Description Fields Constructors Methods
org.eclipse.jgit.dircache

public Class DirCacheBuilder

extends BaseDirCacheEditor
Class Inheritance
Static Imports
org.eclipse.jgit.lib.FileMode.TYPE_MASK, .FileMode.TYPE_TREE

Updates a org.eclipse.jgit.dircache.DirCache by adding individual org.eclipse.jgit.dircache.DirCacheEntrys.

A builder always starts from a clean slate and appends in every single DirCacheEntry which the final updated index must have to reflect its new content.

For maximum performance applications should add entries in path name order. Adding entries out of order is permitted, however a final sorting pass will be implicitly performed during finish() to correct any out-of-order entries. Duplicate detection is also delayed until the sorting is complete.

See Also
DirCacheEditor

Field Summary

Modifier and TypeField and Description
private boolean
Inherited from org.eclipse.jgit.dircache.BaseDirCacheEditor:
cacheentriesentryCnt

Constructor Summary

AccessConstructor and Description
protected
DirCacheBuilder(DirCache
the cache this builder will eventually update.
dc
,
int
estimated number of entries the builder will have upon completion. This sizes the initial entry table.
ecnt
)

Construct a new builder.

Method Summary

Modifier and TypeMethod and Description
public void
add(DirCacheEntry
the new entry to add.
newEntry
)

Append one entry into the resulting entry list.

public void
addTree(byte[]
UTF-8 encoded prefix to mount the tree's entries at. If the path does not end with '/' one will be automatically inserted as necessary.
pathPrefix
,
int
stage of the entries when adding them.
stage
,
ObjectReader
reader the tree(s) will be read from during recursive traversal. This must be the same repository that the resulting DirCache would be written out to (or used in) otherwise the caller is simply asking for deferred MissingObjectExceptions. Caller is responsible for releasing this reader when done.
reader
,
AnyObjectId
the tree to recursively add. This tree's contents will appear under pathPrefix. The ObjectId must be that of a tree; the caller is responsible for dereferencing a tag or commit (if necessary).
tree
)

Recursively add an entire tree into this builder.

private static IllegalStateException
private void
private static CanonicalTreeParser
createTreeParser(byte[] pathPrefix, ObjectReader reader, AnyObjectId tree)

private static CanonicalTreeParser
public void
finish()

Implements abstract org.eclipse.jgit.dircache.BaseDirCacheEditor.finish.

Finish this builder and update the destination org.eclipse.jgit.dircache.DirCache.

private static boolean
public void
keep(int
first entry to copy from the destination cache.
pos
,
int
number of entries to copy.
cnt
)

Add a range of existing entries from the destination cache.

private void
private static DirCacheEntry
Inherited from org.eclipse.jgit.dircache.BaseDirCacheEditor:
commitfastAddfastKeepgetDirCachereplace

Field Detail

sortedback to summary
private boolean sorted

Constructor Detail

DirCacheBuilderback to summary
protected DirCacheBuilder(DirCache dc, int ecnt)

Construct a new builder.

Parameters
dc:DirCache

the cache this builder will eventually update.

ecnt:int

estimated number of entries the builder will have upon completion. This sizes the initial entry table.

Method Detail

addback to summary
public void add(DirCacheEntry newEntry)

Append one entry into the resulting entry list.

The entry is placed at the end of the entry list. If the entry causes the list to now be incorrectly sorted a final sorting phase will be automatically enabled within finish().

The internal entry table is automatically expanded if there is insufficient space for the new addition.

Parameters
newEntry:DirCacheEntry

the new entry to add.

Exceptions
IllegalArgumentException:
If the FileMode of the entry was not set by the caller.
addTreeback to summary
public void addTree(byte[] pathPrefix, int stage, ObjectReader reader, AnyObjectId tree) throws IOException

Recursively add an entire tree into this builder.

If pathPrefix is "a/b" and the tree contains file "c" then the resulting DirCacheEntry will have the path "a/b/c".

All entries are inserted at stage 0, therefore assuming that the application will not insert any other paths with the same pathPrefix.

Parameters
pathPrefix:byte[]

UTF-8 encoded prefix to mount the tree's entries at. If the path does not end with '/' one will be automatically inserted as necessary.

stage:int

stage of the entries when adding them.

reader:ObjectReader

reader the tree(s) will be read from during recursive traversal. This must be the same repository that the resulting DirCache would be written out to (or used in) otherwise the caller is simply asking for deferred MissingObjectExceptions. Caller is responsible for releasing this reader when done.

tree:AnyObjectId

the tree to recursively add. This tree's contents will appear under pathPrefix. The ObjectId must be that of a tree; the caller is responsible for dereferencing a tag or commit (if necessary).

Exceptions
IOException:
a tree cannot be read to iterate through its entries.
badback to summary
private static IllegalStateException bad(DirCacheEntry a, String msg)
beforeAddback to summary
private void beforeAdd(DirCacheEntry newEntry)
createTreeParserback to summary
private static CanonicalTreeParser createTreeParser(byte[] pathPrefix, ObjectReader reader, AnyObjectId tree) throws IOException
enterTreeback to summary
private static CanonicalTreeParser enterTree(CanonicalTreeParser p, ObjectReader reader) throws IOException
finishback to summary
public void finish()

Implements abstract org.eclipse.jgit.dircache.BaseDirCacheEditor.finish.

Doc from org.eclipse.jgit.dircache.BaseDirCacheEditor.finish.

Finish this builder and update the destination org.eclipse.jgit.dircache.DirCache.

When this method completes this builder instance is no longer usable by the calling application. A new builder must be created to make additional changes to the index entries.

After completion the DirCache returned by getDirCache() will contain all modifications.

Note to implementors: Make sure entries is fully sorted then invoke replace() to update the DirCache with the new table.

Annotations
@Override
isTreeback to summary
private static boolean isTree(CanonicalTreeParser p)
keepback to summary
public void keep(int pos, int cnt)

Add a range of existing entries from the destination cache.

The entries are placed at the end of the entry list. If any of the entries causes the list to now be incorrectly sorted a final sorting phase will be automatically enabled within finish().

This method copies from the destination cache, which has not yet been updated with this editor's new table. So all offsets into the destination cache are not affected by any updates that may be currently taking place in this editor.

The internal entry table is automatically expanded if there is insufficient space for the new additions.

Parameters
pos:int

first entry to copy from the destination cache.

cnt:int

number of entries to copy.

resortback to summary
private void resort()
toEntryback to summary
private static DirCacheEntry toEntry(int stage, CanonicalTreeParser i)