use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.
the class MessageIdGenerator method fromChangeUpdateAndReason.
public MessageId fromChangeUpdateAndReason(RepoView repoView, PatchSet.Id patchsetId, @Nullable String reason) {
String suffix = (reason != null) ? ("-" + reason) : "";
String metaRef = patchsetId.changeId().toRefPrefix() + "meta";
Optional<ObjectId> metaSha1;
try {
metaSha1 = repoView.getRef(metaRef);
} catch (IOException ex) {
throw new StorageException("unable to extract info for Message-Id", ex);
}
return metaSha1.map(optional -> new AutoValue_MessageIdGenerator_MessageId(optional.getName() + suffix)).orElseThrow(() -> new IllegalStateException(metaRef + " doesn't exist"));
}
use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.
the class CreateChange method getParentCommit.
@Nullable
private ObjectId getParentCommit(Repository repo, RevWalk revWalk, String inputBranch, @Nullable Boolean newBranch, @Nullable PatchSet basePatchSet, @Nullable String baseCommit, @Nullable MergeInput mergeInput) throws BadRequestException, IOException, UnprocessableEntityException, ResourceConflictException {
if (basePatchSet != null) {
return basePatchSet.commitId();
}
Ref destRef = repo.getRefDatabase().exactRef(inputBranch);
ObjectId parentCommit;
if (baseCommit != null) {
try {
parentCommit = ObjectId.fromString(baseCommit);
} catch (InvalidObjectIdException e) {
throw new UnprocessableEntityException(String.format("Base %s doesn't represent a valid SHA-1", baseCommit), e);
}
RevCommit parentRevCommit;
try {
parentRevCommit = revWalk.parseCommit(parentCommit);
} catch (MissingObjectException e) {
throw new UnprocessableEntityException(String.format("Base %s doesn't exist", baseCommit), e);
}
if (destRef == null) {
throw new BadRequestException("Destination branch does not exist");
}
RevCommit destRefRevCommit = revWalk.parseCommit(destRef.getObjectId());
if (!revWalk.isMergedInto(parentRevCommit, destRefRevCommit)) {
throw new BadRequestException(String.format("Commit %s doesn't exist on ref %s", baseCommit, inputBranch));
}
} else {
if (destRef != null) {
if (Boolean.TRUE.equals(newBranch)) {
throw new ResourceConflictException(String.format("Branch %s already exists.", inputBranch));
}
parentCommit = destRef.getObjectId();
} else {
if (Boolean.TRUE.equals(newBranch)) {
if (mergeInput != null) {
throw new BadRequestException("Cannot create merge: destination branch does not exist");
}
parentCommit = null;
} else {
throw new BadRequestException("Destination branch does not exist");
}
}
}
return parentCommit;
}
use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.
the class PutDisplayName method apply.
@Override
public Response<String> apply(AccountResource rsrc, @Nullable DisplayNameInput input) throws AuthException, ResourceNotFoundException, IOException, PermissionBackendException, ConfigInvalidException {
IdentifiedUser user = rsrc.getUser();
if (!self.get().hasSameAccountId(user)) {
permissionBackend.currentUser().check(GlobalPermission.MODIFY_ACCOUNT);
}
if (input == null) {
input = new DisplayNameInput();
}
String newDisplayName = input.displayName;
AccountState accountState = accountsUpdateProvider.get().update("Set Display Name via API", user.getAccountId(), u -> u.setDisplayName(newDisplayName)).orElseThrow(() -> new ResourceNotFoundException("account not found"));
return Strings.isNullOrEmpty(accountState.account().displayName()) ? Response.none() : Response.ok(accountState.account().displayName());
}
use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.
the class CherryPickChange method getDestChangeWithVerification.
/**
* Returns the change from the destination branch, if it exists and is valid for the cherry-pick.
*
* @param destChangeId the Change-ID of the change in the destination branch.
* @param destBranch the branch to search by the Change-ID.
* @param verifyIsMissing if {@code true}, verifies that the change should be missing in the
* destination branch.
* @return the verified change or {@code null} if the change was not found.
* @throws InvalidChangeOperationException if the change was found but failed validation
*/
@Nullable
private ChangeData getDestChangeWithVerification(String destChangeId, BranchNameKey destBranch, boolean verifyIsMissing) throws InvalidChangeOperationException {
List<ChangeData> destChanges = queryProvider.get().setLimit(2).byBranchKey(destBranch, Change.key(destChangeId));
if (destChanges.size() > 1) {
throw new InvalidChangeOperationException("Several changes with key " + destChangeId + " reside on the same branch. " + "Cannot create a new patch set.");
}
if (destChanges.size() == 1 && verifyIsMissing) {
throw new InvalidChangeOperationException(String.format("Expected that cherry-pick with Change-Id %s to branch %s " + "in project %s creates a new change, but found existing change %d", destChangeId, destBranch.branch(), destBranch.project().get(), destChanges.get(0).getId().get()));
}
ChangeData destChange = destChanges.size() == 1 ? destChanges.get(0) : null;
if (destChange != null && destChange.change().isClosed()) {
throw new InvalidChangeOperationException(String.format("Cherry-pick with Change-Id %s could not update the existing change %d " + "in destination branch %s of project %s, because the change was closed (%s)", destChangeId, destChange.getId().get(), destBranch.branch(), destBranch.project(), destChange.change().getStatus().name()));
}
return destChange;
}
use of com.google.gerrit.common.Nullable in project gerrit by GerritCodeReview.
the class GroupsOnInit method getPathToAllUsersRepository.
@Nullable
private File getPathToAllUsersRepository() {
Path basePath = site.resolve(flags.cfg.getString("gerrit", null, "basePath"));
checkArgument(basePath != null, "gerrit.basePath must be configured");
return RepositoryCache.FileKey.resolve(basePath.resolve(allUsers.get()).toFile(), FS.DETECTED);
}
Aggregations