public class FileReftableDatabase extends RefDatabase
Modifier and Type | Class and Description |
---|---|
private class |
FileReftableDatabase.FileRefRename |
private class |
FileReftableDatabase.FileReftableBatchRefUpdate |
private class |
FileReftableDatabase.FileReftableRefUpdate |
Modifier and Type | Field and Description |
---|---|
private FileRepository |
fileRepository |
private ReftableDatabase |
reftableDatabase |
private FileReftableStack |
reftableStack |
ALL, MAX_SYMBOLIC_REF_DEPTH, SEARCH_PATH
Constructor and Description |
---|
FileReftableDatabase(FileRepository repo) |
FileReftableDatabase(FileRepository repo,
java.io.File refstackName) |
Modifier and Type | Method and Description |
---|---|
private boolean |
addReftable(FileReftableStack.Writer w) |
void |
close()
Close any resources held by this database.
|
void |
compactFully()
Runs a full compaction for GC purposes.
|
static FileReftableDatabase |
convertFrom(FileRepository repo,
boolean writeLogs) |
void |
create()
Initialize a new reference database at this location.
|
private Ref |
doPeel(Ref leaf) |
Ref |
exactRef(java.lang.String name)
Read a single reference.
|
java.util.List<Ref> |
getAdditionalRefs()
Get the additional reference-like entities from the repository.
|
private java.util.concurrent.locks.ReentrantLock |
getLock() |
(package private) ReflogReader |
getReflogReader(java.lang.String refname) |
java.util.List<Ref> |
getRefs()
Returns all refs.
|
java.util.Map<java.lang.String,Ref> |
getRefs(java.lang.String prefix)
Get a section of the reference namespace.
|
boolean |
hasFastTipsWithSha1()
If the ref database does not support fast inverse queries, it may
be advantageous to build a complete SHA1 to ref map in advance for
multiple uses.
|
boolean |
isNameConflicting(java.lang.String name)
Determine if a proposed reference name overlaps with an existing one.
|
static boolean |
isReftable(java.io.File repoDir) |
BatchRefUpdate |
newBatchUpdate()
Create a new batch update to attempt on this database.
|
RefRename |
newRename(java.lang.String fromName,
java.lang.String toName)
Create a new update command to rename a reference.
|
RefUpdate |
newUpdate(java.lang.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.
|
boolean |
performsAtomicTransactions()
Whether the database is capable of performing batch updates as atomic
transactions.
|
private static Ref |
recreate(Ref old,
Ref leaf,
boolean hasVersioning) |
private static Ref |
refForWrite(RevWalk rw,
Ref r) |
private static void |
writeConvertTable(Repository repo,
ReftableWriter w,
boolean writeLogs) |
exactRef, findRef, findRef, firstExactRef, getConflictingNames, getRef, getRefsByPrefix, getRefsByPrefix, getTipsWithSha1, hasRefs, hasVersioning, refresh
private final ReftableDatabase reftableDatabase
private final FileRepository fileRepository
private final FileReftableStack reftableStack
FileReftableDatabase(FileRepository repo) throws java.io.IOException
java.io.IOException
FileReftableDatabase(FileRepository repo, java.io.File refstackName) throws java.io.IOException
java.io.IOException
ReflogReader getReflogReader(java.lang.String refname) throws java.io.IOException
java.io.IOException
public static boolean isReftable(java.io.File repoDir)
repoDir
- public boolean hasFastTipsWithSha1() throws java.io.IOException
hasFastTipsWithSha1
in class RefDatabase
java.io.IOException
- on I/O problems.public void compactFully() throws java.io.IOException
java.io.IOException
- on I/O errorsprivate java.util.concurrent.locks.ReentrantLock getLock()
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.
performsAtomicTransactions
in class RefDatabase
@NonNull public BatchRefUpdate newBatchUpdate()
The default implementation performs a sequential update of each command.
newBatchUpdate
in class RefDatabase
public RefUpdate newUpdate(java.lang.String refName, boolean detach) throws java.io.IOException
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
.java.io.IOException
- the reference space cannot be accessed.public Ref exactRef(java.lang.String name) throws java.io.IOException
Unlike RefDatabase.findRef(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
.java.io.IOException
- the reference space cannot be accessed.public java.util.List<Ref> getRefs() throws java.io.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 RefDatabase.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
RefDatabase.getRefsByPrefix(java.lang.String)
instead.
getRefs
in class RefDatabase
java.io.IOException
- the reference space cannot be accessed.public java.util.Map<java.lang.String,Ref> getRefs(java.lang.String prefix) throws java.io.IOException
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.java.io.IOException
- the reference space cannot be accessed.public java.util.List<Ref> getAdditionalRefs() throws java.io.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 RefDatabase.findRef(String)
and RefDatabase.exactRef(String)
.
getAdditionalRefs
in class RefDatabase
java.io.IOException
- the reference space cannot be accessed.public Ref peel(Ref ref) throws java.io.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.
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
).java.io.IOException
- the reference space or object space cannot be accessed.public RefRename newRename(java.lang.String fromName, java.lang.String toName) throws java.io.IOException
newRename
in class RefDatabase
fromName
- name of reference to rename fromtoName
- name of reference to rename tojava.io.IOException
- the reference space cannot be accessed.public boolean isNameConflicting(java.lang.String name) throws java.io.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.
isNameConflicting
in class RefDatabase
name
- proposed name.java.io.IOException
- the database could not be read to check for conflicts.RefDatabase.getConflictingNames(String)
public void close()
close
in class RefDatabase
public void create() throws java.io.IOException
create
in class RefDatabase
java.io.IOException
- the database could not be created.private boolean addReftable(FileReftableStack.Writer w) throws java.io.IOException
java.io.IOException
private static void writeConvertTable(Repository repo, ReftableWriter w, boolean writeLogs) throws java.io.IOException
java.io.IOException
private static Ref refForWrite(RevWalk rw, Ref r) throws java.io.IOException
java.io.IOException
public static FileReftableDatabase convertFrom(FileRepository repo, boolean writeLogs) throws java.io.IOException
repo
- the repositorywriteLogs
- whether to write reflogsjava.io.IOException
- on IO error