Class RefTreeDatabase
- java.lang.Object
-
- org.eclipse.jgit.lib.RefDatabase
-
- org.eclipse.jgit.internal.storage.reftree.RefTreeDatabase
-
public class RefTreeDatabase extends RefDatabase
Reference database backed by aRefTree.The storage for RefTreeDatabase has two parts. The main part is a native Git tree object stored under the
refs/txnnamespace. To avoid cycles, references torefs/txnare not stored in that tree object, but instead in a "bootstrap" layer, which is a separateRefDatabasesuch asRefDirectoryusing local reference files inside of$GIT_DIR/refs.
-
-
Field Summary
Fields Modifier and Type Field Description private RefDatabasebootstrapprivate Scanner.Resultrefsprivate Repositoryrepoprivate java.lang.StringtxnCommittedprivate java.lang.StringtxnNamespace-
Fields inherited from class org.eclipse.jgit.lib.RefDatabase
ALL, MAX_SYMBOLIC_REF_DEPTH, SEARCH_PATH
-
-
Constructor Summary
Constructors Constructor Description RefTreeDatabase(Repository repo, RefDatabase bootstrap)Create a RefTreeDb for a repository.RefTreeDatabase(Repository repo, RefDatabase bootstrap, java.lang.String txnCommitted)Create a RefTreeDb for a repository.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close any resources held by this database.(package private) booleanconflictsWithBootstrap(java.lang.String name)voidcreate()Initialize a new reference database at this location.RefexactRef(java.lang.String name)Read a single reference.java.util.List<Ref>getAdditionalRefs()Get the additional reference-like entities from the repository.RefDatabasegetBootstrap()Get the bootstrap reference databasejava.util.Map<java.lang.String,Ref>getRefs(java.lang.String prefix)Get a section of the reference namespace.(package private) RepositorygetRepository()java.lang.StringgetTxnCommitted()Get name of bootstrap reference anchoring committed RefTree.java.lang.StringgetTxnNamespace()Get namespace used by bootstrap layer.private static ObjectIdidOf(Ref src)private static java.lang.StringinitNamespace(java.lang.String committed)booleanisNameConflicting(java.lang.String name)Determine if a proposed reference name overlaps with an existing one.BatchRefUpdatenewBatchUpdate()Create a new batch update to attempt on this database.RefRenamenewRename(java.lang.String fromName, java.lang.String toName)Create a new update command to rename a reference.RefUpdatenewUpdate(java.lang.String name, boolean detach)Create a new update command to create, modify or delete a reference.Refpeel(Ref ref)Peel a possibly unpeeled reference by traversing the annotated tags.booleanperformsAtomicTransactions()Whether the database is capable of performing batch updates as atomic transactions.private static java.lang.StringprefixOf(java.lang.String name)private static Refrecreate(Ref old, Ref leaf)voidrefresh()Triggers a refresh of all internal data structures.-
Methods inherited from class org.eclipse.jgit.lib.RefDatabase
exactRef, findRef, findRef, firstExactRef, getConflictingNames, getRef, getRefs, getRefsByPrefix, getRefsByPrefix, getTipsWithSha1, hasFastTipsWithSha1, hasRefs, hasVersioning
-
-
-
-
Field Detail
-
repo
private final Repository repo
-
bootstrap
private final RefDatabase bootstrap
-
txnCommitted
private final java.lang.String txnCommitted
-
txnNamespace
@Nullable private final java.lang.String txnNamespace
-
refs
private volatile Scanner.Result refs
-
-
Constructor Detail
-
RefTreeDatabase
public RefTreeDatabase(Repository repo, RefDatabase bootstrap)
Create a RefTreeDb for a repository.- Parameters:
repo- the repository using references in this database.bootstrap- bootstrap reference database storing the references that anchor theRefTree.
-
RefTreeDatabase
public RefTreeDatabase(Repository repo, RefDatabase bootstrap, java.lang.String txnCommitted)
Create a RefTreeDb for a repository.- Parameters:
repo- the repository using references in this database.bootstrap- bootstrap reference database storing the references that anchor theRefTree.txnCommitted- name of the bootstrap reference holding the committed RefTree.
-
-
Method Detail
-
initNamespace
private static java.lang.String initNamespace(java.lang.String committed)
-
getRepository
Repository getRepository()
-
getBootstrap
public RefDatabase getBootstrap()
Get the bootstrap reference database- Returns:
- the bootstrap reference database, which must be used to access
getTxnCommitted(),getTxnNamespace().
-
getTxnCommitted
public java.lang.String getTxnCommitted()
Get name of bootstrap reference anchoring committed RefTree.- Returns:
- name of bootstrap reference anchoring committed RefTree.
-
getTxnNamespace
@Nullable public java.lang.String getTxnNamespace()
Get namespace used by bootstrap layer.- Returns:
- namespace used by bootstrap layer, e.g.
refs/txn/. Always ends in'/'.
-
create
public void create() throws java.io.IOExceptionInitialize a new reference database at this location.- Specified by:
createin classRefDatabase- Throws:
java.io.IOException- the database could not be created.
-
performsAtomicTransactions
public boolean performsAtomicTransactions()
Whether the database is capable of performing batch updates as atomic transactions.If true, by default
BatchRefUpdateinstances will perform updates atomically, meaning either all updates will succeed, or all updates will fail. It is still possible to turn off this behavior on a per-batch basis by callingupdate.setAtomic(false).If false,
BatchRefUpdateinstances will never perform updates atomically, and callingupdate.setAtomic(true)will cause the entire batch to fail withREJECTED_OTHER_REASON.This definition of atomicity is stronger than what is provided by
ReceivePack.ReceivePackwill attempt to reject all commands if it knows in advance some commands may fail, even if the storage layer does not support atomic transactions. Here, atomicity applies even in the case of unforeseeable errors.- Overrides:
performsAtomicTransactionsin classRefDatabase- Returns:
- whether transactions are atomic by default.
-
refresh
public void refresh()
Triggers a refresh of all internal data structures.In case the RefDatabase implementation has internal caches this method will trigger that all these caches are cleared.
Implementors should overwrite this method if they use any kind of caches.
- Overrides:
refreshin classRefDatabase
-
close
public void close()
Close any resources held by this database.- Specified by:
closein classRefDatabase
-
exactRef
public Ref exactRef(java.lang.String name) throws java.io.IOException
Read a single reference.Unlike
RefDatabase.findRef(java.lang.String), this method expects an unshortened reference name and does not search using the standardRefDatabase.SEARCH_PATH.- Specified by:
exactRefin classRefDatabase- Parameters:
name- the unabbreviated name of the reference.- Returns:
- the reference (if it exists); else
null. - Throws:
java.io.IOException- the reference space cannot be accessed.
-
prefixOf
private static java.lang.String prefixOf(java.lang.String name)
-
getRefs
public java.util.Map<java.lang.String,Ref> getRefs(java.lang.String prefix) throws java.io.IOException
Get a section of the reference namespace.- Specified by:
getRefsin classRefDatabase- Parameters:
prefix- prefix to search the namespace with; must end with/. If the empty string (RefDatabase.ALL), obtain a complete snapshot of all references.- Returns:
- modifiable map that is a complete snapshot of the current
reference namespace, with
prefixremoved from the start of each key. The map can be an unsorted map. - Throws:
java.io.IOException- the reference space cannot be accessed.
-
getAdditionalRefs
public java.util.List<Ref> getAdditionalRefs() throws java.io.IOException
Get the additional reference-like entities from the repository.The result list includes non-ref items such as MERGE_HEAD and FETCH_RESULT cast to be refs. The names of these refs are not returned by
getRefs()but are accepted byRefDatabase.findRef(String)andRefDatabase.exactRef(String).- Specified by:
getAdditionalRefsin classRefDatabase- Returns:
- a list of additional refs
- Throws:
java.io.IOException- the reference space cannot be accessed.
-
peel
public Ref peel(Ref ref) throws java.io.IOException
Peel a possibly unpeeled reference by traversing the annotated tags.If the reference cannot be peeled (as it does not refer to an annotated tag) the peeled id stays null, but
Ref.isPeeled()will be true.Implementors should check
Ref.isPeeled()before performing any additional work effort.- Specified by:
peelin classRefDatabase- Parameters:
ref- The reference to peel- Returns:
refifref.isPeeled()is true; otherwise a new Ref object representing the same data as Ref, but isPeeled() will be true and getPeeledObjectId() will contain the peeled object (ornull).- Throws:
java.io.IOException- the reference space or object space cannot be accessed.
-
isNameConflicting
public boolean isNameConflicting(java.lang.String name) throws java.io.IOExceptionDetermine if a proposed reference name overlaps with an existing one.Reference names use '/' as a component separator, and may be stored in a hierarchical storage such as a directory on the local filesystem.
If the reference "refs/heads/foo" exists then "refs/heads/foo/bar" must not exist, as a reference cannot have a value and also be a container for other references at the same time.
If the reference "refs/heads/foo/bar" exists than the reference "refs/heads/foo" cannot exist, for the same reason.
- Specified by:
isNameConflictingin classRefDatabase- Parameters:
name- proposed name.- Returns:
- true if the name overlaps with an existing reference; false if using this name right now would be safe.
- Throws:
java.io.IOException- the database could not be read to check for conflicts.- See Also:
RefDatabase.getConflictingNames(String)
-
newBatchUpdate
public BatchRefUpdate newBatchUpdate()
Create a new batch update to attempt on this database.The default implementation performs a sequential update of each command.
- Overrides:
newBatchUpdatein classRefDatabase- Returns:
- a new batch update object.
-
newUpdate
public RefUpdate newUpdate(java.lang.String name, boolean detach) throws java.io.IOException
Create a new update command to create, modify or delete a reference.- Specified by:
newUpdatein classRefDatabase- Parameters:
name- the name of the reference.detach- iftrueandnameis currently aSymbolicRef, the update will replace it with anObjectIdRef. Otherwise, the update will recursively traverseSymbolicRefs and operate on the leafObjectIdRef.- Returns:
- a new update for the requested name; never null.
- Throws:
java.io.IOException- the reference space cannot be accessed.
-
newRename
public RefRename newRename(java.lang.String fromName, java.lang.String toName) throws java.io.IOException
Create a new update command to rename a reference.- Specified by:
newRenamein classRefDatabase- Parameters:
fromName- name of reference to rename fromtoName- name of reference to rename to- Returns:
- an update command that knows how to rename a branch to another.
- Throws:
java.io.IOException- the reference space cannot be accessed.
-
conflictsWithBootstrap
boolean conflictsWithBootstrap(java.lang.String name)
-
-