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

public Class DirCacheEditor

extends BaseDirCacheEditor
Class Inheritance
Static Imports
org.eclipse.jgit.dircache.DirCache.cmp, .DirCacheTree.peq, org.eclipse.jgit.lib.FileMode.TYPE_TREE

Updates a org.eclipse.jgit.dircache.DirCache by supplying discrete edit commands.

An editor updates a DirCache by taking a list of org.eclipse.jgit.dircache.DirCacheEditor.PathEdit commands 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 than org.eclipse.jgit.dircache.DirCacheBuilder.

See Also
DirCacheBuilder

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
DirCacheEditor.DeletePath

Deletes a single file entry from the index.

public static class
DirCacheEditor.DeleteTree

Recursively deletes all paths under a subtree.

public abstract static class
DirCacheEditor.PathEdit

Any index record update.

Field Summary

Modifier and TypeField and Description
private static final Comparator<DirCacheEditor.PathEdit>
private int
private final List<DirCacheEditor.PathEdit>
Inherited from org.eclipse.jgit.dircache.BaseDirCacheEditor:
cacheentriesentryCnt

Constructor Summary

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

Construct a new editor.

Method Summary

Modifier and TypeMethod and Description
public void
add(DirCacheEditor.PathEdit
another edit command.
edit
)

Append one edit command to the list of commands to be applied.

private void
public boolean
commit()

Overrides org.eclipse.jgit.dircache.BaseDirCacheEditor.commit.

Finish, write, commit this change, and release the index lock.

private int
private int
findEntry(byte[] p, int pLen)

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
inDir(DirCacheEntry e, byte[] path, int pLen)

private void
private static int
pdir(byte[] path, int e)

Inherited from org.eclipse.jgit.dircache.BaseDirCacheEditor:
fastAddfastKeepgetDirCachereplace

Field Detail

EDIT_CMPback to summary
private static final Comparator<DirCacheEditor.PathEdit> EDIT_CMP
editIdxback to summary
private int editIdx
editsback to summary
private final List<DirCacheEditor.PathEdit> edits

Constructor Detail

DirCacheEditorback to summary
protected DirCacheEditor(DirCache dc, int ecnt)

Construct a new editor.

Parameters
dc:DirCache

the cache this editor will eventually update.

ecnt:int

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

Method Detail

addback to summary
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:DirCacheEditor.PathEdit

another edit command.

applyEditsback to summary
private void applyEdits()
commitback to summary
public boolean commit() throws IOException

Overrides org.eclipse.jgit.dircache.BaseDirCacheEditor.commit.

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

Finish, 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.

Returns:boolean

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.

Annotations
@Override
Exceptions
IOException:
the output file could not be created. The caller no longer holds the lock.
deleteOverlappingSubtreeback to summary
private int deleteOverlappingSubtree(DirCacheEntry ent, int eIdx)
findEntryback to summary
private int findEntry(byte[] p, int pLen)
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
inDirback to summary
private static boolean inDir(DirCacheEntry e, byte[] path, int pLen)
insertEditback to summary
private void insertEdit(DirCacheEditor.DeleteTree d)
pdirback to summary
private static int pdir(byte[] path, int e)
org.eclipse.jgit.dircache back to summary

public final Class DirCacheEditor.DeletePath

extends PathEdit
Class Inheritance

Deletes a single file entry from the index.

This deletion command removes only a single file at the given location, but removes multiple stages (if present) for that path. To remove a complete subtree use DeleteTree instead.

See Also
DeleteTree

Field Summary

Inherited from org.eclipse.jgit.dircache.DirCacheEditor.PathEdit:
pathreplace

Constructor Summary

AccessConstructor and Description
public
DeletePath(String
path of the file within the repository.
entryPath
)

Create a new deletion command by path name.

public
DeletePath(DirCacheEntry
entry instance to remove. Only the path of this entry is actually considered during command evaluation.
ent
)

Create a new deletion command for an existing entry instance.

Method Summary

Modifier and TypeMethod and Description
public void
apply(DirCacheEntry
the entry being processed. All fields are zeroed out if the path is a new path in the index.
ent
)

Implements abstract org.eclipse.jgit.dircache.DirCacheEditor.PathEdit.apply.

Apply the update to a single cache entry matching the path.

Inherited from org.eclipse.jgit.dircache.DirCacheEditor.PathEdit:
setReplacetoString

Constructor Detail

DeletePathback to summary
public DeletePath(String entryPath)

Create a new deletion command by path name.

Parameters
entryPath:String

path of the file within the repository.

DeletePathback to summary
public DeletePath(DirCacheEntry ent)

Create a new deletion command for an existing entry instance.

Parameters
ent:DirCacheEntry

entry instance to remove. Only the path of this entry is actually considered during command evaluation.

Method Detail

applyback to summary
public void apply(DirCacheEntry ent)

Implements abstract org.eclipse.jgit.dircache.DirCacheEditor.PathEdit.apply.

Doc from org.eclipse.jgit.dircache.DirCacheEditor.PathEdit.apply.

Apply the update to a single cache entry matching the path.

After apply is invoked the entry is added to the output table, and will be included in the new index.

Parameters
ent:DirCacheEntry

