Top Description Inners Fields Constructors Methods
org.eclipse.jgit.transport

public Class PushCertificateStore

extends Object
implements AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Static Imports
java.nio.charset.StandardCharsets.UTF_8, org.eclipse.jgit.lib.Constants.OBJ_BLOB, .Constants.OBJ_COMMIT, .FileMode.TYPE_FILE

Storage for recorded push certificates.

Push certificates are stored in a special ref refs/meta/push-certs. The filenames in the tree are ref names followed by the special suffix @{cert}, and the contents are the latest push cert affecting that ref. The special suffix allows storing certificates for both refs/foo and refs/foo/bar in case those both existed at some point.

Since
4.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
pack-priv RevCommit
private final Repository
private final List<PushCertificateStore.PendingCert>
pack-priv ObjectReader
pack-priv static final String
REF_NAME

Ref name storing push certificates.

Constructor Summary

AccessConstructor and Description
public
PushCertificateStore(Repository
the repository.
db
)

Create a new store backed by the given repository.

Method Summary

Modifier and TypeMethod and Description
private static String
public void
clear()

Clear pending certificates added with put(PushCertificate, PersonIdent).

public void
close()

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

private static boolean
public PushCertificate

Returns:

last certificate affecting the ref, or null if no cert was recorded for the last update to this ref.
get
(String
the ref name to get the certificate for.
refName
)

Get latest push certificate associated with a ref.

public Iterable<PushCertificate>

Returns:

iterable over certificates; must be fully iterated in order to close resources.
getAll
(String
the ref name to get certificates for.
refName
)

Iterate over all push certificates affecting a ref.

pack-priv void
load()

private DirCache
private TreeWalk
pack-priv static String
pathName(String refName)

public void
put(PushCertificate
certificate to store.
cert
,
PersonIdent
identity for the commit that stores this certificate. Pending certificates are sorted by identity timestamp during save().
ident
)

Put a certificate to be saved to the store.

public void
put(PushCertificate
certificate to store.
cert
,
PersonIdent
identity for the commit that stores this certificate. Pending certificates are sorted by identity timestamp during save().
ident
,
Collection<ReceiveCommand>
only store certs for the refs listed in this list whose values match the commands in the cert.
matching
)

Put a certificate to be saved to the store, matching a set of commands.

pack-priv static PushCertificate
public RefUpdate.Result

Returns:

the result of attempting to update the ref.
save
()

Save pending certificates to the store.

public boolean

Returns:

whether a command was added to the batch.
save
(BatchRefUpdate
update to save to.
batch
)

Save pending certificates to the store in an existing batch ref update.

private ObjectId
private static void
private RefUpdate.Result
private ObjectId
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

commitback to summary
pack-priv RevCommit commit
dbback to summary
private final Repository db
pendingback to summary
private final List<PushCertificateStore.PendingCert> pending
readerback to summary
pack-priv ObjectReader reader
REF_NAMEback to summary
pack-priv static final String REF_NAME

Ref name storing push certificates.

Constructor Detail

PushCertificateStoreback to summary
public PushCertificateStore(Repository db)

Create a new store backed by the given repository.

Parameters
db:Repository

the repository.

Method Detail

buildMessageback to summary
private static String buildMessage(PushCertificate cert)
clearback to summary
public void clear()

Clear pending certificates added with put(PushCertificate, PersonIdent).

closeback to summary
public void close()

Implements java.lang.AutoCloseable.close.

Doc from java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

Close resources opened by this store.

If get(String) was called, closes the cached object reader created by that method. Does not close the underlying repository.

Annotations
@Override
commandsEqualback to summary
private static boolean commandsEqual(ReceiveCommand c1, ReceiveCommand c2)
getback to summary
public PushCertificate get(String refName) throws IOException

Get latest push certificate associated with a ref.

Lazily opens refs/meta/push-certs and reads from the repository as necessary. The state is cached between calls to get; to reread the, call close() first.

Parameters
refName:String

the ref name to get the certificate for.

Returns:PushCertificate

last certificate affecting the ref, or null if no cert was recorded for the last update to this ref.

