Top Description Inners Fields Constructors Methods
org.eclipse.jgit.internal.storage.file

pack-priv Class SnapshottingRefDirectory

extends RefDirectory
Class Inheritance
Imports
org.eclipse.jgit.lib.ProgressMonitor, .Ref, .RefUpdate, org.eclipse.jgit.revwalk.RevWalk, java.io.File, .IOException, .InputStream, java.nio.file.Files, .Path, java.util.List, .Set, java.util.concurrent.ConcurrentHashMap

Snapshotting write-through cache of a RefDirectory.

This is intended to be short-term write-through snapshot based cache used in a request scope to avoid re-reading packed-refs on each read and to avoid refreshing paths to a loose ref that has already been refreshed.

Only use this class when concurrent writes from other requests (not using the same instance of SnapshottingRefDirectory) generally need not be visible to the current request. The exception to this is when such writes would cause writes from this snapshot to fail due to their base ref value being outdated.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
private static class
private static class
private static class
private static interface
private static interface

Field Summary

Modifier and TypeField and Description
private volatile boolean
pack-priv final RefDirectory
private final Set<File>
Inherited from org.eclipse.jgit.internal.storage.file.RefDirectory:
inProcessPackedRefsLocklogsDirlogsRefsDirPACKED_REFS_HEADERPACKED_REFS_PEELEDpackedRefspackedRefsFilerefsDirSYMREF

Constructor Summary

AccessConstructor and Description
pack-priv
SnapshottingRefDirectory(RefDirectory
a reference to the ref database
refDb
)

Create a snapshotting write-through cache of a RefDirectory.

Method Summary

Modifier and TypeMethod and Description
pack-priv RefDirectoryRename
pack-priv RefDirectoryUpdate
pack-priv void
pack-priv RefDirectory.PackedRefList
getPackedRefs()

Overrides org.eclipse.jgit.internal.storage.file.RefDirectory.getPackedRefs.

Lazily initializes and returns a PackedRefList snapshot.

pack-priv synchronized void
private static <T> T
private static <A, R> R
private static <A1, A2, A3> void
public PackedBatchRefUpdate
newBatchUpdate()

Overrides org.eclipse.jgit.internal.storage.file.RefDirectory.newBatchUpdate.

Create a new batch update to attempt on this database.

public PackedBatchRefUpdate
newBatchUpdate(boolean
whether loose refs should be locked during the batch ref update. Note that this should only be set to false if the application using this ensures that no other ref updates run concurrently to avoid lost updates caused by a race. In such cases it can improve performance.
shouldLockLooseRefs
)

Overrides org.eclipse.jgit.internal.storage.file.RefDirectory.newBatchUpdate.

Create a new batch update to attempt on this database.

pack-priv RefDirectoryUpdate
newTemporaryUpdate()

Overrides org.eclipse.jgit.internal.storage.file.RefDirectory.newTemporaryUpdate.

Create a reference update to write a temporary reference.

public RefDirectoryUpdate
newUpdate(String
the name of the reference.
name
,
boolean
if true and name is currently a org.eclipse.jgit.lib.SymbolicRef, the update will replace it with an org.eclipse.jgit.lib.ObjectIdRef. Otherwise, the update will recursively traverse org.eclipse.jgit.lib.SymbolicRefs and operate on the leaf org.eclipse.jgit.lib.ObjectIdRef.
detach
)

Overrides org.eclipse.jgit.internal.storage.file.RefDirectory.newUpdate.

Create a new update command to create, modify or delete a reference.

pack-priv void
refreshPathToLooseRef(Path
path of a loose ref relative to the repository root
refPath
)

Overrides org.eclipse.jgit.internal.storage.file.RefDirectory.refreshPathToLooseRef.

Workaround for issues caused by NFS caching.

private synchronized void
refreshSnapshot()

Refresh our snapshot by calling the underlying RefDirectory's getPackedRefs().

Inherited from org.eclipse.jgit.internal.storage.file.RefDirectory:
closecommitPackedRefscompareAndSetPackedRefscreatecreateSnapshottingRefDirectorydeleteexactRefexactReffileForfireRefsChangedfirstExactRefgetAdditionalRefsgetReflogReadergetRefsgetRefsByPrefixgetRepositorygetRetrySleepMsisInCloneisNameConflictinglevelsInlockPackedRefslockPackedRefsOrThrowloglogFornewLogWriternewRenamepackpackpackRefspeelperformsAtomicTransactionsrefreshrefreshPackedRefsscanRefsetRetrySleepMssleepstoredstoredSymbolicRef

