Top Description Inners Fields Constructors Methods
org.eclipse.jgit.internal.storage.file

public Class RefDirectory

extends RefDatabase
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.internal.storage.file.SnapshottingRefDirectory
Static Imports
java.nio.charset.StandardCharsets.UTF_8, org.eclipse.jgit.lib.Constants.HEAD, .Constants.LOGS, .Constants.L_LOGS, .Constants.OBJECT_ID_STRING_LENGTH, .Constants.PACKED_REFS, .Constants.R_HEADS, .Constants.R_REFS, .Constants.R_TAGS, .Ref.Storage.LOOSE, .Ref.Storage.NEW, .Ref.Storage.PACKED

Traditional file system based org.eclipse.jgit.lib.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 org.eclipse.jgit.lib.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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static interface
private class
private static class
private static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private final CoreConfig
private final File
private final File
pack-priv final ReentrantLock
inProcessPackedRefsLock

Lock for coordinating operations within a single process that may contend on the packed-refs file.

private final AtomicInteger
lastNotifiedModCnt

Last modCnt that we sent to listeners.

private static final Logger
pack-priv final File
pack-priv final File
private final AtomicReference<RefList<RefDirectory.LooseRef>>
looseRefs

Immutable sorted list of loose references.

private final AtomicInteger
modCnt

Number of modifications made to this database.

private static final RefDirectory.PackedRefList
public static final String
PACKED_REFS_HEADER

Magic string denoting the header of a packed-refs file.

public static final String
PACKED_REFS_PEELED

If in the header, denotes the file has peeled data.

pack-priv final AtomicReference<RefDirectory.PackedRefList>
packedRefs

Immutable sorted list of packed references.

pack-priv final File
private final FileRepository
pack-priv final File
private static final List<Integer>
private List<Integer>
public static final String
SYMREF

Magic string denoting the start of a symbolic reference file.

Inherited from org.eclipse.jgit.lib.RefDatabase:
additionalRefsNamesALLMAX_SYMBOLIC_REF_DEPTHSEARCH_PATH

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
public void
close()

Implements abstract org.eclipse.jgit.lib.RefDatabase.close.

Close any resources held by this database.

pack-priv void
commitPackedRefs(final LockFile lck, final RefList<Ref> refs, final RefDirectory.PackedRefList oldPackedList, boolean changed)

pack-priv void
private static String
copy(String src, int off, int end)

public void
create()

Implements abstract org.eclipse.jgit.lib.RefDatabase.create.

Initialize a new reference database at this location.

pack-priv RefDirectoryRename
pack-priv RefDirectoryUpdate
public SnapshottingRefDirectory

Returns:

a cached RefDirectory.
createSnapshottingRefDirectory
()

Create a cache of this RefDirectory.

pack-priv void
pack-priv static void
delete(File file, int depth)

private static void
delete(File file)

private static void
deleteAndUnlock(File file, int depth, RefDirectoryUpdate refUpdate)

private static void
deleteAndUnlock(File file, int depth, LockFile rLck)

private static void
deleteEmptyParentDirs(File file, int depth)

private ObjectIdRef
doPeel(Ref leaf)

public Ref
exactRef(String
the unabbreviated name of the reference.
name
)

Implements abstract org.eclipse.jgit.lib.RefDatabase.exactRef.

Read a single reference.

public Map<String, Ref>
exactRef(String...
the unabbreviated names of references to look up.
refs
)

Overrides org.eclipse.jgit.lib.RefDatabase.exactRef.

Read the specified references.

pack-priv File

Returns:

the loose file location.
fileFor
(String
name of the ref, relative to the Git repository top level directory (so typically starts with refs/).
name
)

Locate the file on disk for a single reference name.

pack-priv void
fireRefsChanged()

If the parent should fire listeners, fires them.

public Ref
firstExactRef(String...
the unabbreviated names of references to look up.
refs
)

Overrides org.eclipse.jgit.lib.RefDatabase.firstExactRef.

Find the first named reference.

public List<Ref>
getAdditionalRefs()

Implements abstract org.eclipse.jgit.lib.RefDatabase.getAdditionalRefs.

Get the additional reference-like entities from the repository.

pack-priv RefDirectory.PackedRefList
public ReflogReader
getReflogReader(Ref
a Ref
ref
)

Implements abstract org.eclipse.jgit.lib.RefDatabase.getReflogReader.

Get the reflog reader.

public Map<String, Ref>
getRefs(String
prefix to search the namespace with; must end with /. If the empty string (ALL), obtain a complete snapshot of all references.
prefix
)

Implements abstract org.eclipse.jgit.lib.RefDatabase.getRefs.

Get a section of the reference namespace.

public List<Ref>
getRefsByPrefix(String...
strings that names of refs should start with.
prefixes
)

Overrides org.eclipse.jgit.lib.RefDatabase.getRefsByPrefix.

Returns refs whose names start with one of the given prefixes.

pack-priv Repository
pack-priv Iterable<Integer>

Returns:

iterable of times, in milliseconds, that the caller should sleep before attempting an operation.
getRetrySleepMs
()

