Class RefUpdateContext
- All Implemented Interfaces:
AutoCloseable
BatchRefUpdate#execute
method.
To pass the additional information RefUpdateContext
, wraps a code into an open
RefUpdateContext, e.g.:
try(RefUpdateContext ctx = RefUpdateContext.open(RefUpdateType.CHANGE_MODIFICATION)) {
...
// some code which modifies a ref using BatchRefUpdate.execute method
}
When the BatchRefUpdate#execute
method is executed, it can get all opened contexts and
use it for an additional actions, e.g. it can put it in the reflog.
The information provided by this class is used internally in google.
The InMemoryRepositoryManager file makes some validation to ensure that RefUpdateContext is used correctly within the code (see thee validateRefUpdateContext method).
The class includes only operations from open-source gerrit and can be extended (see
TestActionRefUpdateContext
for example how to extend it).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
List of possible ref-update types. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCustomData
(Object data) Add custom data.<T> void
clearCustomData
(Class<T> clazz) Remove all custom data that has a type that is assignable from the given class.void
close()
Closes the current context.protected static final Deque
<RefUpdateContext> <T> com.google.common.collect.ImmutableList
<T> getCustomData
(Class<T> clazz) Get all custom data that has a type that is assignable from the given class.Returns the justification for the operation.static com.google.common.collect.ImmutableList
<RefUpdateContext> Returns the list of opened contexts; the first element is the outermost context.Returns the type ofRefUpdateContext
.static boolean
Checks if there is an open context of the given type.static RefUpdateContext
open
(RefUpdateContext.RefUpdateType updateType) Opens a context of a give type.protected static <T extends RefUpdateContext>
Topen
(T ctx) Opens a provided context.static RefUpdateContext
openDirectPush
(Optional<String> justification) Opens a direct push context with an optional justification.
-
Constructor Details
-
RefUpdateContext
-
-
Method Details
-
open
Opens a provided context. -
open
Opens a context of a give type. -
openDirectPush
Opens a direct push context with an optional justification. -
getOpenedContexts
Returns the list of opened contexts; the first element is the outermost context. -
hasOpen
Checks if there is an open context of the given type. -
getCurrent
-
addCustomData
Add custom data.Custom data is always stored on the top-level context, but can be added through any context.
-
getCustomData
Get all custom data that has a type that is assignable from the given class.Custom data is always stored on the top-level context, but can be retrieved through any context.
-
clearCustomData
Remove all custom data that has a type that is assignable from the given class.Custom data is only stored on the top-level context, but clearing custom data can be done through any context.
-
getUpdateType
Returns the type ofRefUpdateContext
.For descendants, always return
RefUpdateContext.RefUpdateType.OTHER
(except known descendants defined as nested classes). -
getJustification
Returns the justification for the operation. -
close
public void close()Closes the current context.- Specified by:
close
in interfaceAutoCloseable
-