Class PushCertificateStore
- All Implemented Interfaces:
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.
- Since:
- 4.1
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) RevCommit
private final Repository
private final List<PushCertificateStore.PendingCert>
(package private) ObjectReader
(package private) static final String
Ref name storing push certificates. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new store backed by the given repository. -
Method Summary
Modifier and TypeMethodDescriptionprivate static String
buildMessage
(PushCertificate cert) void
clear()
Clear pending certificates added withput(PushCertificate, PersonIdent)
.void
close()
private static boolean
Get latest push certificate associated with a ref.Iterate over all push certificates affecting a ref.(package private) void
load()
private DirCache
private TreeWalk
newTreeWalk
(String refName) (package private) static String
void
put
(PushCertificate cert, PersonIdent ident) Put a certificate to be saved to the store.void
put
(PushCertificate cert, PersonIdent ident, Collection<ReceiveCommand> matching) Put a certificate to be saved to the store, matching a set of commands.(package private) static PushCertificate
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
(List<PushCertificateStore.PendingCert> pending) private RefUpdate.Result
private ObjectId
write()
-
Field Details
-
REF_NAME
Ref name storing push certificates.- See Also:
-
db
-
pending
-
reader
ObjectReader reader -
commit
RevCommit commit
-
-
Constructor Details
-
PushCertificateStore
Create a new store backed by the given repository.- Parameters:
db
- the repository.
-
-
Method Details
-
close
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.- Specified by:
close
in interfaceAutoCloseable
-
get
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 toget
; to reread the, callclose()
first.- Parameters:
refName
- the ref name to get the certificate for.- Returns:
- last certificate affecting the ref, or null if no cert was recorded for the last update to this ref.
- Throws:
IOException
- if a problem occurred reading the repository.
-
getAll
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 ifsave
orclose
is called on the enclosing store during iteration.- Parameters:
refName
- the ref name to get certificates for.- Returns:
- iterable over certificates; must be fully iterated in order to close resources.
-
load
- Throws:
IOException
-
read
- Throws:
IOException
-
put
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)
andgetAll(String)
until after callingsave()
.- Parameters:
cert
- certificate to store.ident
- identity for the commit that stores this certificate. Pending certificates are sorted by identity timestamp duringsave()
.
-
put
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)
andgetAll(String)
until after callingsave()
.- Parameters:
cert
- certificate to store.ident
- identity for the commit that stores this certificate. Pending certificates are sorted by identity timestamp duringsave()
.matching
- only store certs for the refs listed in this list whose values match the commands in the cert.
-
save
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:
- the result of attempting to update the ref.
- Throws:
IOException
- if there was an error reading from or writing to the repository.
-
save
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/orclear()
.- Parameters:
batch
- update to save to.- Returns:
- whether a command was added to the batch.
- Throws:
IOException
- if there was an error reading from or writing to the repository.
-
clear
public void clear()Clear pending certificates added withput(PushCertificate, PersonIdent)
. -
write
- Throws:
IOException
-
sortPending
-
newDirCache
- Throws:
IOException
-
saveCert
private ObjectId saveCert(ObjectInserter inserter, DirCache dc, PushCertificateStore.PendingCert pc, ObjectId curr) throws IOException - Throws:
IOException
-
commandsEqual
-
updateRef
- Throws:
IOException
-
newTreeWalk
- Throws:
IOException
-
pathName
-
buildMessage
-