public class RefDirectory extends RefDatabase
RefDatabase
.
This is the classical reference database representation for a Git repository. References are stored in two formats: loose, and packed.
Loose references are stored as individual files within the refs/
directory. The file name matches the reference name and the file contents is
the current ObjectId
in string form.
Packed references are stored in a single text file named packed-refs
.
In the packed format, each reference is stored on its own line. This file
reduces the number of files needed for large reference spaces, reducing the
overall size of a Git repository on disk.
Modifier and Type | Field and Description |
---|---|
static String |
PACKED_REFS_HEADER
Magic string denoting the header of a packed-refs file.
|
static String |
PACKED_REFS_PEELED
If in the header, denotes the file has peeled data.
|
static String |
SYMREF
Magic string denoting the start of a symbolic reference file.
|
ALL, MAX_SYMBOLIC_REF_DEPTH, SEARCH_PATH
Modifier and Type | Method and Description |
---|---|
void |
close()
Close any resources held by this database.
|
void |
create()
Initialize a new reference database at this location.
|
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.
|
boolean |
isNameConflicting(String name)
Determine if a proposed reference name overlaps with an existing one.
|
org.eclipse.jgit.internal.storage.file.RefDirectoryRename |
newRename(String fromName,
String toName)
Create a new update command to rename a reference.
|
org.eclipse.jgit.internal.storage.file.RefDirectoryUpdate |
newUpdate(String name,
boolean detach)
Create a new update command to create, modify or delete a reference.
|
void |
pack(List<String> refs)
Adds a set of refs to the set of packed-refs.
|
Ref |
peel(Ref ref)
Peel a possibly unpeeled reference by traversing the annotated tags.
|
void |
refresh()
Triggers a refresh of all internal data structures.
|
findRef, getConflictingNames, newBatchUpdate, performsAtomicTransactions
public static final String SYMREF
public static final String PACKED_REFS_HEADER
public static final String PACKED_REFS_PEELED
public void create() throws IOException
RefDatabase
create
in class RefDatabase
IOException
- the database could not be created.public void close()
RefDatabase
close
in class RefDatabase
public void refresh()
RefDatabase
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.
refresh
in class RefDatabase
public boolean isNameConflicting(String name) 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
name
- proposed name.IOException
- the database could not be read to check for conflicts.RefDatabase.getConflictingNames(String)
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)
.
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 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 List<Ref> getAdditionalRefs() throws IOException
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)
getAdditionalRefs
in class RefDatabase
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 org.eclipse.jgit.internal.storage.file.RefDirectoryUpdate newUpdate(String name, boolean detach) throws IOException
RefDatabase
newUpdate
in class RefDatabase
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.public org.eclipse.jgit.internal.storage.file.RefDirectoryRename 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 void pack(List<String> refs) throws IOException
refs
- the refs to be added. Must be fully qualified.IOException
Copyright © 2015 Eclipse JGit Project. All rights reserved.