Class RefDirectory
- java.lang.Object
-
- org.eclipse.jgit.lib.RefDatabase
-
- org.eclipse.jgit.internal.storage.file.RefDirectory
-
public class RefDirectory extends RefDatabase
Traditional file system basedRefDatabase.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 currentObjectIdin 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.
-
-
Field Summary
Fields Modifier and Type Field Description static StringPACKED_REFS_HEADERMagic string denoting the header of a packed-refs file.static StringPACKED_REFS_PEELEDIf in the header, denotes the file has peeled data.static StringSYMREFMagic string denoting the start of a symbolic reference file.-
Fields inherited from class org.eclipse.jgit.lib.RefDatabase
ALL, MAX_SYMBOLIC_REF_DEPTH, SEARCH_PATH
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close any resources held by this database.voidcreate()Initialize a new reference database at this location.List<Ref>getAdditionalRefs()Get the additional reference-like entities from the repository.RefgetRef(String needle)Read a single reference.Map<String,Ref>getRefs(String prefix)Get a section of the reference namespace.booleanisNameConflicting(String name)Determine if a proposed reference name overlaps with an existing one.org.eclipse.jgit.internal.storage.file.RefDirectoryRenamenewRename(String fromName, String toName)Create a new update command to rename a reference.org.eclipse.jgit.internal.storage.file.RefDirectoryUpdatenewUpdate(String name, boolean detach)Create a new update command to create, modify or delete a reference.voidpack(List<String> refs)Adds a set of refs to the set of packed-refs.Refpeel(Ref ref)Peel a possibly unpeeled reference by traversing the annotated tags.voidrefresh()Triggers a refresh of all internal data structures.-
Methods inherited from class org.eclipse.jgit.lib.RefDatabase
findRef, getConflictingNames, newBatchUpdate, performsAtomicTransactions
-
-
-
-
Field Detail
-
SYMREF
public static final String SYMREF
Magic string denoting the start of a symbolic reference file.- See Also:
- Constant Field Values
-
PACKED_REFS_HEADER
public static final String PACKED_REFS_HEADER
Magic string denoting the header of a packed-refs file.- See Also:
- Constant Field Values
-
PACKED_REFS_PEELED
public static final String PACKED_REFS_PEELED
If in the header, denotes the file has peeled data.- See Also:
- Constant Field Values
-
-
Method Detail
-
create
public void create() throws IOExceptionDescription copied from class:RefDatabaseInitialize a new reference database at this location.- Specified by:
createin classRefDatabase- Throws:
IOException- the database could not be created.
-
close
public void close()
Description copied from class:RefDatabaseClose any resources held by this database.- Specified by:
closein classRefDatabase
-
refresh
public void refresh()
Description copied from class:RefDatabaseTriggers 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
-
isNameConflicting
public boolean isNameConflicting(String name) throws IOException
Description copied from class:RefDatabaseDetermine 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:
IOException- the database could not be read to check for conflicts.- See Also:
RefDatabase.getConflictingNames(String)
-
getRef
public Ref getRef(String needle) throws IOException
Description copied from class:RefDatabaseRead a single reference.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 bygetRefs(ALL).get(name).- Specified by:
getRefin classRefDatabase- Parameters:
needle- the name of the reference. May be a short name which must be searched for using the standardRefDatabase.SEARCH_PATH.- Returns:
- the reference (if it exists); else
null. - Throws:
IOException- the reference space cannot be accessed.
-
getRefs
public Map<String,Ref> getRefs(String prefix) throws IOException
Description copied from class:RefDatabaseGet 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:
IOException- the reference space cannot be accessed.
-
getAdditionalRefs
public List<Ref> getAdditionalRefs() throws IOException
Description copied from class:RefDatabaseGet 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(ALL)but are accepted byRefDatabase.getRef(String)- Specified by:
getAdditionalRefsin classRefDatabase- Returns:
- a list of additional refs
- Throws:
IOException- the reference space cannot be accessed.
-
peel
public Ref peel(Ref ref) throws IOException
Description copied from class:RefDatabasePeel 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 (or null).- Throws:
IOException- the reference space or object space cannot be accessed.
-
newUpdate
public org.eclipse.jgit.internal.storage.file.RefDirectoryUpdate newUpdate(String name, boolean detach) throws IOException
Description copied from class:RefDatabaseCreate 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:
IOException- the reference space cannot be accessed.
-
newRename
public org.eclipse.jgit.internal.storage.file.RefDirectoryRename newRename(String fromName, String toName) throws IOException
Description copied from class:RefDatabaseCreate 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:
IOException- the reference space cannot be accessed.
-
pack
public void pack(List<String> refs) throws IOException
Adds a set of refs to the set of packed-refs. Only non-symbolic refs are added. If a ref with the given name already existed in packed-refs it is updated with the new value. Each loose ref which was added to the packed-ref file is deleted. If a given ref can't be locked it will not be added to the pack file.- Parameters:
refs- the refs to be added. Must be fully qualified.- Throws:
IOException
-
-