public abstract class RefDatabase extends Object
ObjectId
mapping.
A reference database stores a mapping of reference names to
ObjectId
. Every
Repository
has a single reference database,
mapping names to the tips of the object graph contained by the
ObjectDatabase
.
Modifier and Type | Field and Description |
---|---|
static String |
ALL
Magic value for
getRefsByPrefix(String) to return all
references. |
static int |
MAX_SYMBOLIC_REF_DEPTH
Maximum number of times a
SymbolicRef can be traversed. |
protected static String[] |
SEARCH_PATH
Order of prefixes to search when using non-absolute references.
|
Constructor and Description |
---|
RefDatabase() |
Modifier and Type | Method and Description |
---|---|
abstract void |
close()
Close any resources held by this database.
|
abstract void |
create()
Initialize a new reference database at this location.
|
Map<String,Ref> |
exactRef(String... refs)
Read the specified references.
|
Ref |
exactRef(String name)
Read a single reference.
|
static Ref |
findRef(Map<String,Ref> map,
String name)
Try to find the specified name in the ref map using
SEARCH_PATH . |
Ref |
firstExactRef(String... refs)
Find the first named reference.
|
abstract List<Ref> |
getAdditionalRefs()
Get the additional reference-like entities from the repository.
|
Collection<String> |
getConflictingNames(String name)
Determine if a proposed reference cannot coexist with existing ones.
|
abstract Ref |
getRef(String name)
Read a single reference.
|
List<Ref> |
getRefs()
Returns all refs.
|
abstract Map<String,Ref> |
getRefs(String prefix)
Deprecated.
use
getRefsByPrefix(java.lang.String) instead |
List<Ref> |
getRefsByPrefix(String prefix)
Returns refs whose names start with a given prefix.
|
boolean |
hasRefs()
Check if any refs exist in the ref database.
|
abstract boolean |
isNameConflicting(String name)
Determine if a proposed reference name overlaps with an existing one.
|
BatchRefUpdate |
newBatchUpdate()
Create a new batch update to attempt on this database.
|
abstract RefRename |
newRename(String fromName,
String toName)
Create a new update command to rename a reference.
|
abstract RefUpdate |
newUpdate(String name,
boolean detach)
Create a new update command to create, modify or delete a reference.
|
abstract Ref |
peel(Ref ref)
Peel a possibly unpeeled reference by traversing the annotated tags.
|
boolean |
performsAtomicTransactions()
Whether the database is capable of performing batch updates as atomic
transactions.
|
void |
refresh()
Triggers a refresh of all internal data structures.
|
protected static final String[] SEARCH_PATH
The implementation's getRef(String)
method must take this search
space into consideration when locating a reference by name. The first
entry in the path is always ""
, ensuring that absolute references
are resolved without further mangling.
public static final int MAX_SYMBOLIC_REF_DEPTH
SymbolicRef
can be traversed.
If the reference is nested deeper than this depth, the implementation should either fail, or at least claim the reference does not exist.
public static final String ALL
getRefsByPrefix(String)
to return all
references.public abstract void create() throws IOException
IOException
- the database could not be created.public abstract void close()
public abstract boolean isNameConflicting(String name) throws IOException
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.
name
- proposed name.IOException
- the database could not be read to check for conflicts.getConflictingNames(String)
@NonNull public Collection<String> getConflictingNames(String name) throws IOException
name
- proposed name to check for conflicts againstIOException
isNameConflicting(String)
@NonNull public abstract RefUpdate newUpdate(String name, boolean detach) throws IOException
name
- 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.@NonNull public abstract RefRename newRename(String fromName, String toName) throws IOException
fromName
- name of reference to rename fromtoName
- name of reference to rename toIOException
- the reference space cannot be accessed.@NonNull public BatchRefUpdate newBatchUpdate()
The default implementation performs a sequential update of each command.
public boolean performsAtomicTransactions()
If true, by default BatchRefUpdate
instances
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 calling update.setAtomic(false)
.
If false, BatchRefUpdate
instances will
never perform updates atomically, and calling
update.setAtomic(true)
will cause the entire batch to fail with
REJECTED_OTHER_REASON
.
This definition of atomicity is stronger than what is provided by
ReceivePack
. ReceivePack
will
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.
@Nullable public abstract Ref getRef(String name) throws IOException
Aside from taking advantage of 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
exactRef(String)
.
name
- the name of the reference. May be a short name which must be
searched for using the standard SEARCH_PATH
.null
.IOException
- the reference space cannot be accessed.@Nullable public Ref exactRef(String name) throws IOException
Unlike getRef(java.lang.String)
, this method expects an unshortened reference
name and does not search using the standard SEARCH_PATH
.
name
- the unabbreviated name of the reference.null
.IOException
- the reference space cannot be accessed.@NonNull public Map<String,Ref> exactRef(String... refs) throws IOException
This method expects a list of unshortened reference names and returns a map from reference names to refs. Any named references that do not exist will not be included in the returned map.
refs
- the unabbreviated names of references to look up.IOException
- the reference space cannot be accessed.@Nullable public Ref firstExactRef(String... refs) throws IOException
This method expects a list of unshortened reference names and returns the first that exists.
refs
- the unabbreviated names of references to look up.null
.IOException
- the reference space cannot be accessed.@NonNull public List<Ref> getRefs() throws IOException
This includes HEAD
, branches under ref/heads/
, tags
under refs/tags/
, etc. It does not include pseudo-refs like
FETCH_HEAD
; for those, see getAdditionalRefs()
.
Symbolic references to a non-existent ref (for example,
HEAD
pointing to a branch yet to be born) are not included.
Callers interested in only a portion of the ref hierarchy can call
getRefsByPrefix(java.lang.String)
instead.
IOException
- the reference space cannot be accessed.@NonNull @Deprecated public abstract Map<String,Ref> getRefs(String prefix) throws IOException
getRefsByPrefix(java.lang.String)
insteadprefix
- prefix to search the namespace with; must end with /
.
If the empty string (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.@NonNull public List<Ref> getRefsByPrefix(String prefix) throws IOException
The default implementation uses getRefs(String)
. Implementors of
RefDatabase
should override this method directly if a better
implementation is possible.
prefix
- string that names of refs should start with; may be
empty (to return all refs).prefix
.IOException
- the reference space cannot be accessed.public boolean hasRefs() throws IOException
This uses the same definition of refs as getRefs()
. In
particular, returns false
in a new repository with no refs
under refs/
and HEAD
pointing to a branch yet to be
born, and returns true
in a repository with no refs under
refs/
and a detached HEAD
pointing to history.
IOException
- the reference space cannot be accessed.@NonNull public abstract List<Ref> getAdditionalRefs() throws IOException
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 by getRef(String)
and exactRef(String)
.
IOException
- the reference space cannot be accessed.@NonNull public abstract Ref peel(Ref ref) throws IOException
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.
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 void refresh()
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.
@Nullable public static Ref findRef(Map<String,Ref> map, String name)
SEARCH_PATH
.map
- map of refs to search within. Names should be fully qualified,
e.g. "refs/heads/master".name
- short name of ref to find, e.g. "master" to find
"refs/heads/master" in map.null
if not found.Copyright © 2019 Eclipse JGit Project. All rights reserved.