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 interface
VersionedMetaData.BatchMetaDataUpdate
static class
VersionedMetaData.PathInfo
Path 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.ObjectInserter
inserter
protected org.eclipse.jgit.dircache.DirCache
newTree
protected Project.NameKey
projectName
protected org.eclipse.jgit.lib.ObjectReader
reader
protected org.eclipse.jgit.revwalk.RevCommit
revision
The revision at which the data was loaded.protected org.eclipse.jgit.revwalk.RevWalk
rw
-
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.RevCommit
commit(MetaDataUpdate update)
Update this metadata branch, recording a new commit on its reference.org.eclipse.jgit.revwalk.RevCommit
commit(MetaDataUpdate update, org.eclipse.jgit.lib.ObjectInserter objInserter, org.eclipse.jgit.lib.ObjectReader objReader, org.eclipse.jgit.revwalk.RevWalk revWalk)
Update this metadata branch, recording a new commit on its reference.org.eclipse.jgit.revwalk.RevCommit
commitToNewRef(MetaDataUpdate update, String refName)
Creates a new commit and a new ref based on this commit.protected org.eclipse.jgit.lib.ObjectId
getObjectId(String fileName)
List<VersionedMetaData.PathInfo>
getPathInfos(boolean recursive)
protected abstract String
getRefName()
Returns name of the reference storing this configuration.org.eclipse.jgit.lib.ObjectId
getRevision()
Returns revision of the metadata that was loaded.void
load(Project.NameKey projectName, org.eclipse.jgit.lib.Repository db)
Load the current version from the branch.void
load(Project.NameKey projectName, org.eclipse.jgit.lib.Repository db, org.eclipse.jgit.lib.ObjectId id)
Load a specific version from the repository.void
load(Project.NameKey projectName, org.eclipse.jgit.revwalk.RevWalk walk, org.eclipse.jgit.lib.ObjectId id)
Load a specific version from an open walk.void
load(MetaDataUpdate update)
void
load(MetaDataUpdate update, org.eclipse.jgit.lib.ObjectId id)
protected abstract void
onLoad()
Set up the metadata, parsing any state from the loaded revision.protected abstract boolean
onSave(org.eclipse.jgit.lib.CommitBuilder commit)
Save any changes to the metadata in a commit.VersionedMetaData.BatchMetaDataUpdate
openUpdate(MetaDataUpdate update)
Open a batch of updates to the same metadata ref.VersionedMetaData.BatchMetaDataUpdate
openUpdate(MetaDataUpdate update, org.eclipse.jgit.lib.ObjectInserter objInserter, org.eclipse.jgit.lib.ObjectReader objReader, org.eclipse.jgit.revwalk.RevWalk revWalk)
Open a batch of updates to the same metadata ref.protected org.eclipse.jgit.lib.Config
readConfig(String fileName)
protected org.eclipse.jgit.lib.Config
readConfig(String fileName, Optional<? extends org.eclipse.jgit.lib.Config> baseConfig)
protected byte[]
readFile(String fileName)
protected org.eclipse.jgit.dircache.DirCache
readTree(org.eclipse.jgit.revwalk.RevTree tree)
protected String
readUTF8(String fileName)
protected void
saveConfig(String fileName, org.eclipse.jgit.lib.Config cfg)
protected void
saveFile(String fileName, byte[] raw)
protected void
saveUTF8(String fileName, String text)
protected static void
set(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 void
set(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.ConfigInvalidException
Set up the metadata, parsing any state from the loaded revision.- Throws:
IOException
org.eclipse.jgit.errors.ConfigInvalidException
-
onSave
protected abstract boolean onSave(org.eclipse.jgit.lib.CommitBuilder commit) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
Save any changes to the metadata in a commit.- Returns:
- true if the commit should proceed, false to abort.
- Throws:
IOException
org.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:
IOException
org.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:
IOException
org.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:
IOException
org.eclipse.jgit.errors.ConfigInvalidException
-
load
public void load(MetaDataUpdate update) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
- Throws:
IOException
org.eclipse.jgit.errors.ConfigInvalidException
-
load
public void load(MetaDataUpdate update, org.eclipse.jgit.lib.ObjectId id) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
- Throws:
IOException
org.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
-
commit
public org.eclipse.jgit.revwalk.RevCommit commit(MetaDataUpdate update, org.eclipse.jgit.lib.ObjectInserter objInserter, org.eclipse.jgit.lib.ObjectReader objReader, org.eclipse.jgit.revwalk.RevWalk revWalk) 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.objInserter
- Shared object inserter.objReader
- Shared object reader.revWalk
- Shared rev walk.- 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
MetaDataUpdate
with aBatchRefUpdate
.A ref update produced by this
VersionedMetaData.BatchMetaDataUpdate
is 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.
-
openUpdate
public VersionedMetaData.BatchMetaDataUpdate openUpdate(MetaDataUpdate update, org.eclipse.jgit.lib.ObjectInserter objInserter, org.eclipse.jgit.lib.ObjectReader objReader, org.eclipse.jgit.revwalk.RevWalk revWalk) 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
MetaDataUpdate
with aBatchRefUpdate
.A ref update produced by this
VersionedMetaData.BatchMetaDataUpdate
is only committed if there is no associatedBatchRefUpdate
. As a result, the configured ref updated event is not fired if there is an associated batch.If object inserter, reader and revwalk are provided, then the updates are not flushed, allowing callers the flexibility to flush only once after several updates.
- Parameters:
update
- helper info about the update.objInserter
- Shared object inserter.objReader
- Shared object reader.revWalk
- Shared rev walk.- 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:
IOException
org.eclipse.jgit.errors.MissingObjectException
org.eclipse.jgit.errors.IncorrectObjectTypeException
-
readConfig
protected org.eclipse.jgit.lib.Config readConfig(String fileName) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
- Throws:
IOException
org.eclipse.jgit.errors.ConfigInvalidException
-
readConfig
protected org.eclipse.jgit.lib.Config readConfig(String fileName, Optional<? extends org.eclipse.jgit.lib.Config> baseConfig) throws IOException, org.eclipse.jgit.errors.ConfigInvalidException
- Throws:
IOException
org.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
-
-