Class VersionedMetaData
- java.lang.Object
-
- com.google.gerrit.server.git.meta.VersionedMetaData
-
- Direct Known Subclasses:
AccountConfig,ExternalIdNotes,GroupConfig,GroupNameNotes,ProjectConfig,ProjectLevelConfig.Bare,VersionedAccountDestinations,VersionedAccountQueries,VersionedAuthorizedKeys,VersionedDefaultPreferences,VersionedMetaDataOnInit
public abstract class VersionedMetaData extends Object
Support for metadata stored within a version controlled branch.Implementors are responsible for supplying implementations of the onLoad and onSave methods to read from the repository, or format an update that can later be written back to the repository.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceVersionedMetaData.BatchMetaDataUpdatestatic classVersionedMetaData.PathInfoPath information that does not hold references to any repository data structures, allowing the application to retain this object for long periods of time.
-
Field Summary
Fields Modifier and Type Field Description protected org.eclipse.jgit.lib.ObjectInserterinserterprotected org.eclipse.jgit.dircache.DirCachenewTreeprotected Project.NameKeyprojectNameprotected org.eclipse.jgit.lib.ObjectReaderreaderprotected org.eclipse.jgit.revwalk.RevCommitrevisionThe revision at which the data was loaded.protected org.eclipse.jgit.revwalk.RevWalkrw
-
Constructor Summary
Constructors Constructor Description VersionedMetaData()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description org.eclipse.jgit.revwalk.RevCommitcommit(MetaDataUpdate update)Update this metadata branch, recording a new commit on its reference.org.eclipse.jgit.revwalk.RevCommitcommitToNewRef(MetaDataUpdate update, String refName)Creates a new commit and a new ref based on this commit.protected org.eclipse.jgit.lib.ObjectIdgetObjectId(String fileName)List<VersionedMetaData.PathInfo>getPathInfos(boolean recursive)protected abstract StringgetRefName()org.eclipse.jgit.lib.ObjectIdgetRevision()voidload(Project.NameKey projectName, org.eclipse.jgit.lib.Repository db)Load the current version from the branch.voidload(Project.NameKey projectName, org.eclipse.jgit.lib.Repository db, org.eclipse.jgit.lib.ObjectId id)Load a specific version from the repository.voidload(Project.NameKey projectName, org.eclipse.jgit.revwalk.RevWalk walk, org.eclipse.jgit.lib.ObjectId id)Load a specific version from an open walk.voidload(MetaDataUpdate update)voidload(MetaDataUpdate update, org.eclipse.jgit.lib.ObjectId id)protected abstract voidonLoad()Set up the metadata, parsing any state from the loaded revision.protected abstract booleanonSave(org.eclipse.jgit.lib.CommitBuilder commit)Save any changes to the metadata in a commit.VersionedMetaData.BatchMetaDataUpdateopenUpdate(MetaDataUpdate update)Open a batch of updates to the same metadata ref.protected org.eclipse.jgit.lib.ConfigreadConfig(String fileName)protected org.eclipse.jgit.lib.ConfigreadConfig(String fileName, org.eclipse.jgit.lib.Config baseConfig)protected byte[]readFile(String fileName)protected org.eclipse.jgit.dircache.DirCachereadTree(org.eclipse.jgit.revwalk.RevTree tree)protected StringreadUTF8(String fileName)protected voidsaveConfig(String fileName, org.eclipse.jgit.lib.Config cfg)protected voidsaveFile(String fileName, byte[] raw)protected voidsaveUTF8(String fileName, String text)protected static voidset(org.eclipse.jgit.lib.Config rc, String section, String subsection, String name, boolean value)protected static <E extends Enum<?>>
voidset(org.eclipse.jgit.lib.Config rc, String section, String subsection, String name, E value, E defaultValue)protected static voidset(org.eclipse.jgit.lib.Config rc, String section, String subsection, String name, String value)
-
-
-
Field Detail
-
revision
protected org.eclipse.jgit.revwalk.RevCommit revision
The revision at which the data was loaded. Is null for data yet to be created.
-
projectName
protected Project.NameKey projectName
-
rw
protected org.eclipse.jgit.revwalk.RevWalk rw
-
reader
protected org.eclipse.jgit.lib.ObjectReader reader
-
inserter
protected org.eclipse.jgit.lib.ObjectInserter inserter
-
newTree
protected org.eclipse.jgit.dircache.DirCache newTree
-
-
Method Detail
-
getRefName
protected abstract String getRefName()
- Returns:
- name of the reference storing this configuration.
-
onLoad
protected abstract void onLoad() throws IOException, org.eclipse.jgit.errors.ConfigInvalidExceptionSet up the metadata, parsing any state from the loaded revision.- Throws:
IOExceptionorg.eclipse.jgit.errors.ConfigInvalidException
-
onSave
protected abstract boolean onSave(org.eclipse.jgit.lib.CommitBuilder commit) throws IOException, org.eclipse.jgit.errors.ConfigInvalidExceptionSave any changes to the metadata in a commit.- Returns:
- true if the commit should proceed, false to abort.
- Throws:
IOExceptionorg.eclipse.jgit.errors.ConfigInvalidException
-
getRevision
public org.eclipse.jgit.lib.ObjectId getRevision()
- Returns:
- revision of the metadata that was loaded.
-
load
public void load(Project.NameKey projectName, org.eclipse.jgit.lib.Repository db) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
Load the current version from the branch.The repository is not held after the call completes, allowing the application to retain this object for long periods of time.
- Parameters:
projectName- the name of the projectdb- repository to access.- Throws:
IOExceptionorg.eclipse.jgit.errors.ConfigInvalidException
-
load
public void load(Project.NameKey projectName, org.eclipse.jgit.lib.Repository db, org.eclipse.jgit.lib.ObjectId id) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
Load a specific version from the repository.This method is primarily useful for applying updates to a specific revision that was shown to an end-user in the user interface. If there are conflicts with another user's concurrent changes, these will be automatically detected at commit time.
The repository is not held after the call completes, allowing the application to retain this object for long periods of time.
- Parameters:
projectName- the name of the projectdb- repository to access.id- revision to load.- Throws:
IOExceptionorg.eclipse.jgit.errors.ConfigInvalidException
-
load
public void load(Project.NameKey projectName, org.eclipse.jgit.revwalk.RevWalk walk, org.eclipse.jgit.lib.ObjectId id) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
Load a specific version from an open walk.This method is primarily useful for applying updates to a specific revision that was shown to an end-user in the user interface. If there are conflicts with another user's concurrent changes, these will be automatically detected at commit time.
The caller retains ownership of the walk and is responsible for closing it. However, this instance does not hold a reference to the walk or the repository after the call completes, allowing the application to retain this object for long periods of time.
- Parameters:
projectName- the name of the projectwalk- open walk to access to access.id- revision to load.- Throws:
IOExceptionorg.eclipse.jgit.errors.ConfigInvalidException
-
load
public void load(MetaDataUpdate update) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
- Throws:
IOExceptionorg.eclipse.jgit.errors.ConfigInvalidException
-
load
public void load(MetaDataUpdate update, org.eclipse.jgit.lib.ObjectId id) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
- Throws:
IOExceptionorg.eclipse.jgit.errors.ConfigInvalidException
-
commit
public org.eclipse.jgit.revwalk.RevCommit commit(MetaDataUpdate update) throws IOException
Update this metadata branch, recording a new commit on its reference. This method mutates its receiver.- Parameters:
update- helper information to define the update that will occur.- Returns:
- the commit that was created
- Throws:
IOException- if there is a storage problem and the update cannot be executed as requested or if it failed because of a concurrent update to the same reference
-
commitToNewRef
public org.eclipse.jgit.revwalk.RevCommit commitToNewRef(MetaDataUpdate update, String refName) throws IOException
Creates a new commit and a new ref based on this commit. This method mutates its receiver.- Parameters:
update- helper information to define the update that will occur.refName- name of the ref that should be created- Returns:
- the commit that was created
- Throws:
IOException- if there is a storage problem and the update cannot be executed as requested or if it failed because of a concurrent update to the same reference
-
openUpdate
public VersionedMetaData.BatchMetaDataUpdate openUpdate(MetaDataUpdate update) throws IOException
Open a batch of updates to the same metadata ref.This allows making multiple commits to a single metadata ref, at the end of which is a single ref update. For batching together updates to multiple refs (each consisting of one or more commits against their respective refs), create the
MetaDataUpdatewith aBatchRefUpdate.A ref update produced by this
VersionedMetaData.BatchMetaDataUpdateis only committed if there is no associatedBatchRefUpdate. As a result, the configured ref updated event is not fired if there is an associated batch.- Parameters:
update- helper info about the update.- Throws:
IOException- if the update failed.
-
readTree
protected org.eclipse.jgit.dircache.DirCache readTree(org.eclipse.jgit.revwalk.RevTree tree) throws IOException, org.eclipse.jgit.errors.MissingObjectException, org.eclipse.jgit.errors.IncorrectObjectTypeException- Throws:
IOExceptionorg.eclipse.jgit.errors.MissingObjectExceptionorg.eclipse.jgit.errors.IncorrectObjectTypeException
-
readConfig
protected org.eclipse.jgit.lib.Config readConfig(String fileName) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
- Throws:
IOExceptionorg.eclipse.jgit.errors.ConfigInvalidException
-
readConfig
protected org.eclipse.jgit.lib.Config readConfig(String fileName, org.eclipse.jgit.lib.Config baseConfig) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
- Throws:
IOExceptionorg.eclipse.jgit.errors.ConfigInvalidException
-
readUTF8
protected String readUTF8(String fileName) throws IOException
- Throws:
IOException
-
readFile
protected byte[] readFile(String fileName) throws IOException
- Throws:
IOException
-
getObjectId
protected org.eclipse.jgit.lib.ObjectId getObjectId(String fileName) throws IOException
- Throws:
IOException
-
getPathInfos
public List<VersionedMetaData.PathInfo> getPathInfos(boolean recursive) throws IOException
- Throws:
IOException
-
set
protected static void set(org.eclipse.jgit.lib.Config rc, String section, String subsection, String name, String value)
-
set
protected static void set(org.eclipse.jgit.lib.Config rc, String section, String subsection, String name, boolean value)
-
set
protected static <E extends Enum<?>> void set(org.eclipse.jgit.lib.Config rc, String section, String subsection, String name, E value, E defaultValue)
-
saveConfig
protected void saveConfig(String fileName, org.eclipse.jgit.lib.Config cfg) throws IOException
- Throws:
IOException
-
saveUTF8
protected void saveUTF8(String fileName, String text) throws IOException
- Throws:
IOException
-
saveFile
protected void saveFile(String fileName, byte[] raw) throws IOException
- Throws:
IOException
-
-