Field Detail

isValidback to summary
private volatile boolean isValid
refDbback to summary
pack-priv final RefDirectory refDb
refreshedLooseRefDirsback to summary
private final Set<File> refreshedLooseRefDirs

Constructor Detail

SnapshottingRefDirectoryback to summary
pack-priv SnapshottingRefDirectory(RefDirectory refDb)

Create a snapshotting write-through cache of a RefDirectory.

Parameters
refDb:RefDirectory

a reference to the ref database

Method Detail

createRefDirectoryRenameback to summary
pack-priv RefDirectoryRename createRefDirectoryRename(RefDirectoryUpdate from, RefDirectoryUpdate to)

Overrides org.eclipse.jgit.internal.storage.file.RefDirectory.createRefDirectoryRename.

Annotations
@Override
createRefDirectoryUpdateback to summary
pack-priv RefDirectoryUpdate createRefDirectoryUpdate(Ref ref)

Overrides org.eclipse.jgit.internal.storage.file.RefDirectory.createRefDirectoryUpdate.

Annotations
@Override
deleteback to summary
pack-priv void delete(RefDirectoryUpdate update) throws IOException

Overrides org.eclipse.jgit.internal.storage.file.RefDirectory.delete.

Annotations
@Override
getPackedRefsback to summary
pack-priv RefDirectory.PackedRefList getPackedRefs() throws IOException

Overrides org.eclipse.jgit.internal.storage.file.RefDirectory.getPackedRefs.

Lazily initializes and returns a PackedRefList snapshot.

A newer snapshot will be returned when a ref update is performed using this SnapshottingRefDirectory.

Annotations
@Override
invalidateSnapshotback to summary
pack-priv synchronized void invalidateSnapshot()
invalidateSnapshotOnErrorback to summary
private static <T> T invalidateSnapshotOnError(SnapshottingRefDirectory.SupplierThrowsException<T, IOException> f, SnapshottingRefDirectory refDb) throws IOException
invalidateSnapshotOnErrorback to summary
private static <A, R> R invalidateSnapshotOnError(SnapshottingRefDirectory.FunctionThrowsException<A, R, IOException> f, A a, SnapshottingRefDirectory refDb) throws IOException
invalidateSnapshotOnErrorback to summary
private static <A1, A2, A3> void invalidateSnapshotOnError(SnapshottingRefDirectory.TriConsumerThrowsException<A1, A2, A3, IOException> f, A1 a1, A2 a2, A3 a3, SnapshottingRefDirectory refDb) throws IOException
newBatchUpdateback to summary
public PackedBatchRefUpdate newBatchUpdate()

Overrides org.eclipse.jgit.internal.storage.file.RefDirectory.newBatchUpdate.

Doc from org.eclipse.jgit.lib.RefDatabase.newBatchUpdate.

Create a new batch update to attempt on this database.

The default implementation performs a sequential update of each command.

Returns:PackedBatchRefUpdate

a new batch update object.

Annotations
@Override
newBatchUpdateback to summary
public PackedBatchRefUpdate newBatchUpdate(boolean shouldLockLooseRefs)

Overrides org.eclipse.jgit.internal.storage.file.RefDirectory.newBatchUpdate.

Doc from org.eclipse.jgit.internal.storage.file.RefDirectory.newBatchUpdate.

Create a new batch update to attempt on this database.

Parameters
shouldLockLooseRefs:boolean

whether loose refs should be locked during the batch ref update. Note that this should only be set to false if the application using this ensures that no other ref updates run concurrently to avoid lost updates caused by a race. In such cases it can improve performance.

Returns:PackedBatchRefUpdate

a new batch update object

Annotations
@Override
newTemporaryUpdateback to summary
pack-priv RefDirectoryUpdate newTemporaryUpdate() throws IOException

Overrides org.eclipse.jgit.internal.storage.file.RefDirectory.newTemporaryUpdate.

Doc from org.eclipse.jgit.internal.storage.file.RefDirectory.newTemporaryUpdate.

Create a reference update to write a temporary reference.

Returns:RefDirectoryUpdate

an update for a new temporary reference.

