Rebase: Extract a method to find base revision
Using while(false) with break is unidiomatic in Gerrit. Use early returns from a function instead. Change-Id: Ib188ca5819b0cbe1b111c1ce49b4095fade0f59f
This commit is contained in:
@@ -88,14 +88,29 @@ public class Rebase implements RestModifyView<RevisionResource, RebaseInput>,
|
|||||||
|
|
||||||
try (Repository repo = repoManager.openRepository(change.getProject());
|
try (Repository repo = repoManager.openRepository(change.getProject());
|
||||||
RevWalk rw = new RevWalk(repo)) {
|
RevWalk rw = new RevWalk(repo)) {
|
||||||
String baseRev = null;
|
rebaseChange.get().rebase(repo, rw, change, rsrc.getPatchSet().getId(),
|
||||||
if (input != null && input.base != null) {
|
rsrc.getUser(), findBaseRev(rw, rsrc, input));
|
||||||
|
} catch (InvalidChangeOperationException e) {
|
||||||
|
throw new ResourceConflictException(e.getMessage());
|
||||||
|
} catch (NoSuchChangeException e) {
|
||||||
|
throw new ResourceNotFoundException(change.getId().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.format(change.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String findBaseRev(RevWalk rw, RevisionResource rsrc,
|
||||||
|
RebaseInput input) throws AuthException, ResourceConflictException,
|
||||||
|
OrmException, IOException {
|
||||||
|
if (input == null || input.base == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Change change = rsrc.getChange();
|
||||||
String base = input.base.trim();
|
String base = input.base.trim();
|
||||||
do {
|
|
||||||
if (base.equals("")) {
|
if (base.equals("")) {
|
||||||
// remove existing dependency to other patch set
|
// remove existing dependency to other patch set
|
||||||
baseRev = change.getDest().get();
|
return change.getDest().get();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReviewDb db = dbProvider.get();
|
ReviewDb db = dbProvider.get();
|
||||||
@@ -109,7 +124,9 @@ public class Rebase implements RestModifyView<RevisionResource, RebaseInput>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Change baseChange = db.changes().get(basePatchSet.getId().getParentKey());
|
Change baseChange = db.changes().get(basePatchSet.getId().getParentKey());
|
||||||
if (baseChange != null) {
|
if (baseChange == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (!baseChange.getProject().equals(change.getProject())) {
|
if (!baseChange.getProject().equals(change.getProject())) {
|
||||||
throw new ResourceConflictException("base change is in wrong project: "
|
throw new ResourceConflictException("base change is in wrong project: "
|
||||||
+ baseChange.getProject());
|
+ baseChange.getProject());
|
||||||
@@ -124,20 +141,7 @@ public class Rebase implements RestModifyView<RevisionResource, RebaseInput>,
|
|||||||
+ " is a descendant of the current "
|
+ " is a descendant of the current "
|
||||||
+ " change - recursion not allowed");
|
+ " change - recursion not allowed");
|
||||||
}
|
}
|
||||||
baseRev = basePatchSet.getRevision().get();
|
return basePatchSet.getRevision().get();
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (false); // just wanted to use the break statement
|
|
||||||
}
|
|
||||||
rebaseChange.get().rebase(repo, rw, change, rsrc.getPatchSet().getId(),
|
|
||||||
rsrc.getUser(), baseRev);
|
|
||||||
} catch (InvalidChangeOperationException e) {
|
|
||||||
throw new ResourceConflictException(e.getMessage());
|
|
||||||
} catch (NoSuchChangeException e) {
|
|
||||||
throw new ResourceNotFoundException(change.getId().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return json.format(change.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMergedInto(RevWalk rw, PatchSet base, PatchSet tip)
|
private boolean isMergedInto(RevWalk rw, PatchSet base, PatchSet tip)
|
||||||
|
|||||||
Reference in New Issue
Block a user