Exceptions
IOException:
if a problem occurred reading the repository.
getAllback to summary
public Iterable<PushCertificate> getAll(String refName)

Iterate over all push certificates affecting a ref.

Only includes push certificates actually stored in the tree; see class Javadoc for conditions where this might not include all push certs ever seen for this ref.

The returned iterable may be iterated multiple times, and push certs will be re-read from the current state of the store on each call to Iterable#iterator(). However, method calls on the returned iterator may fail if save or close is called on the enclosing store during iteration.

Parameters
refName:String

the ref name to get certificates for.

Returns:Iterable<PushCertificate>

iterable over certificates; must be fully iterated in order to close resources.

loadback to summary
pack-priv void load() throws IOException
newDirCacheback to summary
private DirCache newDirCache() throws IOException
newTreeWalkback to summary
private TreeWalk newTreeWalk(String refName) throws IOException
pathNameback to summary
pack-priv static String pathName(String refName)
putback to summary
public void put(PushCertificate cert, PersonIdent ident)

Put a certificate to be saved to the store.

Writes the contents of this certificate for each ref mentioned. It is up to the caller to ensure this certificate accurately represents the state of the ref.

Pending certificates added to this method are not returned by get(String) and getAll(String) until after calling save().

Parameters
cert:PushCertificate

certificate to store.

ident:PersonIdent

identity for the commit that stores this certificate. Pending certificates are sorted by identity timestamp during save().

putback to summary
public void put(PushCertificate cert, PersonIdent ident, Collection<ReceiveCommand> matching)

Put a certificate to be saved to the store, matching a set of commands.

Like put(PushCertificate, PersonIdent), except a value is only stored for a push certificate if there is a corresponding command in the list that exactly matches the old/new values mentioned in the push certificate.

Pending certificates added to this method are not returned by get(String) and getAll(String) until after calling save().

Parameters
cert:PushCertificate

certificate to store.

ident:PersonIdent

identity for the commit that stores this certificate. Pending certificates are sorted by identity timestamp during save().

matching:Collection<ReceiveCommand>

only store certs for the refs listed in this list whose values match the commands in the cert.

readback to summary
pack-priv static PushCertificate read(TreeWalk tw) throws IOException
saveback to summary
public RefUpdate.Result save() throws IOException

Save pending certificates to the store.

One commit is created per certificate added with put(PushCertificate, PersonIdent), in order of identity timestamps, and a single ref update is performed.

The pending list is cleared if and only the ref update fails, which allows for easy retries in case of lock failure.

Returns:RefUpdate.Result

the result of attempting to update the ref.

Exceptions
IOException:
if there was an error reading from or writing to the repository.
saveback to summary
public boolean save(BatchRefUpdate batch) throws IOException

Save pending certificates to the store in an existing batch ref update.

One commit is created per certificate added with put(PushCertificate, PersonIdent), in order of identity timestamps, all commits are flushed, and a single command is added to the batch.

The cached ref value and pending list are not cleared. If the ref update succeeds, the caller is responsible for calling close() and/or clear().

Parameters
batch:BatchRefUpdate

update to save to.

Returns:boolean

whether a command was added to the batch.

Exceptions
IOException:
if there was an error reading from or writing to the repository.
saveCertback to summary
private ObjectId saveCert(ObjectInserter inserter, DirCache dc, PushCertificateStore.PendingCert pc, ObjectId curr) throws IOException
sortPendingback to summary
private static void sortPending(List<PushCertificateStore.PendingCert> pending)
updateRefback to summary
private RefUpdate.Result updateRef(ObjectId newId) throws IOException
writeback to summary
private ObjectId write() throws IOException
org.eclipse.jgit.transport back to summary

private Class PushCertificateStore.PendingCert

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv PushCertificate
pack-priv PersonIdent
pack-priv Collection<ReceiveCommand>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

certback to summary
pack-priv PushCertificate cert
identback to summary
pack-priv PersonIdent ident
matchingback to summary
pack-priv Collection<ReceiveCommand> matching

Constructor Detail

PendingCertback to summary
pack-priv PendingCert(PushCertificate cert, PersonIdent ident, Collection<ReceiveCommand> matching)