Annotations
@Override
Exceptions
IOException:
a temporary name cannot be allocated.
newUpdateback to summary
public RefDirectoryUpdate newUpdate(String name, boolean detach) throws IOException

Overrides org.eclipse.jgit.internal.storage.file.RefDirectory.newUpdate.

Doc from org.eclipse.jgit.lib.RefDatabase.newUpdate.

Create a new update command to create, modify or delete a reference.

Parameters
name:String

the name of the reference.

detach:boolean

if true and name is currently a org.eclipse.jgit.lib.SymbolicRef, the update will replace it with an org.eclipse.jgit.lib.ObjectIdRef. Otherwise, the update will recursively traverse org.eclipse.jgit.lib.SymbolicRefs and operate on the leaf org.eclipse.jgit.lib.ObjectIdRef.

Returns:RefDirectoryUpdate

a new update for the requested name; never null.

Annotations
@Override
Exceptions
IOException:
the reference space cannot be accessed.
refreshPathToLooseRefback to summary
pack-priv void refreshPathToLooseRef(Path refPath)

Overrides org.eclipse.jgit.internal.storage.file.RefDirectory.refreshPathToLooseRef.

Doc from org.eclipse.jgit.internal.storage.file.RefDirectory.refreshPathToLooseRef.

Workaround for issues caused by NFS caching. Refresh directories starting from the repository root to a loose ref by opening an input stream. This refreshes file attributes of the loose ref (at least on some NFS clients).

Parameters
refPath:Path

path of a loose ref relative to the repository root

Annotations
@Override
refreshSnapshotback to summary
private synchronized void refreshSnapshot() throws IOException

Refresh our snapshot by calling the underlying RefDirectory's getPackedRefs().

Update the in-memory copy of the underlying RefDirectory's packed-refs to avoid the overhead of re-reading packed-refs on each new snapshot as the packed-refs of the underlying RefDirectory may not get updated if most threads use this snapshot.

Exceptions
IOException:
if an IO error occurred
org.eclipse.jgit.internal.storage.file back to summary

private Interface SnapshottingRefDirectory.FunctionThrowsException<A, R, E extends Exception>

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public R
apply(A a)

Method Detail

applyback to summary
public R apply(A a) throws FunctionThrowsException:E
org.eclipse.jgit.internal.storage.file back to summary

private Class SnapshottingRefDirectory.SnapshotPackedBatchRefUpdate

extends PackedBatchRefUpdate
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
SnapshotPackedBatchRefUpdate(RefDirectory refDb, boolean shouldLockLooseRefs)

Method Summary

Modifier and TypeMethod and Description
public void
execute(RevWalk
a RevWalk to parse tags in case the storage system wants to store them pre-peeled, a common performance optimization.
walk
,
ProgressMonitor
progress monitor to receive update status on.
monitor
,
List<String>
a list of option strings; set null to execute without
options
)

Overrides org.eclipse.jgit.internal.storage.file.PackedBatchRefUpdate.execute.

Execute this batch update.

public void
execute(RevWalk
a RevWalk to parse tags in case the storage system wants to store them pre-peeled, a common performance optimization.
walk
,
ProgressMonitor
progress monitor to receive update status on.
monitor
)

Overrides org.eclipse.jgit.lib.BatchRefUpdate.execute.

Execute this batch update without option strings.

public SnapshottingRefDirectory
getRefDatabase()

Overrides org.eclipse.jgit.lib.BatchRefUpdate.getRefDatabase.

Get the ref database associated with this update.

Constructor Detail

SnapshotPackedBatchRefUpdateback to summary
pack-priv SnapshotPackedBatchRefUpdate(RefDirectory refDb)
SnapshotPackedBatchRefUpdateback to summary
pack-priv SnapshotPackedBatchRefUpdate(RefDirectory refDb, boolean shouldLockLooseRefs)

Method Detail

executeback to summary
public void execute(RevWalk walk, ProgressMonitor monitor, List<String> options) throws IOException

Overrides org.eclipse.jgit.internal.storage.file.PackedBatchRefUpdate.execute.

Doc from org.eclipse.jgit.lib.BatchRefUpdate.execute.

Execute this batch update.

The default implementation of this method performs a sequential reference update over each reference.

Implementations must respect the atomicity requirements of the underlying database as described in setAtomic(boolean) and org.eclipse.jgit.lib.RefDatabase#performsAtomicTransactions().

Parameters
walk:RevWalk

a RevWalk to parse tags in case the storage system wants to store them pre-peeled, a common performance optimization.

monitor:ProgressMonitor

progress monitor to receive update status on.

options:List<String>

a list of option strings; set null to execute without

Annotations
@Override
Exceptions
IOException:
the database is unable to accept the update. Individual command status must be tested to determine if there is a partial failure, or a total failure.
executeback to summary
public void execute(RevWalk walk, ProgressMonitor monitor) throws IOException

Overrides org.eclipse.jgit.lib.BatchRefUpdate.execute.

Doc from org.eclipse.jgit.lib.BatchRefUpdate.execute.

Execute this batch update without option strings.

Parameters
walk:RevWalk

a RevWalk to parse tags in case the storage system wants to store them pre-peeled, a common performance optimization.

monitor:ProgressMonitor

progress monitor to receive update status on.

Annotations
@Override
Exceptions
IOException:
the database is unable to accept the update. Individual command status must be tested to determine if there is a partial failure, or a total failure.
getRefDatabaseback to summary
public SnapshottingRefDirectory getRefDatabase()

Overrides org.eclipse.jgit.lib.BatchRefUpdate.getRefDatabase.

Doc from org.eclipse.jgit.lib.BatchRefUpdate.getRefDatabase.

Get the ref database associated with this update.

Returns:SnapshottingRefDirectory

the ref database.

Annotations
@Override
org.eclipse.jgit.internal.storage.file back to summary

private Class SnapshottingRefDirectory.SnapshotRefDirectoryRename

extends RefDirectoryRename
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public SnapshottingRefDirectory
getRefDirectory()

Overrides org.eclipse.jgit.internal.storage.file.RefDirectoryRename.getRefDirectory.

Get the ref directory associated with this rename.

public RefUpdate.Result
Inherited from org.eclipse.jgit.internal.storage.file.RefDirectoryRename:
doRename

Constructor Detail

SnapshotRefDirectoryRenameback to summary
pack-priv SnapshotRefDirectoryRename(RefDirectoryUpdate src, RefDirectoryUpdate dst)

Method Detail

getRefDirectoryback to summary
public SnapshottingRefDirectory getRefDirectory()

Overrides org.eclipse.jgit.internal.storage.file.RefDirectoryRename.getRefDirectory.

Doc from org.eclipse.jgit.internal.storage.file.RefDirectoryRename.getRefDirectory.

Get the ref directory associated with this rename.

Returns:SnapshottingRefDirectory

the ref directory.

Annotations
@Override
renameback to summary
public RefUpdate.Result rename() throws IOException

Overrides org.eclipse.jgit.lib.RefRename.rename.

Doc from org.eclipse.jgit.lib.RefRename.rename.

Rename

Returns:RefUpdate.Result

the result of the new ref update

Annotations
@Override
Exceptions
IOException:
if an IO error occurred
org.eclipse.jgit.internal.storage.file back to summary

private Class SnapshottingRefDirectory.SnapshotRefDirectoryUpdate

extends RefDirectoryUpdate
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public RefUpdate.Result
delete()

Overrides org.eclipse.jgit.lib.RefUpdate.delete.

Delete the ref.

public RefUpdate.Result
delete(RevWalk
a RevWalk instance this delete command can borrow to perform the merge test. The walk will be reset to perform the test.
walk
)

Overrides org.eclipse.jgit.lib.RefUpdate.delete.

Delete the ref.

protected void
doAfterLocking(String
the name of the reference.
name
)

Overrides org.eclipse.jgit.internal.storage.file.RefDirectoryUpdate.doAfterLocking.

Invalidate the SnapshottingRefDirectory snapshot after locking the ref.

public RefUpdate.Result
forceUpdate()

Overrides org.eclipse.jgit.lib.RefUpdate.forceUpdate.

Force the ref to take the new value.

public SnapshottingRefDirectory
getRefDatabase()

Overrides org.eclipse.jgit.internal.storage.file.RefDirectoryUpdate.getRefDatabase.

Get the reference database this update modifies.

public RefUpdate.Result
update()

Overrides org.eclipse.jgit.lib.RefUpdate.update.

Gracefully update the ref to the new value.

public RefUpdate.Result
update(RevWalk
a RevWalk instance this update command can borrow to perform the merge test. The walk will be reset to perform the test.
walk
)

Overrides org.eclipse.jgit.lib.RefUpdate.update.

