|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.jgit.dircache.DirCacheBuilder
public class DirCacheBuilder
Updates a DirCache
by adding individual DirCacheEntry
s.
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.
DirCacheEditor
Field Summary | |
---|---|
protected DirCache |
cache
The cache instance this editor updates during finish() . |
protected DirCacheEntry[] |
entries
Entry table this builder will eventually replace into cache . |
protected int |
entryCnt
Total number of valid entries in entries . |
Constructor Summary | |
---|---|
protected |
DirCacheBuilder(DirCache dc,
int ecnt)
Construct a new builder. |
Method Summary | |
---|---|
void |
add(DirCacheEntry newEntry)
Append one entry into the resulting entry list. |
void |
addTree(byte[] pathPrefix,
int stage,
ObjectReader reader,
AnyObjectId tree)
Recursively add an entire tree into this builder. |
boolean |
commit()
Finish, write, commit this change, and release the index lock. |
protected void |
fastAdd(DirCacheEntry newEntry)
Append one entry into the resulting entry list. |
protected void |
fastKeep(int pos,
int cnt)
Add a range of existing entries from the destination cache. |
void |
finish()
Finish this builder and update the destination DirCache . |
DirCache |
getDirCache()
|
void |
keep(int pos,
int cnt)
Add a range of existing entries from the destination cache. |
protected void |
replace()
Update the DirCache with the contents of entries . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected DirCache cache
finish()
.
protected DirCacheEntry[] entries
cache
.
Use fastAdd(DirCacheEntry)
or fastKeep(int, int)
to
make additions to this table. The table is automatically expanded if it
is too small for a new addition.
Typically the entries in here are sorted by their path names, just like they are in the DirCache instance.
protected int entryCnt
entries
.
Constructor Detail |
---|
protected DirCacheBuilder(DirCache dc, int ecnt)
dc
- the cache this builder will eventually update.ecnt
- estimated number of entries the builder will have upon
completion. This sizes the initial entry table.Method Detail |
---|
public void add(DirCacheEntry newEntry)
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.
newEntry
- the new entry to add.
IllegalArgumentException
- If the FileMode of the entry was not set by the caller.public void keep(int pos, int cnt)
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.
pos
- first entry to copy from the destination cache.cnt
- number of entries to copy.public void addTree(byte[] pathPrefix, int stage, ObjectReader reader, AnyObjectId tree) throws IOException
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.
pathPrefix
- 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
- stage of the entries when adding them.reader
- 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
- 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).
IOException
- a tree cannot be read to iterate through its entries.public void finish()
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.
public DirCache getDirCache()
finish()
.protected void fastAdd(DirCacheEntry newEntry)
The entry is placed at the end of the entry list. The caller is responsible for making sure the final table is correctly sorted.
The entries
table is automatically expanded if there is
insufficient space for the new addition.
newEntry
- the new entry to add.protected void fastKeep(int pos, int cnt)
The entries are placed at the end of the entry list, preserving their current order. The caller is responsible for making sure the final table is correctly sorted.
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 entries
table is automatically expanded if there is
insufficient space for the new additions.
pos
- first entry to copy from the destination cache.cnt
- number of entries to copy.protected void replace()
entries
.
This method should be invoked only during an implementation of
finish()
, and only after entries
is sorted.
public boolean commit() throws IOException
If this method fails (returns false) the lock is still released.
This is a utility method for applications as the finish-write-commit pattern is very common after using a builder to update entries.
IllegalStateException
- the lock is not held.
IOException
- the output file could not be created. The caller no longer
holds the lock.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |