use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class SubmoduleCommits method amendGitlinksCommit.
/**
* Amend an existing commit with gitlink updates
*/
CodeReviewCommit amendGitlinksCommit(BranchNameKey subscriber, CodeReviewCommit currentCommit, Collection<SubmoduleSubscription> subscriptions) throws IOException, SubmoduleConflictException {
OpenRepo or;
try {
or = orm.getRepo(subscriber.project());
} catch (NoSuchProjectException | IOException e) {
throw new StorageException("Cannot access superproject", e);
}
StringBuilder msgbuf = new StringBuilder();
DirCache dc = readTree(or.rw, currentCommit);
DirCacheEditor ed = dc.editor();
for (SubmoduleSubscription s : sortByPath(subscriptions)) {
updateSubmodule(dc, ed, msgbuf, s);
}
ed.finish();
ObjectId newTreeId = dc.writeTree(or.ins);
// Gitlinks are already updated, just return the commit
if (newTreeId.equals(currentCommit.getTree())) {
return currentCommit;
}
or.rw.parseBody(currentCommit);
CommitBuilder commit = new CommitBuilder();
commit.setTreeId(newTreeId);
commit.setParentIds(currentCommit.getParents());
if (verboseSuperProject != VerboseSuperprojectUpdate.FALSE) {
// TODO(czhen): handle cherrypick footer
commit.setMessage(currentCommit.getFullMessage() + "\n\n* submodules:\n" + msgbuf.toString());
} else {
commit.setMessage(currentCommit.getFullMessage());
}
commit.setAuthor(currentCommit.getAuthorIdent());
commit.setCommitter(myIdent);
ObjectId id = or.ins.insert(commit);
CodeReviewCommit newCommit = or.getCodeReviewRevWalk().parseCommit(id);
newCommit.copyFrom(currentCommit);
return newCommit;
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class SubmoduleOp method updateSuperProjects.
public void updateSuperProjects(boolean dryrun) throws RestApiException {
ImmutableSet<Project.NameKey> projects = updateOrderCalculator.getProjectsInOrder();
if (projects == null) {
return;
}
if (dryrun) {
// On dryrun, the refs hasn't been updated.
// force the new tips on submoduleCommits
forceRefTips(updatedBranches, submoduleCommits);
}
LinkedHashSet<Project.NameKey> superProjects = new LinkedHashSet<>();
try {
GitlinkOp.Factory gitlinkOpFactory = new GitlinkOp.Factory(submoduleCommits, subscriptionGraph);
for (Project.NameKey project : projects) {
// only need superprojects
if (subscriptionGraph.isAffectedSuperProject(project)) {
superProjects.add(project);
// get a new BatchUpdate for the super project
OpenRepo or = orm.getRepo(project);
for (BranchNameKey branch : subscriptionGraph.getAffectedSuperBranches(project)) {
or.getUpdate().addRepoOnlyOp(gitlinkOpFactory.create(branch));
}
}
}
BatchUpdate.execute(orm.batchUpdates(superProjects), ImmutableList.of(), dryrun);
} catch (UpdateException | IOException | NoSuchProjectException e) {
throw new StorageException("Cannot update gitlinks", e);
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class SubmoduleOp method forceRefTips.
private void forceRefTips(Map<BranchNameKey, ReceiveCommand> updatedBranches, SubmoduleCommits submoduleCommits) {
// This is dryrun, all commands succeeded (no need to filter success).
for (Map.Entry<BranchNameKey, ReceiveCommand> updateBranch : updatedBranches.entrySet()) {
try {
ReceiveCommand command = updateBranch.getValue();
if (command.getType() == ReceiveCommand.Type.DELETE) {
continue;
}
BranchNameKey branchNameKey = updateBranch.getKey();
OpenRepo openRepo = orm.getRepo(branchNameKey.project());
CodeReviewCommit fakeTip = openRepo.rw.parseCommit(command.getNewId());
submoduleCommits.addBranchTip(branchNameKey, fakeTip);
} catch (NoSuchProjectException | IOException e) {
throw new StorageException("Cannot find branch tip target in dryrun", e);
}
}
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class MergeUtil method canCherryPick.
public boolean canCherryPick(MergeSorter mergeSorter, Repository repo, CodeReviewCommit mergeTip, CodeReviewRevWalk rw, CodeReviewCommit toMerge) {
if (mergeTip == null) {
//
return true;
}
if (toMerge.getParentCount() == 0) {
//
return false;
}
if (toMerge.getParentCount() == 1) {
//
try (ObjectInserter ins = new InMemoryInserter(repo)) {
ThreeWayMerger m = newThreeWayMerger(ins, repo.getConfig());
m.setBase(toMerge.getParent(0));
return m.merge(mergeTip, toMerge);
} catch (IOException e) {
throw new StorageException(String.format("Cannot merge commit %s with mergetip %s", toMerge.name(), mergeTip.name()), e);
}
}
//
return canFastForward(mergeSorter, mergeTip, rw, toMerge) || canMerge(mergeSorter, repo, mergeTip, toMerge);
}
use of com.google.gerrit.exceptions.StorageException in project gerrit by GerritCodeReview.
the class MergeUtil method markCleanMerges.
public void markCleanMerges(RevWalk rw, RevFlag canMergeFlag, CodeReviewCommit mergeTip, Set<RevCommit> alreadyAccepted) {
if (mergeTip == null) {
//
return;
}
try {
rw.resetRetain(canMergeFlag);
rw.sort(RevSort.TOPO);
rw.sort(RevSort.REVERSE, true);
rw.markStart(mergeTip);
for (RevCommit c : alreadyAccepted) {
// If branch was not created by this submit.
if (!Objects.equals(c, mergeTip)) {
rw.markUninteresting(c);
}
}
CodeReviewCommit c;
while ((c = (CodeReviewCommit) rw.next()) != null) {
if (c.getPatchsetId() != null && c.getStatusCode() == null) {
c.setStatusCode(CommitMergeStatus.CLEAN_MERGE);
}
}
} catch (IOException e) {
throw new StorageException("Cannot mark clean merges", e);
}
}
Aggregations