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

public Class FileRepository

extends Repository
Class Inheritance
Static Imports
java.util.stream.Collectors.toList

Represents a Git repository. A repository holds all objects and refs used for managing source code (could by any type of file, but source code is what SCM's are typically used for). In Git terms all data is stored in GIT_DIR, typically a directory called .git. A work tree is maintained unless the repository is a bare repository. Typically the .git directory is located at the root of the work dir.

This class is thread-safe.

This implementation only handles a subtly undocumented subset of git features.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final Logger
private final ObjectDirectory
private RefDatabase
private final FileBasedConfig
private FileSnapshot
private final Object
private static final String

Constructor Summary

AccessConstructor and Description
public
FileRepository(File
GIT_DIR (the location of the repository metadata).
gitDir
)

Construct a representation of a Git repository.

public
FileRepository(String
GIT_DIR (the location of the repository metadata).
gitDir
)

A convenience API for FileRepository(File).

public
FileRepository(BaseRepositoryBuilder<B extends BaseRepositoryBuilder, R extends Repository>
description of the repository's important paths.
options
)

Create a repository using the local file system.

Method Summary

Modifier and TypeMethod and Description
public void
autoGC(ProgressMonitor
to report progress
monitor
)

Overrides org.eclipse.jgit.lib.Repository.autoGC.

Check whether any housekeeping is required; if yes, run garbage collection; if not, exit without performing any work.

public void
convertRefStorage(String
the format to convert to, either "reftable" or "refdir"
format
,
boolean
whether to write reflogs
writeLogs
,
boolean
whether to make a backup of the old data
backup
)

Converts between ref storage formats.

pack-priv void
convertToPackedRefs(boolean
whether to write reflogs
writeLogs
,
boolean
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.
backup
)

Converts the RefDatabase from reftable to RefDirectory.

pack-priv void
convertToReftable(boolean
whether to write reflogs
writeLogs
,
boolean
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.
backup
)

Converts the RefDatabase from RefDirectory to reftable.

public void
create(boolean
if true, a bare repository (a repository without a working directory) is created.
bare
)

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

Create a new Git repository initializing the necessary files and directories.

public void
create(boolean
if true, a bare repository (a repository without a working directory) is created.
bare
,
boolean
if true, relative paths are used for GIT_DIR and GIT_WORK_TREE
relativePaths
)

Create a new Git repository initializing the necessary files and directories.

public AttributesNodeProvider
private File
private void
detectIndexChanges()

Detect index changes.

public Set<ObjectId>
getAdditionalHaves()

Overrides org.eclipse.jgit.lib.Repository.getAdditionalHaves.

Objects known to exist but not expressed by getAllRefs().

private Set<ObjectId>

Returns:

unmodifiable collection of other known objects.
getAdditionalHaves
(Set<ObjectDirectory.AlternateHandle.Id>
Set of AlternateHandle Ids already seen
skips
)

Objects known to exist but not expressed by #getAllRefs().

public FileBasedConfig
getConfig()

Implements abstract org.eclipse.jgit.lib.Repository.getConfig.

Get the configuration of this repository.

public String
getGitwebDescription()

Overrides org.eclipse.jgit.lib.Repository.getGitwebDescription.

Read the GIT_DIR/description file for gitweb.

public String
getIdentifier()

Implements abstract org.eclipse.jgit.lib.Repository.getIdentifier.

Get repository identifier.

public ObjectDirectory
getObjectDatabase()

Implements abstract org.eclipse.jgit.lib.Repository.getObjectDatabase.

Get the object database which stores this repository's data.

public File

Returns:

the directory containing the objects owned by this repository.
getObjectsDirectory
()

Get the directory containing the objects owned by this repository

public RefDatabase
getRefDatabase()

Implements abstract org.eclipse.jgit.lib.Repository.getRefDatabase.

Get the reference database which stores the reference namespace.

private String
getRelativeDir(File base, File other)

private void
public void
notifyIndexChanged(boolean
true if the index was changed by the same JGit process
internal
)

Implements abstract org.eclipse.jgit.lib.Repository.notifyIndexChanged.

Notify that the index changed by firing an IndexChangedEvent.

public void
openPack(File
path of the pack file to open.
pack
)

Add a single existing pack to the list of available pack files.

public void
scanForRepoChanges()

Implements abstract org.eclipse.jgit.lib.Repository.scanForRepoChanges.

Force a scan for changed refs.

public void
setGitwebDescription(String
new description; null to clear the description.
description
)

Overrides org.eclipse.jgit.lib.Repository.setGitwebDescription.

Set the GIT_DIR/description file for gitweb.

private boolean
Inherited from org.eclipse.jgit.lib.Repository:
closecreatedoCloseexactReffindReffireEventgetAllRefsgetAllRefsByPeeledObjectIdgetBranchgetCommonDirectorygetDirectorygetFSgetFullBranchgetGlobalListenerListgetIndexFilegetInitialBranchgetListenerListgetReflogReadergetReflogReadergetRemoteNamegetRemoteNamesgetRepositoryStategetTagsgetWorkTreeincrementOpenisBareisValidRefNameisWorkTreeCaseInsensitivelockDirCachenewObjectInserternewObjectReadernormalizeBranchNameopenopenparseCommitreadCherryPickHeadreadCommitEditMsgreadDirCachereadMergeCommitMsgreadMergeHeadsreadOrigHeadreadRebaseTodoreadRevertHeadreadSquashCommitMsgrenameRefresolveshortenRefNameshortenRemoteBranchNamesimplifystripWorkDirtoStringupdateRefupdateRefwriteCherryPickHeadwriteCommitEditMsgwriteMergeCommitMsgwriteMergeHeadswriteOrigHeadwriteRebaseTodoFilewriteRevertHeadwriteSquashCommitMsg

Field Detail

LOGback to summary
private static final Logger LOG

Hides org.eclipse.jgit.lib.Repository.LOG.

objectDatabaseback to summary
private final ObjectDirectory objectDatabase
refsback to summary
private RefDatabase refs
repoConfigback to summary
private final FileBasedConfig repoConfig
snapshotback to summary
private FileSnapshot snapshot
snapshotLockback to summary
private final Object snapshotLock
UNNAMEDback to summary
private static final String UNNAMED

Constructor Detail

FileRepositoryback to summary
public FileRepository(File gitDir) throws IOException

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 org.eclipse.jgit.storage.file.FileRepositoryBuilder. This constructor is the same as saying:

new FileRepositoryBuilder().setGitDir(gitDir).build()
Parameters
gitDir:File

GIT_DIR (the location of the repository metadata).

Exceptions
IOException:
the repository appears to already exist but cannot be accessed.
See Also
FileRepositoryBuilder
FileRepositoryback to summary
public FileRepository(String gitDir) throws IOException

A convenience API for FileRepository(File).

Parameters
gitDir:String

GIT_DIR (the location of the repository metadata).

Exceptions
IOException:
the repository appears to already exist but cannot be accessed.
See Also
FileRepositoryBuilder
FileRepositoryback to summary
public FileRepository(BaseRepositoryBuilder<B extends BaseRepositoryBuilder, R extends Repository> options) throws IOException

Create a repository using the local file system.

Parameters
options:BaseRepositoryBuilder<B extends BaseRepositoryBuilder, R extends Repository>

description of the repository's important paths.

Exceptions
IOException:
the user configuration file or repository configuration file cannot be accessed.

Method Detail

autoGCback to summary
public void autoGC(ProgressMonitor monitor)

Overrides org.eclipse.jgit.lib.Repository.autoGC.

Doc from org.eclipse.jgit.lib.Repository.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. See org.eclipse.jgit.internal.storage.file.GC#setAuto(boolean) for configuration details.

Parameters
monitor:ProgressMonitor

to report progress

Annotations
@SuppressWarnings:FutureReturnValueIgnored
@Override
convertRefStorageback to summary
public void convertRefStorage(String format, boolean writeLogs, boolean backup) throws IOException

Converts between ref storage formats.

Parameters
format:String

the format to convert to, either "reftable" or "refdir"

writeLogs:boolean

whether to write reflogs

backup:boolean

whether to make a backup of the old data

Exceptions
IOException:
on I/O problems.
convertToPackedRefsback to summary
pack-priv void convertToPackedRefs(boolean writeLogs, boolean backup) throws IOException

Converts the RefDatabase from reftable to RefDirectory. This operation is not atomic.

Parameters
writeLogs:boolean

whether to write reflogs

backup:boolean

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.

Exceptions
IOException:
on IO problem
convertToReftableback to summary
pack-priv void convertToReftable(boolean writeLogs, boolean backup) throws IOException

Converts the RefDatabase from RefDirectory to reftable. This operation is not atomic.

Parameters
writeLogs:boolean

whether to write reflogs

backup:boolean

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.

Annotations
@SuppressWarnings:nls
Exceptions
IOException:
on IO problem
createback to summary
public void create(boolean bare) throws IOException

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

Doc from org.eclipse.jgit.lib.Repository.create.

Create a new Git repository initializing the necessary files and directories.

Create a new Git repository initializing the necessary files and directories.

Parameters
bare:boolean

if true, a bare repository (a repository without a working directory) is created.

Annotations
@Override
Exceptions
IOException:
in case of IO problem
createback to summary
public void create(boolean bare, boolean relativePaths) throws IOException

Create a new Git repository initializing the necessary files and directories.

Parameters
bare:boolean

if true, a bare repository (a repository without a working directory) is created.

relativePaths:boolean

if true, relative paths are used for GIT_DIR and GIT_WORK_TREE

Exceptions
IOException:
in case of IO problem
createAttributesNodeProviderback to summary
public AttributesNodeProvider createAttributesNodeProvider()

Implements abstract org.eclipse.jgit.lib.Repository.createAttributesNodeProvider.

Doc from org.eclipse.jgit.lib.Repository.createAttributesNodeProvider.

Create a new org.eclipse.jgit.attributes.AttributesNodeProvider.

Returns:AttributesNodeProvider

a new org.eclipse.jgit.attributes.AttributesNodeProvider. This org.eclipse.jgit.attributes.AttributesNodeProvider is lazy loaded only once. It means that it will not be updated after loading. Prefer creating new instance for each use.

Annotations
@Override
descriptionFileback to summary
private File descriptionFile()
detectIndexChangesback to summary
private void detectIndexChanges()

Detect index changes.

getAdditionalHavesback to summary
public Set<ObjectId> getAdditionalHaves() throws IOException

Overrides org.eclipse.jgit.lib.Repository.getAdditionalHaves.

Doc from org.eclipse.jgit.lib.Repository.getAdditionalHaves.

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.

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.

Returns:Set<ObjectId>

unmodifiable collection of other known objects.

Annotations
@Override
Exceptions
IOException:
if an IO error occurred
getAdditionalHavesback to summary
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<ObjectDirectory.AlternateHandle.Id>

Set of AlternateHandle Ids already seen

Returns:Set<ObjectId>

unmodifiable collection of other known objects.

Exceptions
IOException:
if getting refs hits an IO error
getConfigback to summary
public FileBasedConfig getConfig()

Implements abstract org.eclipse.jgit.lib.Repository.getConfig.

Doc from org.eclipse.jgit.lib.Repository.getConfig.

Get the configuration of this repository.

Returns:FileBasedConfig

the configuration of this repository.

Annotations
@Override
getGitwebDescriptionback to summary
public String getGitwebDescription() throws IOException

Overrides org.eclipse.jgit.lib.Repository.getGitwebDescription.

Doc from org.eclipse.jgit.lib.Repository.getGitwebDescription.

Read the GIT_DIR/description file for gitweb.

Returns:String

description text; null if no description has been configured.

Annotations
@Override
@Nullable
Exceptions
IOException:
description cannot be accessed.
getIdentifierback to summary
public String getIdentifier()

Implements abstract org.eclipse.jgit.lib.Repository.getIdentifier.

Doc from org.eclipse.jgit.lib.Repository.getIdentifier.

Get repository identifier.

Returns:String

repository identifier. The returned identifier has to be unique within a given Git server.

Annotations
@Override
getObjectDatabaseback to summary
public ObjectDirectory getObjectDatabase()

Implements abstract org.eclipse.jgit.lib.Repository.getObjectDatabase.

Doc from org.eclipse.jgit.lib.Repository.getObjectDatabase.

Get the object database which stores this repository's data.

Returns:ObjectDirectory

the object database which stores this repository's data.

Annotations
@Override
getObjectsDirectoryback to summary
public File getObjectsDirectory()

Get the directory containing the objects owned by this repository

Returns:File

the directory containing the objects owned by this repository.

getRefDatabaseback to summary
public RefDatabase getRefDatabase()

Implements abstract org.eclipse.jgit.lib.Repository.getRefDatabase.

Doc from org.eclipse.jgit.lib.Repository.getRefDatabase.

Get the reference database which stores the reference namespace.

Returns:RefDatabase

the reference database which stores the reference namespace.

Annotations
@Override
getRelativeDirback to summary
private String getRelativeDir(File base, File other)
loadRepoConfigback to summary
private void loadRepoConfig() throws IOException
notifyIndexChangedback to summary
public void notifyIndexChanged(boolean internal)

Implements abstract org.eclipse.jgit.lib.Repository.notifyIndexChanged.

Doc from org.eclipse.jgit.lib.Repository.notifyIndexChanged.

Notify that the index changed by firing an IndexChangedEvent.

Parameters
internal:boolean

true if the index was changed by the same JGit process

Annotations
@Override
openPackback to summary
public void openPack(File pack) throws IOException

Add a single existing pack to the list of available pack files.

Parameters
pack:File

path of the pack file to open.

Exceptions
IOException:
index file could not be opened, read, or is not recognized as a Git pack file index.
scanForRepoChangesback to summary
public void scanForRepoChanges() throws IOException

Implements abstract org.eclipse.jgit.lib.Repository.scanForRepoChanges.

Doc from org.eclipse.jgit.lib.Repository.scanForRepoChanges.

Force a scan for changed refs. Fires an IndexChangedEvent(false) if changes are detected.

Annotations
@Override
Exceptions
IOException:
if an IO error occurred
setGitwebDescriptionback to summary
public void setGitwebDescription(String description) throws IOException

Overrides org.eclipse.jgit.lib.Repository.setGitwebDescription.

Doc from org.eclipse.jgit.lib.Repository.setGitwebDescription.

Set the GIT_DIR/description file for gitweb.

Parameters
description:String

new description; null to clear the description.

Annotations
@Override
Exceptions
IOException:
description cannot be persisted.
shouldAutoDetachback to summary
private boolean shouldAutoDetach()
org.eclipse.jgit.internal.storage.file back to summary

pack-priv Class FileRepository.AttributesNodeProviderImpl

extends Object
implements AttributesNodeProvider
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.internal.storage.file.FileRepository.AttributesNodeProviderImpl
All Implemented Interfaces
org.eclipse.jgit.attributes.AttributesNodeProvider

Implementation a AttributesNodeProvider for a FileRepository.
Author
Arthur Daussy

Field Summary

Modifier and TypeField and Description
private AttributesNode
private AttributesNode

Constructor Summary

AccessConstructor and Description
protected
AttributesNodeProviderImpl(Repository
Repository that will provide the attribute nodes.
repo
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public AttributesNode
getGlobalAttributesNode()

Implements org.eclipse.jgit.attributes.AttributesNodeProvider.getGlobalAttributesNode.

Retrieve the org.eclipse.jgit.attributes.AttributesNode that holds the information located in the global gitattributes file.

public AttributesNode
getInfoAttributesNode()

Implements org.eclipse.jgit.attributes.AttributesNodeProvider.getInfoAttributesNode.

Retrieve the org.eclipse.jgit.attributes.AttributesNode that holds the information located in $GIT_DIR/info/attributes file.

pack-priv static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

globalAttributesNodeback to summary
private AttributesNode globalAttributesNode
infoAttributesNodeback to summary
private AttributesNode infoAttributesNode

Constructor Detail

AttributesNodeProviderImplback to summary
protected AttributesNodeProviderImpl(Repository repo)

Constructor.

Parameters
repo:Repository

Repository that will provide the attribute nodes.

Method Detail

getGlobalAttributesNodeback to summary
public AttributesNode getGlobalAttributesNode() throws IOException

Implements org.eclipse.jgit.attributes.AttributesNodeProvider.getGlobalAttributesNode.

Doc from org.eclipse.jgit.attributes.AttributesNodeProvider.getGlobalAttributesNode.

Retrieve the org.eclipse.jgit.attributes.AttributesNode that holds the information located in the global gitattributes file.

Returns:AttributesNode

the org.eclipse.jgit.attributes.AttributesNode that holds the information located in the global gitattributes file.

Annotations
@Override
Exceptions
IOException:
java.io.IOException if an error is raised while parsing the attributes file
getInfoAttributesNodeback to summary
public AttributesNode getInfoAttributesNode() throws IOException

Implements org.eclipse.jgit.attributes.AttributesNodeProvider.getInfoAttributesNode.

Doc from org.eclipse.jgit.attributes.AttributesNodeProvider.getInfoAttributesNode.

Retrieve the org.eclipse.jgit.attributes.AttributesNode that holds the information located in $GIT_DIR/info/attributes file.

Returns:AttributesNode

the org.eclipse.jgit.attributes.AttributesNode that holds the information located in $GIT_DIR/info/attributes file.

Annotations
@Override
Exceptions
IOException:
if an error is raised while parsing the attributes file
loadRulesFromFileback to summary
pack-priv static void loadRulesFromFile(AttributesNode r, File attrs) throws FileNotFoundException, IOException