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

pack-priv abstract Class BaseDirCacheEditor

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.dircache.DirCacheBuilder, org.eclipse.jgit.dircache.DirCacheEditor
Static Imports
org.eclipse.jgit.lib.FileMode.TYPE_TREE, org.eclipse.jgit.util.Paths.compareSameName

Generic update/editing support for DirCache.

The different update strategies extend this class to provide their own unique services to applications.

Field Summary

Modifier and TypeField and Description
protected DirCache
protected DirCacheEntry[]
protected int
entryCnt

Total number of valid entries in BaseDirCacheEditor#entries.

Constructor Summary

AccessConstructor and Description
protected
BaseDirCacheEditor(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
private void
public boolean

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.
commit
()

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

protected void
fastAdd(DirCacheEntry
the new entry to add.
newEntry
)

Append one entry into the resulting entry list.

protected void
fastKeep(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.

public abstract void
finish()

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

public DirCache

Returns:

the cache we will update on finish().
getDirCache
()

Get the DirCache

private static int
lastSlash(byte[] path)

private static int
nextSlash(byte[] b, int p)

protected void
replace()

Update the DirCache with the contents of BaseDirCacheEditor#entries.

private static boolean
startsWith(byte[] a, byte[] b, int n)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheback to summary
protected DirCache cache
Annotations
@SuppressWarnings:doclint:missing
entriesback to summary
protected DirCacheEntry[] entries
Annotations
@SuppressWarnings:doclint:missing
entryCntback to summary
protected int entryCnt

Total number of valid entries in BaseDirCacheEditor#entries.

Constructor Detail

BaseDirCacheEditorback to summary
protected BaseDirCacheEditor(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

checkNameConflictsback to summary
private void checkNameConflicts()
commitback to summary
public boolean commit() throws IOException

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.

Exceptions
IOException:
the output file could not be created. The caller no longer holds the lock.
IllegalStateException:
the lock is not held.
fastAddback to summary
protected void fastAdd(DirCacheEntry newEntry)

Append one entry into the resulting entry list.

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.

Parameters
newEntry:DirCacheEntry

the new entry to add.

fastKeepback to summary
protected void fastKeep(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, 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.

Parameters
pos:int

first entry to copy from the destination cache.

cnt:int

number of entries to copy.

finishback to summary
public abstract void 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.

getDirCacheback to summary
public DirCache getDirCache()

Get the DirCache

Returns:DirCache

the cache we will update on finish().

lastSlashback to summary
private static int lastSlash(byte[] path)
nextSlashback to summary
private static int nextSlash(byte[] b, int p)
replaceback to summary
protected void replace()

Update the DirCache with the contents of BaseDirCacheEditor#entries.

This method should be invoked only during an implementation of finish(), and only after entries is sorted.

startsWithback to summary
private static boolean startsWith(byte[] a, byte[] b, int n)