Class DirCacheEditor
- java.lang.Object
-
- org.eclipse.jgit.dircache.BaseDirCacheEditor
-
- org.eclipse.jgit.dircache.DirCacheEditor
-
public class DirCacheEditor extends BaseDirCacheEditor
Updates aDirCacheby supplying discrete edit commands.An editor updates a DirCache by taking a list of
DirCacheEditor.PathEditcommands and executing them against the entries of the destination cache to produce a new cache. This edit style allows applications to insert a few commands and then have the editor compute the proper entry indexes necessary to perform an efficient in-order update of the index records. This can be easier to use thanDirCacheBuilder.- See Also:
DirCacheBuilder
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDirCacheEditor.DeletePathDeletes a single file entry from the index.static classDirCacheEditor.DeleteTreeRecursively deletes all paths under a subtree.static classDirCacheEditor.PathEditAny index record update.
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Comparator<DirCacheEditor.PathEdit>EDIT_CMPprivate inteditIdxprivate java.util.List<DirCacheEditor.PathEdit>edits-
Fields inherited from class org.eclipse.jgit.dircache.BaseDirCacheEditor
cache, entries, entryCnt
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDirCacheEditor(DirCache dc, int ecnt)Construct a new editor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(DirCacheEditor.PathEdit edit)Append one edit command to the list of commands to be applied.private voidapplyEdits()booleancommit()Finish, write, commit this change, and release the index lock.private intdeleteOverlappingSubtree(DirCacheEntry ent, int eIdx)private intfindEntry(byte[] p, int pLen)voidfinish()Finish this builder and update the destinationDirCache.private static booleaninDir(DirCacheEntry e, byte[] path, int pLen)private voidinsertEdit(DirCacheEditor.DeleteTree d)private static intpdir(byte[] path, int e)-
Methods inherited from class org.eclipse.jgit.dircache.BaseDirCacheEditor
fastAdd, fastKeep, getDirCache, replace
-
-
-
-
Field Detail
-
EDIT_CMP
private static final java.util.Comparator<DirCacheEditor.PathEdit> EDIT_CMP
-
edits
private final java.util.List<DirCacheEditor.PathEdit> edits
-
editIdx
private int editIdx
-
-
Constructor Detail
-
DirCacheEditor
protected DirCacheEditor(DirCache dc, int ecnt)
Construct a new editor.- Parameters:
dc- the cache this editor will eventually update.ecnt- estimated number of entries the editor will have upon completion. This sizes the initial entry table.
-
-
Method Detail
-
add
public void add(DirCacheEditor.PathEdit edit)
Append one edit command to the list of commands to be applied.Edit commands may be added in any order chosen by the application. They are automatically rearranged by the builder to provide the most efficient update possible.
- Parameters:
edit- another edit command.
-
commit
public boolean commit() throws java.io.IOExceptionFinish, write, commit this change, and release the index lock.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.
- Overrides:
commitin classBaseDirCacheEditor- Returns:
- true if the commit was successful and the file contains the new data; false if the commit failed and the file remains with the old data.
- Throws:
java.io.IOException- the output file could not be created. The caller no longer holds the lock.
-
finish
public void finish()
Finish this builder and update the destinationDirCache.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
BaseDirCacheEditor.getDirCache()will contain all modifications.Note to implementors: Make sure
BaseDirCacheEditor.entriesis fully sorted then invokeBaseDirCacheEditor.replace()to update the DirCache with the new table.- Specified by:
finishin classBaseDirCacheEditor
-
applyEdits
private void applyEdits()
-
deleteOverlappingSubtree
private int deleteOverlappingSubtree(DirCacheEntry ent, int eIdx)
-
findEntry
private int findEntry(byte[] p, int pLen)
-
insertEdit
private void insertEdit(DirCacheEditor.DeleteTree d)
-
inDir
private static boolean inDir(DirCacheEntry e, byte[] path, int pLen)
-
pdir
private static int pdir(byte[] path, int e)
-
-