org.eclipse.jgit.internal.storage.dfs

## Class DfsRefDatabase

- java.lang.Object
- - org.eclipse.jgit.lib.RefDatabase
  - - org.eclipse.jgit.internal.storage.dfs.DfsRefDatabase

    public abstract class DfsRefDatabase
    extends RefDatabase

### Nested Class Summary

Nested Classes
`static class` `DfsRefDatabase.RefCache` Collection of references managed by this database.

### Field Summary

### Fields inherited from class org.eclipse.jgit.lib.RefDatabase

`ALL, MAX_SYMBOLIC_REF_DEPTH, SEARCH_PATH`

### Constructor Summary

Constructors
`protected` `DfsRefDatabase(DfsRepository repository)` Initialize the reference database for a repository.

### Method Summary

Methods
`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.
`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.
`org.eclipse.jgit.internal.storage.dfs.DfsRefUpdate` `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.

### Methods inherited from class org.eclipse.jgit.lib.RefDatabase

`getConflictingNames, newBatchUpdate, refresh`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### DfsRefDatabase

    protected DfsRefDatabase(DfsRepository repository)

Initialize the reference database for a repository.

Parameters:
  `repository` - the repository this database instance manages references for.

### Method Detail

#### getRepository

    protected DfsRepository getRepository()

Returns:
  the repository the database holds the references of.

#### getRef

    public Ref getRef(String needle)
               throws IOException

Description copied from class: `RefDatabase`
Read 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 by `getRefs(ALL).get(name)`.

Specified by:
  `getRef` in class `RefDatabase`
Parameters:
  `needle` - the name of the reference. May be a short name which must be searched for using the standard `RefDatabase.SEARCH_PATH`.
Returns:
  the reference (if it exists); else `null`.
Throws:
  `IOException` - the reference space cannot be accessed.

#### getAdditionalRefs

    public List<Ref> getAdditionalRefs()

Description copied from class: `RefDatabase`
Get 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 by `RefDatabase.getRef(String)`

Specified by:
  `getAdditionalRefs` in class `RefDatabase`
Returns:
  a list of additional refs

#### getRefs

    public Map<String,Ref> getRefs(String prefix)
                            throws IOException

Description copied from class: `RefDatabase`
Get a section of the reference namespace.

Specified by:
  `getRefs` in class `RefDatabase`
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 `prefix` removed from the start of each key. The map can be an unsorted map.
Throws:
  `IOException` - the reference space cannot be accessed.

#### peel

    public Ref peel(Ref ref)
             throws IOException

Description copied from class: `RefDatabase`
Peel 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:
  `peel` in class `RefDatabase`
Parameters:
  `ref` - The reference to peel
Returns:
  `ref` 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).
Throws:
  `IOException` - the reference space or object space cannot be accessed.

#### newUpdate

    public org.eclipse.jgit.internal.storage.dfs.DfsRefUpdate newUpdate(String refName,
                                                               boolean detach)
                                                                 throws IOException

Description copied from class: `RefDatabase`
Create a new update command to create, modify or delete a reference.

Specified by:
  `newUpdate` in class `RefDatabase`
Parameters:
  `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`.
Returns:
  a new update for the requested name; never null.
Throws:
  `IOException` - the reference space cannot be accessed.

#### newRename

    public RefRename newRename(String fromName,
                      String toName)
                        throws IOException

Description copied from class: `RefDatabase`
Create a new update command to rename a reference.

Specified by:
  `newRename` in class `RefDatabase`
Parameters:
  `fromName` - name of reference to rename from
  `toName` - 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.

#### isNameConflicting

    public boolean isNameConflicting(String refName)
                              throws IOException

Description copied from class: `RefDatabase`
Determine 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:
  `isNameConflicting` in class `RefDatabase`
Parameters:
  `refName` - 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)`

#### create

    public void create()

Description copied from class: `RefDatabase`
Initialize a new reference database at this location.

Specified by:
  `create` in class `RefDatabase`

#### close

    public void close()

Description copied from class: `RefDatabase`
Close any resources held by this database.

Specified by:
  `close` in class `RefDatabase`

#### scanAllRefs

    protected abstract DfsRefDatabase.RefCache scanAllRefs()
                                                    throws IOException

Read all known references in the repository.

Returns:
  all current references of the repository.
Throws:
  `IOException` - references cannot be accessed.

#### compareAndPut

    protected abstract boolean compareAndPut(Ref oldRef,
                        Ref newRef)
                                      throws IOException

Compare a reference, and put if it matches.

Parameters:
  `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.
Returns:
  true if the put was successful; false otherwise.
Throws:
  `IOException` - the reference cannot be put due to a system error.

#### compareAndRemove

    protected abstract boolean compareAndRemove(Ref oldRef)
                                         throws IOException

Compare a reference, and delete if it matches.

Parameters:
  `oldRef` - the old reference information that was previously read.
Returns:
  true if the remove was successful; false otherwise.
Throws:
  `IOException` - the reference could not be removed due to a system error.

#### cachePeeledState

    protected void cachePeeledState(Ref oldLeaf,
                        Ref newLeaf)

Update the cached peeled state of a reference

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.

Parameters:
  `oldLeaf` - the old reference.
  `newLeaf` - the new reference, with peel information.