public class FileRepository extends Repository
This class is thread-safe.
This implementation only handles a subtly undocumented subset of git features.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
FileRepository.AttributesNodeProviderImpl
Implementation a
AttributesNodeProvider for a
FileRepository . |
Modifier and Type | Field and Description |
---|---|
private static org.slf4j.Logger |
LOG |
private ObjectDirectory |
objectDatabase |
private RefDatabase |
refs |
private FileBasedConfig |
repoConfig |
private FileSnapshot |
snapshot |
private java.lang.Object |
snapshotLock |
private static java.lang.String |
UNNAMED |
Constructor and Description |
---|
FileRepository(BaseRepositoryBuilder options)
Create a repository using the local file system.
|
FileRepository(java.io.File gitDir)
Construct a representation of a Git repository.
|
FileRepository(java.lang.String gitDir)
A convenience API for
FileRepository(File) . |
Modifier and Type | Method and Description |
---|---|
void |
autoGC(ProgressMonitor monitor)
Check whether any housekeeping is required; if yes, run garbage
collection; if not, exit without performing any work.
|
void |
convertRefStorage(java.lang.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.
|
AttributesNodeProvider |
createAttributesNodeProvider()
Create a new
AttributesNodeProvider . |
private java.io.File |
descriptionFile() |
private void |
detectIndexChanges()
Detect index changes.
|
java.util.Set<ObjectId> |
getAdditionalHaves()
Objects known to exist but not expressed by
Repository.getAllRefs() . |
private java.util.Set<ObjectId> |
getAdditionalHaves(java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)
Objects known to exist but not expressed by
#getAllRefs() . |
FileBasedConfig |
getConfig()
Get the configuration of this repository.
|
java.lang.String |
getGitwebDescription()
Read the
GIT_DIR/description file for gitweb. |
java.lang.String |
getIdentifier()
Get repository identifier.
|
ObjectDirectory |
getObjectDatabase()
Get the object database which stores this repository's data.
|
java.io.File |
getObjectsDirectory()
Get the directory containing the objects owned by this repository
|
RefDatabase |
getRefDatabase()
Get the reference database which stores the reference namespace.
|
ReflogReader |
getReflogReader(java.lang.String refName)
Get the reflog reader
|
private void |
loadRepoConfig() |
void |
notifyIndexChanged(boolean internal)
Notify that the index changed by firing an IndexChangedEvent.
|
void |
openPack(java.io.File pack)
Add a single existing pack to the list of available pack files.
|
void |
scanForRepoChanges()
Force a scan for changed refs.
|
void |
setGitwebDescription(java.lang.String description)
Set the
GIT_DIR/description file for gitweb. |
private boolean |
shouldAutoDetach() |
close, create, doClose, exactRef, findRef, fireEvent, getAllRefs, getAllRefsByPeeledObjectId, getBranch, getDirectory, getFS, getFullBranch, getGlobalListenerList, getIndexFile, 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
private static final org.slf4j.Logger LOG
private static final java.lang.String UNNAMED
private final FileBasedConfig repoConfig
private RefDatabase refs
private final ObjectDirectory objectDatabase
private final java.lang.Object snapshotLock
private FileSnapshot snapshot
public FileRepository(java.io.File gitDir) throws java.io.IOException
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()
gitDir
- GIT_DIR (the location of the repository metadata).java.io.IOException
- the repository appears to already exist but cannot be
accessed.FileRepositoryBuilder
public FileRepository(java.lang.String gitDir) throws java.io.IOException
FileRepository(File)
.gitDir
- GIT_DIR (the location of the repository metadata).java.io.IOException
- the repository appears to already exist but cannot be
accessed.FileRepositoryBuilder
public FileRepository(BaseRepositoryBuilder options) throws java.io.IOException
options
- description of the repository's important paths.java.io.IOException
- the user configuration file or repository configuration file
cannot be accessed.private void loadRepoConfig() throws java.io.IOException
java.io.IOException
public void create(boolean bare) throws java.io.IOException
Create a new Git repository initializing the necessary files and directories.
create
in class Repository
bare
- if true, a bare repository (a repository without a working
directory) is created.java.io.IOException
- in case of IO problempublic java.io.File getObjectsDirectory()
public ObjectDirectory getObjectDatabase()
getObjectDatabase
in class Repository
public RefDatabase getRefDatabase()
getRefDatabase
in class Repository
public java.lang.String getIdentifier()
getIdentifier
in class Repository
public FileBasedConfig getConfig()
getConfig
in class Repository
@Nullable public java.lang.String getGitwebDescription() throws java.io.IOException
GIT_DIR/description
file for gitweb.getGitwebDescription
in class Repository
java.io.IOException
- description cannot be accessed.public void setGitwebDescription(@Nullable java.lang.String description) throws java.io.IOException
GIT_DIR/description
file for gitweb.setGitwebDescription
in class Repository
description
- new description; null to clear the description.java.io.IOException
- description cannot be persisted.private java.io.File descriptionFile()
public java.util.Set<ObjectId> getAdditionalHaves()
Repository.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.
getAdditionalHaves
in class Repository
private java.util.Set<ObjectId> getAdditionalHaves(java.util.Set<ObjectDirectory.AlternateHandle.Id> skips)
#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.
skips
- Set of AlternateHandle Ids already seenpublic void openPack(java.io.File pack) throws java.io.IOException
pack
- path of the pack file to open.java.io.IOException
- index file could not be opened, read, or is not recognized as
a Git pack file index.public void scanForRepoChanges() throws java.io.IOException
scanForRepoChanges
in class Repository
java.io.IOException
private void detectIndexChanges()
public void notifyIndexChanged(boolean internal)
notifyIndexChanged
in class Repository
internal
- true
if the index was changed by the same
JGit processpublic ReflogReader getReflogReader(java.lang.String refName) throws java.io.IOException
getReflogReader
in class Repository
refName
- a String
object.ReflogReader
for the supplied
refname, or null
if the named ref does not exist.java.io.IOException
- the ref could not be accessed.public AttributesNodeProvider createAttributesNodeProvider()
AttributesNodeProvider
.createAttributesNodeProvider
in class Repository
AttributesNodeProvider
.
This AttributesNodeProvider
is lazy loaded only once. It means that it will not be updated
after loading. Prefer creating new instance for each use.private boolean shouldAutoDetach()
public void autoGC(ProgressMonitor monitor)
Currently this option is supported for repositories of type
FileRepository
only. See
GC.setAuto(boolean)
for
configuration details.
autoGC
in class Repository
monitor
- to report progressvoid convertToPackedRefs(boolean writeLogs, boolean backup) throws java.io.IOException
writeLogs
- whether to write reflogsbackup
- whether to rename or delete the old storage files. If set to
true
, the reftable list is left in refs.old
,
and the reftable/
dir is left alone. If set to
false
, the reftable/
dir is removed, and
refs
file is removed.java.io.IOException
- on IO problemvoid convertToReftable(boolean writeLogs, boolean backup) throws java.io.IOException
writeLogs
- whether to write reflogsbackup
- whether to rename or delete the old storage files. If set to
true
, the loose refs are left in refs.old
, the
packed-refs in packed-refs.old
and reflogs in
refs.old/
. HEAD is left in HEAD.old
and also
.log
is appended to additional refs. If set to
false
, the refs/
and logs/
directories
and HEAD
and additional symbolic refs are removed.java.io.IOException
- on IO problempublic void convertRefStorage(java.lang.String format, boolean writeLogs, boolean backup) throws java.io.IOException
format
- the format to convert to, either "reftable" or "refdir"writeLogs
- whether to write reflogsbackup
- whether to make a backup of the old datajava.io.IOException
- on I/O problems.