the entry being processed. All fields are zeroed out if the path is a new path in the index.

Annotations
@Override
org.eclipse.jgit.dircache back to summary

public final Class DirCacheEditor.DeleteTree

extends PathEdit
Class Inheritance

Recursively deletes all paths under a subtree.

This deletion command is more generic than DeletePath as it can remove all records which appear recursively under the same subtree. Multiple stages are removed (if present) for any deleted entry.

This command will not remove a single file entry. To remove a single file use DeletePath.

See Also
DeletePath

Field Summary

Inherited from org.eclipse.jgit.dircache.DirCacheEditor.PathEdit:
pathreplace

Constructor Summary

AccessConstructor and Description
public
DeleteTree(String
path of the subtree within the repository. If the path does not end with "/" a "/" is implicitly added to ensure only the subtree's contents are matched by the command. The special case "" (not "/"!) deletes all entries.
entryPath
)

Create a new tree deletion command by path name.

pack-priv
DeleteTree(byte[] path)

Method Summary

Modifier and TypeMethod and Description
private static byte[]
appendSlash(byte[] path)

public void
apply(DirCacheEntry
the entry being processed. All fields are zeroed out if the path is a new path in the index.
ent
)

Implements abstract org.eclipse.jgit.dircache.DirCacheEditor.PathEdit.apply.

Apply the update to a single cache entry matching the path.

Inherited from org.eclipse.jgit.dircache.DirCacheEditor.PathEdit:
setReplacetoString

Constructor Detail

DeleteTreeback to summary
public DeleteTree(String entryPath)

Create a new tree deletion command by path name.

Parameters
entryPath:String

path of the subtree within the repository. If the path does not end with "/" a "/" is implicitly added to ensure only the subtree's contents are matched by the command. The special case "" (not "/"!) deletes all entries.

DeleteTreeback to summary
pack-priv DeleteTree(byte[] path)

Method Detail

appendSlashback to summary
private static byte[] appendSlash(byte[] path)
applyback to summary
public void apply(DirCacheEntry ent)

Implements abstract org.eclipse.jgit.dircache.DirCacheEditor.PathEdit.apply.

Doc from org.eclipse.jgit.dircache.DirCacheEditor.PathEdit.apply.

Apply the update to a single cache entry matching the path.

After apply is invoked the entry is added to the output table, and will be included in the new index.

Parameters
ent:DirCacheEntry

the entry being processed. All fields are zeroed out if the path is a new path in the index.

Annotations
@Override
org.eclipse.jgit.dircache back to summary

public abstract Class DirCacheEditor.PathEdit

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.dircache.DirCacheEditor.DeletePath, org.eclipse.jgit.dircache.DirCacheEditor.DeleteTree

Any index record update.

Applications should subclass and provide their own implementation for the apply(DirCacheEntry) method. The editor will invoke apply once for each record in the index which matches the path name. If there are multiple records (for example in stages 1, 2 and 3), the edit instance will be called multiple times, once for each stage. If any of these calls resets the stage to 0, only this entry will be taken and entries for other stages are discarded.

Field Summary

Modifier and TypeField and Description
pack-priv final byte[]
pack-priv boolean

Constructor Summary

AccessConstructor and Description
public
PathEdit(String
path of the file within the repository.
entryPath
)

Create a new update command by path name.

pack-priv
PathEdit(byte[] path)

public
PathEdit(DirCacheEntry
entry instance to match path of. Only the path of this entry is actually considered during command evaluation.
ent
)

Create a new update command for an existing entry instance.

Method Summary

Modifier and TypeMethod and Description
public abstract void
apply(DirCacheEntry
the entry being processed. All fields are zeroed out if the path is a new path in the index.
ent
)

Apply the update to a single cache entry matching the path.

public DirCacheEditor.PathEdit

Returns:

this
setReplace
(boolean
if true a file can replace a directory, or a directory can replace a file.
ok
)

Configure if a file can replace a directory (or vice versa).

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

pathback to summary
pack-priv final byte[] path
replaceback to summary
pack-priv boolean replace

Constructor Detail

PathEditback to summary
public PathEdit(String entryPath)

Create a new update command by path name.

Parameters
entryPath:String

path of the file within the repository.

PathEditback to summary
pack-priv PathEdit(byte[] path)
PathEditback to summary
public PathEdit(DirCacheEntry ent)

Create a new update command for an existing entry instance.

Parameters
ent:DirCacheEntry

entry instance to match path of. Only the path of this entry is actually considered during command evaluation.

Method Detail

applyback to summary
public abstract void apply(DirCacheEntry ent)

Apply the update to a single cache entry matching the path.

After apply is invoked the entry is added to the output table, and will be included in the new index.

Parameters
ent:DirCacheEntry

the entry being processed. All fields are zeroed out if the path is a new path in the index.

setReplaceback to summary
public DirCacheEditor.PathEdit setReplace(boolean ok)

Configure if a file can replace a directory (or vice versa).

Default is true as this is usually the desired behavior.

Parameters
ok:boolean

if true a file can replace a directory, or a directory can replace a file.

Returns:DirCacheEditor.PathEdit

this

Since
4.2
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override