public class PushCertificateStore
extends java.lang.Object
implements java.lang.AutoCloseable
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.
Modifier and Type | Class and Description |
---|---|
private static class |
PushCertificateStore.PendingCert |
Modifier and Type | Field and Description |
---|---|
(package private) RevCommit |
commit |
private Repository |
db |
private java.util.List<PushCertificateStore.PendingCert> |
pending |
(package private) ObjectReader |
reader |
(package private) static java.lang.String |
REF_NAME
Ref name storing push certificates.
|
Constructor and Description |
---|
PushCertificateStore(Repository db)
Create a new store backed by the given repository.
|
Modifier and Type | Method and Description |
---|---|
private static java.lang.String |
buildMessage(PushCertificate cert) |
void |
clear()
Clear pending certificates added with
put(PushCertificate,
PersonIdent) . |
void |
close() |
private static boolean |
commandsEqual(ReceiveCommand c1,
ReceiveCommand c2) |
PushCertificate |
get(java.lang.String refName)
Get latest push certificate associated with a ref.
|
java.lang.Iterable<PushCertificate> |
getAll(java.lang.String refName)
Iterate over all push certificates affecting a ref.
|
(package private) void |
load() |
private DirCache |
newDirCache() |
private TreeWalk |
newTreeWalk(java.lang.String refName) |
(package private) static java.lang.String |
pathName(java.lang.String refName) |
void |
put(PushCertificate cert,
PersonIdent ident)
Put a certificate to be saved to the store.
|
void |
put(PushCertificate cert,
PersonIdent ident,
java.util.Collection<ReceiveCommand> matching)
Put a certificate to be saved to the store, matching a set of commands.
|
(package private) static PushCertificate |
read(TreeWalk tw) |
RefUpdate.Result |
save()
Save pending certificates to the store.
|
boolean |
save(BatchRefUpdate batch)
Save pending certificates to the store in an existing batch ref update.
|
private ObjectId |
saveCert(ObjectInserter inserter,
DirCache dc,
PushCertificateStore.PendingCert pc,
ObjectId curr) |
private static void |
sortPending(java.util.List<PushCertificateStore.PendingCert> pending) |
private RefUpdate.Result |
updateRef(ObjectId newId) |
private ObjectId |
write() |
static final java.lang.String REF_NAME
private final Repository db
private final java.util.List<PushCertificateStore.PendingCert> pending
ObjectReader reader
RevCommit commit
public PushCertificateStore(Repository db)
db
- the repository.public void close()
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.
close
in interface java.lang.AutoCloseable
public PushCertificate get(java.lang.String refName) throws java.io.IOException
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.
refName
- the ref name to get the certificate for.java.io.IOException
- if a problem occurred reading the repository.public java.lang.Iterable<PushCertificate> getAll(java.lang.String refName)
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.
refName
- the ref name to get certificates for.void load() throws java.io.IOException
java.io.IOException
static PushCertificate read(TreeWalk tw) throws java.io.IOException
java.io.IOException
public void put(PushCertificate cert, PersonIdent ident)
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()
.
cert
- certificate to store.ident
- identity for the commit that stores this certificate. Pending
certificates are sorted by identity timestamp during
save()
.public void put(PushCertificate cert, PersonIdent ident, java.util.Collection<ReceiveCommand> matching)
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()
.
cert
- certificate to store.ident
- identity for the commit that stores this certificate. Pending
certificates are sorted by identity timestamp during
save()
.matching
- only store certs for the refs listed in this list whose values
match the commands in the cert.public RefUpdate.Result save() throws java.io.IOException
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.
java.io.IOException
- if there was an error reading from or writing to the
repository.public boolean save(BatchRefUpdate batch) throws java.io.IOException
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()
.
batch
- update to save to.java.io.IOException
- if there was an error reading from or writing to the
repository.public void clear()
put(PushCertificate,
PersonIdent)
.private ObjectId write() throws java.io.IOException
java.io.IOException
private static void sortPending(java.util.List<PushCertificateStore.PendingCert> pending)
private DirCache newDirCache() throws java.io.IOException
java.io.IOException
private ObjectId saveCert(ObjectInserter inserter, DirCache dc, PushCertificateStore.PendingCert pc, ObjectId curr) throws java.io.IOException
java.io.IOException
private static boolean commandsEqual(ReceiveCommand c1, ReceiveCommand c2)
private RefUpdate.Result updateRef(ObjectId newId) throws java.io.IOException
java.io.IOException
private TreeWalk newTreeWalk(java.lang.String refName) throws java.io.IOException
java.io.IOException
static java.lang.String pathName(java.lang.String refName)
private static java.lang.String buildMessage(PushCertificate cert)