Class FileRepository
- All Implemented Interfaces:
AutoCloseable
- GIT_DIR
- objects/ - objects
- refs/ - tags and heads
- config - configuration
- info/ - more configurations
This class is thread-safe.
This implementation only handles a subtly undocumented subset of git features.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
Implementation aAttributesNodeProvider
for aFileRepository
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.slf4j.Logger
private final ObjectDirectory
private RefDatabase
private final FileBasedConfig
private FileSnapshot
private final Object
private static final String
-
Constructor Summary
ConstructorsConstructorDescriptionFileRepository
(File gitDir) Construct a representation of a Git repository.FileRepository
(String gitDir) A convenience API forFileRepository(File)
.FileRepository
(BaseRepositoryBuilder options) Create a repository using the local file system. -
Method Summary
Modifier and TypeMethodDescriptionvoid
autoGC
(ProgressMonitor monitor) Check whether any housekeeping is required; if yes, run garbage collection; if not, exit without performing any work.void
convertRefStorage
(String format, boolean writeLogs, boolean backup) Converts between ref storage formats.(package private) void
convertToPackedRefs
(boolean writeLogs, boolean backup) Converts the RefDatabase from reftable to RefDirectory.(package private) void
convertToReftable
(boolean writeLogs, boolean backup) Converts the RefDatabase from RefDirectory to reftable.void
create
(boolean bare) Create a new Git repository initializing the necessary files and directories.Create a newAttributesNodeProvider
.private File
private void
Detect index changes.Objects known to exist but not expressed byRepository.getAllRefs()
.Objects known to exist but not expressed by#getAllRefs()
.Get the configuration of this repository.Read theGIT_DIR/description
file for gitweb.Get repository identifier.Get the object database which stores this repository's data.Get the directory containing the objects owned by this repositoryGet the reference database which stores the reference namespace.getReflogReader
(String refName) Get the reflog readerprivate void
void
notifyIndexChanged
(boolean internal) Notify that the index changed by firing an IndexChangedEvent.void
Add a single existing pack to the list of available pack files.void
Force a scan for changed refs.void
setGitwebDescription
(String description) Set theGIT_DIR/description
file for gitweb.private boolean
Methods inherited from class org.eclipse.jgit.lib.Repository
close, create, doClose, exactRef, findRef, fireEvent, getAllRefs, getAllRefsByPeeledObjectId, getBranch, getDirectory, getFS, getFullBranch, getGlobalListenerList, getIndexFile, getInitialBranch, getListenerList, getRemoteName, getRemoteNames, getRepositoryState, getTags, getWorkTree, hasObject, incrementOpen, isBare, isValidRefName, lockDirCache, newObjectInserter, newObjectReader, normalizeBranchName, open, open, parseCommit, peel, readCherryPickHead, readCommitEditMsg, readDirCache, readMergeCommitMsg, readMergeHeads, readOrigHead, readRebaseTodo, readRevertHead, readSquashCommitMsg, renameRef, resolve, shortenRefName, shortenRemoteBranchName, simplify, stripWorkDir, toString, updateRef, updateRef, writeCherryPickHead, writeCommitEditMsg, writeMergeCommitMsg, writeMergeHeads, writeOrigHead, writeRebaseTodoFile, writeRevertHead, writeSquashCommitMsg
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
UNNAMED
- See Also:
-
repoConfig
-
refs
-
objectDatabase
-
snapshotLock
-
snapshot
-
-
Constructor Details
-
FileRepository
Construct a representation of a Git repository.The work tree, object directory, alternate object directories and index file locations are deduced from the given git directory and the default rules by running
FileRepositoryBuilder
. This constructor is the same as saying:new FileRepositoryBuilder().setGitDir(gitDir).build()
- Parameters:
gitDir
- GIT_DIR (the location of the repository metadata).- Throws:
IOException
- the repository appears to already exist but cannot be accessed.- See Also:
-
FileRepository
A convenience API forFileRepository(File)
.- Parameters:
gitDir
- GIT_DIR (the location of the repository metadata).- Throws:
IOException
- the repository appears to already exist but cannot be accessed.- See Also:
-
FileRepository
Create a repository using the local file system.- Parameters:
options
- description of the repository's important paths.- Throws:
IOException
- the user configuration file or repository configuration file cannot be accessed.
-
-
Method Details
-
loadRepoConfig
- Throws:
IOException
-
create
Create a new Git repository initializing the necessary files and directories.Create a new Git repository initializing the necessary files and directories.
- Specified by:
create
in classRepository
- Parameters:
bare
- if true, a bare repository (a repository without a working directory) is created.- Throws:
IOException
- in case of IO problem
-
getObjectsDirectory
Get the directory containing the objects owned by this repository- Returns:
- the directory containing the objects owned by this repository.
-
getObjectDatabase
Get the object database which stores this repository's data.- Specified by:
getObjectDatabase
in classRepository
- Returns:
- the object database which stores this repository's data.
-
getRefDatabase
Get the reference database which stores the reference namespace.- Specified by:
getRefDatabase
in classRepository
- Returns:
- the reference database which stores the reference namespace.
-
getIdentifier
Get repository identifier.- Specified by:
getIdentifier
in classRepository
- Returns:
- repository identifier. The returned identifier has to be unique within a given Git server.
-
getConfig
Get the configuration of this repository.- Specified by:
getConfig
in classRepository
- Returns:
- the configuration of this repository.
-
getGitwebDescription
Read theGIT_DIR/description
file for gitweb.- Overrides:
getGitwebDescription
in classRepository
- Returns:
- description text; null if no description has been configured.
- Throws:
IOException
- description cannot be accessed.
-
setGitwebDescription
Set theGIT_DIR/description
file for gitweb.- Overrides:
setGitwebDescription
in classRepository
- Parameters:
description
- new description; null to clear the description.- Throws:
IOException
- description cannot be persisted.
-
descriptionFile
-
getAdditionalHaves
Objects known to exist but not expressed byRepository.getAllRefs()
.When a repository borrows objects from another repository, it can advertise that it safely has that other repository's references, without exposing any other details about the other repository. This may help a client trying to push changes avoid pushing more than it needs to.
Objects known to exist but not expressed by
#getAllRefs()
.When a repository borrows objects from another repository, it can advertise that it safely has that other repository's references, without exposing any other details about the other repository. This may help a client trying to push changes avoid pushing more than it needs to.
- Overrides:
getAdditionalHaves
in classRepository
- Returns:
- unmodifiable collection of other known objects.
- Throws:
IOException
-
getAdditionalHaves
private Set<ObjectId> getAdditionalHaves(Set<ObjectDirectory.AlternateHandle.Id> skips) throws IOException Objects known to exist but not expressed by#getAllRefs()
.When a repository borrows objects from another repository, it can advertise that it safely has that other repository's references, without exposing any other details about the other repository. This may help a client trying to push changes avoid pushing more than it needs to.
- Parameters:
skips
- Set of AlternateHandle Ids already seen- Returns:
- unmodifiable collection of other known objects.
- Throws:
IOException
- if getting refs hits an IO error
-
openPack
Add a single existing pack to the list of available pack files.- Parameters:
pack
- path of the pack file to open.- Throws:
IOException
- index file could not be opened, read, or is not recognized as a Git pack file index.
-
scanForRepoChanges
Force a scan for changed refs. Fires an IndexChangedEvent(false) if changes are detected.- Specified by:
scanForRepoChanges
in classRepository
- Throws:
IOException
-
detectIndexChanges
private void detectIndexChanges()Detect index changes. -
notifyIndexChanged
public void notifyIndexChanged(boolean internal) Notify that the index changed by firing an IndexChangedEvent.- Specified by:
notifyIndexChanged
in classRepository
- Parameters:
internal
-true
if the index was changed by the same JGit process
-
getReflogReader
Get the reflog reader- Specified by:
getReflogReader
in classRepository
- Parameters:
refName
- aString
object.- Returns:
- a
ReflogReader
for the supplied refname, ornull
if the named ref does not exist. - Throws:
IOException
- the ref could not be accessed.
-
createAttributesNodeProvider
Create a newAttributesNodeProvider
.- Specified by:
createAttributesNodeProvider
in classRepository
- Returns:
- a new
AttributesNodeProvider
. ThisAttributesNodeProvider
is lazy loaded only once. It means that it will not be updated after loading. Prefer creating new instance for each use.
-
shouldAutoDetach
private boolean shouldAutoDetach() -
autoGC
Check whether any housekeeping is required; if yes, run garbage collection; if not, exit without performing any work. Some JGit commands run autoGC after performing operations that could create many loose objects.Currently this option is supported for repositories of type
FileRepository
only. SeeGC.setAuto(boolean)
for configuration details.- Overrides:
autoGC
in classRepository
- Parameters:
monitor
- to report progress
-
convertToPackedRefs
Converts the RefDatabase from reftable to RefDirectory. This operation is not atomic.- Parameters:
writeLogs
- whether to write reflogsbackup
- whether to rename or delete the old storage files. If set totrue
, the reftable list is left inrefs.old
, and thereftable/
dir is left alone. If set tofalse
, thereftable/
dir is removed, andrefs
file is removed.- Throws:
IOException
- on IO problem
-
convertToReftable
Converts the RefDatabase from RefDirectory to reftable. This operation is not atomic.- Parameters:
writeLogs
- whether to write reflogsbackup
- whether to rename or delete the old storage files. If set totrue
, the loose refs are left inrefs.old
, the packed-refs inpacked-refs.old
and reflogs inrefs.old/
. HEAD is left inHEAD.old
and also.log
is appended to additional refs. If set tofalse
, therefs/
andlogs/
directories andHEAD
and additional symbolic refs are removed.- Throws:
IOException
- on IO problem
-
convertRefStorage
Converts between ref storage formats.- Parameters:
format
- the format to convert to, either "reftable" or "refdir"writeLogs
- whether to write reflogsbackup
- whether to make a backup of the old data- Throws:
IOException
- on I/O problems.
-