public abstract class DfsRefDatabase extends RefDatabase
Modifier and Type | Class and Description |
---|---|
static class |
DfsRefDatabase.RefCache
Collection of references managed by this database.
|
ALL, MAX_SYMBOLIC_REF_DEPTH, SEARCH_PATH
Modifier | Constructor and Description |
---|---|
protected |
DfsRefDatabase(DfsRepository repository)
Initialize the reference database for a repository.
|
Modifier and Type | Method and Description |
---|---|
protected void |
cachePeeledState(Ref oldLeaf,
Ref newLeaf)
Update the cached peeled state of a reference
|
void |
close()
Close any resources held by this database.
|
protected abstract boolean |
compareAndPut(Ref oldRef,
Ref newRef)
Compare a reference, and put if it matches.
|
protected abstract boolean |
compareAndRemove(Ref oldRef)
Compare a reference, and delete if it matches.
|
void |
create()
Initialize a new reference database at this location.
|
Ref |
exactRef(String name)
Read a single reference.
|
List<Ref> |
getAdditionalRefs()
Get the additional reference-like entities from the repository.
|
Ref |
getRef(String needle)
Read a single reference.
|
Map<String,Ref> |
getRefs(String prefix)
Get a section of the reference namespace.
|
protected DfsRepository |
getRepository() |
boolean |
isNameConflicting(String refName)
Determine if a proposed reference name overlaps with an existing one.
|
RefRename |
newRename(String fromName,
String toName)
Create a new update command to rename a reference.
|
RefUpdate |
newUpdate(String refName,
boolean detach)
Create a new update command to create, modify or delete a reference.
|
Ref |
peel(Ref ref)
Peel a possibly unpeeled reference by traversing the annotated tags.
|
protected abstract DfsRefDatabase.RefCache |
scanAllRefs()
Read all known references in the repository.
|
exactRef, findRef, firstExactRef, getConflictingNames, newBatchUpdate, performsAtomicTransactions, refresh
protected DfsRefDatabase(DfsRepository repository)
repository
- the repository this database instance manages references for.protected DfsRepository getRepository()
public Ref exactRef(String name) throws IOException
RefDatabase
Unlike RefDatabase.getRef(java.lang.String)
, this method expects an unshortened reference
name and does not search using the standard RefDatabase.SEARCH_PATH
.
exactRef
in class RefDatabase
name
- the unabbreviated name of the reference.null
.IOException
- the reference space cannot be accessed.public Ref getRef(String needle) throws IOException
RefDatabase
Aside from taking advantage of RefDatabase.SEARCH_PATH
, this method may be
able to more quickly resolve a single reference name than obtaining the
complete namespace by getRefs(ALL).get(name)
.
To read a specific reference without using @{link #SEARCH_PATH}, see
RefDatabase.exactRef(String)
.
getRef
in class RefDatabase
needle
- the name of the reference. May be a short name which must be
searched for using the standard RefDatabase.SEARCH_PATH
.null
.IOException
- the reference space cannot be accessed.public List<Ref> getAdditionalRefs()
RefDatabase
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(ALL)
but are accepted by RefDatabase.getRef(String)
and RefDatabase.exactRef(String)
.
getAdditionalRefs
in class RefDatabase
public Map<String,Ref> getRefs(String prefix) throws IOException
RefDatabase
getRefs
in class RefDatabase
prefix
- prefix to search the namespace with; must end with /
.
If the empty string (RefDatabase.ALL
), obtain a complete snapshot
of all references.prefix
removed from the start
of each key. The map can be an unsorted map.IOException
- the reference space cannot be accessed.public Ref peel(Ref ref) throws IOException
RefDatabase
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.
peel
in class RefDatabase
ref
- The reference to peelref
if ref.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
(or null).IOException
- the reference space or object space cannot be accessed.public RefUpdate newUpdate(String refName, boolean detach) throws IOException
RefDatabase
newUpdate
in class RefDatabase
refName
- the name of the reference.detach
- if true
and name
is currently a
SymbolicRef
, the update will replace it with an
ObjectIdRef
. Otherwise, the update will recursively
traverse SymbolicRef
s and operate on the leaf
ObjectIdRef
.IOException
- the reference space cannot be accessed.public RefRename newRename(String fromName, String toName) throws IOException
RefDatabase
newRename
in class RefDatabase
fromName
- name of reference to rename fromtoName
- name of reference to rename toIOException
- the reference space cannot be accessed.public boolean isNameConflicting(String refName) throws IOException
RefDatabase
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.
isNameConflicting
in class RefDatabase
refName
- proposed name.IOException
- the database could not be read to check for conflicts.RefDatabase.getConflictingNames(String)
public void create()
RefDatabase
create
in class RefDatabase
public void close()
RefDatabase
close
in class RefDatabase
protected abstract DfsRefDatabase.RefCache scanAllRefs() throws IOException
IOException
- references cannot be accessed.protected abstract boolean compareAndPut(Ref oldRef, Ref newRef) throws IOException
oldRef
- old value to compare to. If the reference is expected to not
exist the old value has a storage of
Ref.Storage.NEW
and an ObjectId
value of null
.newRef
- new reference to store.IOException
- the reference cannot be put due to a system error.protected abstract boolean compareAndRemove(Ref oldRef) throws IOException
oldRef
- the old reference information that was previously read.IOException
- the reference could not be removed due to a system error.protected void cachePeeledState(Ref oldLeaf, Ref newLeaf)
The ref database invokes this method after it peels a reference that had not been peeled before. This allows the storage to cache the peel state of the reference, and if it is actually peelable, the target that it peels to, so that on-the-fly peeling doesn't have to happen on the next reference read.
oldLeaf
- the old reference.newLeaf
- the new reference, with peel information.Copyright © 2015 Eclipse JGit Project. All rights reserved.