Get times to sleep while retrying a possibly contentious operation.

private boolean
private boolean
pack-priv boolean

Returns:

true if we are currently cloning a repository
isInClone
()

Detect if we are in a clone command execution

public boolean
isNameConflicting(String
proposed name.
name
)

Implements abstract org.eclipse.jgit.lib.RefDatabase.isNameConflicting.

Determine if a proposed reference name overlaps with an existing one.

private static boolean
isSymRef(byte[] buf, int n)

pack-priv static int
pack-priv LockFile
pack-priv LockFile
pack-priv void
log(boolean force, RefUpdate update, String msg, boolean deref)

public File

Returns:

the log file location.
logFor
(String
name of the ref, relative to the Git repository top level directory (so typically starts with refs/).
name
)

Locate the log file on disk for a single reference name.

public PackedBatchRefUpdate
newBatchUpdate()

Overrides org.eclipse.jgit.lib.RefDatabase.newBatchUpdate.

Create a new batch update to attempt on this database.

public PackedBatchRefUpdate

Returns:

a new batch update object
newBatchUpdate
(boolean
whether loose refs should be locked during the batch ref update. Note that this should only be set to false if the application using this ensures that no other ref updates run concurrently to avoid lost updates caused by a race. In such cases it can improve performance.
shouldLockLooseRefs
)

Create a new batch update to attempt on this database.

pack-priv ReflogWriter
newLogWriter(boolean force)

public RefDirectoryRename
newRename(String
name of reference to rename from
fromName
,
String
name of reference to rename to
toName
)

Implements abstract org.eclipse.jgit.lib.RefDatabase.newRename.

Create a new update command to rename a reference.

private static RefDirectory.LooseSymbolicRef
newSymbolicRef(FileSnapshot snapshot, String name, String target)

pack-priv RefDirectoryUpdate

Returns:

an update for a new temporary reference.
newTemporaryUpdate
()

Create a reference update to write a temporary reference.

public RefDirectoryUpdate
newUpdate(String
the name of the reference.
name
,
boolean
if true and name is currently a org.eclipse.jgit.lib.SymbolicRef, the update will replace it with an org.eclipse.jgit.lib.ObjectIdRef. Otherwise, the update will recursively traverse org.eclipse.jgit.lib.SymbolicRefs and operate on the leaf org.eclipse.jgit.lib.ObjectIdRef.
detach
)

Implements abstract org.eclipse.jgit.lib.RefDatabase.newUpdate.

Create a new update command to create, modify or delete a reference.

public void
pack(List<String>
the refs to be added. Must be fully qualified.
refs
)

Adds a set of refs to the set of packed-refs.

pack-priv void
pack(Map<String, LockFile> heldLocks)

private void
pack(Collection<String> refs, Map<String, LockFile> heldLocks)

public void
packRefs(ProgressMonitor
a progress monitor
pm
,
PackRefsCommand
PackRefsCommand to control ref packing behavior
packRefs
)

Overrides org.eclipse.jgit.lib.RefDatabase.packRefs.

Optimize pack ref storage.

private RefList<Ref>
public Ref
peel(Ref
The reference to peel
ref
)

Implements abstract org.eclipse.jgit.lib.RefDatabase.peel.

Peel a possibly unpeeled reference by traversing the annotated tags.

private Ref

Returns:

a ref for Storage PACKED having the same name, id, peeledId as f
peeledPackedRef
(Ref
given ref
ref
)

Make sure a ref is peeled and has the Storage PACKED.

public boolean
performsAtomicTransactions()

Overrides org.eclipse.jgit.lib.RefDatabase.performsAtomicTransactions.

Whether the database is capable of performing batch updates as atomic transactions.

private void
private Ref
private RefDirectory.PackedRefList
private Ref
readRef(String name, RefList<Ref> packed)

private static Ref
public void
refresh()

Overrides org.eclipse.jgit.lib.RefDatabase.refresh.

Triggers a refresh of all internal data structures.

pack-priv RefDirectory.PackedRefList
private RefDirectory.PackedRefList
pack-priv void
refreshPathToLooseRef(Path
path of a loose ref relative to the repository root
refPath
)

Workaround for issues caused by NFS caching.

private Ref
resolve(final Ref ref, int depth, String prefix, RefList<RefDirectory.LooseRef> loose, RefList<Ref> packed)

pack-priv RefDirectory.LooseRef
pack-priv void
setRetrySleepMs(List<Integer> retrySleepMs)

pack-priv static void
sleep(long
time to sleep, in milliseconds; zero or negative is a no-op.
ms
)

Sleep with Thread#sleep(long), converting InterruptedException to InterruptedIOException.

pack-priv void
pack-priv void
private RefList<Ref>
upcast(RefList<? extends Ref> loose)

Inherited from org.eclipse.jgit.lib.RefDatabase:
findReffindRefgetConflictingNamesgetReflogReadergetRefsgetRefsByPrefixgetRefsByPrefixWithExclusionsgetTipsWithSha1hasFastTipsWithSha1hasRefshasVersioning