Gracefully update the ref to the new value.

Inherited from org.eclipse.jgit.internal.storage.file.RefDirectoryUpdate:
doDeletedoLinkdoUpdategetRepositorytryLockunlock

Constructor Detail

SnapshotRefDirectoryUpdateback to summary
pack-priv SnapshotRefDirectoryUpdate(RefDirectory r, Ref ref)

Method Detail

deleteback to summary
public RefUpdate.Result delete() throws IOException

Overrides org.eclipse.jgit.lib.RefUpdate.delete.

Doc from org.eclipse.jgit.lib.RefUpdate.delete.

Delete the ref.

This is the same as:

return delete(new RevWalk(getRepository()));
Returns:RefUpdate.Result

the result status of the delete.

Annotations
@Override
Exceptions
IOException:
if an IO error occurred
deleteback to summary
public RefUpdate.Result delete(RevWalk walk) throws IOException

Overrides org.eclipse.jgit.lib.RefUpdate.delete.

Doc from org.eclipse.jgit.lib.RefUpdate.delete.

Delete the ref.

Parameters
walk:RevWalk

a RevWalk instance this delete command can borrow to perform the merge test. The walk will be reset to perform the test.

Returns:RefUpdate.Result

the result status of the delete.

Annotations
@Override
Exceptions
IOException:
if an IO error occurred
doAfterLockingback to summary
protected void doAfterLocking(String name)

Overrides org.eclipse.jgit.internal.storage.file.RefDirectoryUpdate.doAfterLocking.

Invalidate the SnapshottingRefDirectory snapshot after locking the ref.

Doing this after locking the ref ensures that the upcoming write is not based on a cached value.

Parameters
name:String

the name of the reference.

Annotations
@Override
forceUpdateback to summary
public RefUpdate.Result forceUpdate() throws IOException

Overrides org.eclipse.jgit.lib.RefUpdate.forceUpdate.

Doc from org.eclipse.jgit.lib.RefUpdate.forceUpdate.

Force the ref to take the new value.

This is just a convenient helper for setting the force flag, and as such the merge test is performed.

Returns:RefUpdate.Result

the result status of the update.

Annotations
@Override
Exceptions
IOException:
an unexpected IO error occurred while writing changes.
getRefDatabaseback to summary
public SnapshottingRefDirectory getRefDatabase()

Overrides org.eclipse.jgit.internal.storage.file.RefDirectoryUpdate.getRefDatabase.

Doc from org.eclipse.jgit.lib.RefUpdate.getRefDatabase.

Get the reference database this update modifies.

Returns:SnapshottingRefDirectory

the reference database this update modifies.

Annotations
@Override
updateback to summary
public RefUpdate.Result update() throws IOException

Overrides org.eclipse.jgit.lib.RefUpdate.update.

Doc from org.eclipse.jgit.lib.RefUpdate.update.

Gracefully update the ref to the new value.

Merge test will be performed according to isForceUpdate().

This is the same as:

return update(new RevWalk(getRepository()));
Returns:RefUpdate.Result

the result status of the update.

Annotations
@Override
Exceptions
IOException:
an unexpected IO error occurred while writing changes.
updateback to summary
public RefUpdate.Result update(RevWalk walk) throws IOException

Overrides org.eclipse.jgit.lib.RefUpdate.update.

Doc from org.eclipse.jgit.lib.RefUpdate.update.

Gracefully update the ref to the new value.

Merge test will be performed according to isForceUpdate().

Parameters
walk:RevWalk

a RevWalk instance this update command can borrow to perform the merge test. The walk will be reset to perform the test.

Returns:RefUpdate.Result

the result status of the update.

Annotations
@Override
Exceptions
IOException:
an unexpected IO error occurred while writing changes.
org.eclipse.jgit.internal.storage.file back to summary

private Interface SnapshottingRefDirectory.SupplierThrowsException<R, E extends Exception>

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public R
call()

Method Detail

callback to summary
public R call() throws SupplierThrowsException:E
org.eclipse.jgit.internal.storage.file back to summary

private Interface SnapshottingRefDirectory.TriConsumerThrowsException<A1, A2, A3, E extends Exception>

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public void
accept(A1 a1, A2 a2, A3 a3)

Method Detail

acceptback to summary
public void accept(A1 a1, A2 a2, A3 a3) throws TriConsumerThrowsException:E