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());
|
||||
RevWalk rw = new RevWalk(repo)) {
|
||||
String baseRev = null;
|
||||
if (input != null && input.base != null) {
|
||||
rebaseChange.get().rebase(repo, rw, change, rsrc.getPatchSet().getId(),
|
||||
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();
|
||||
do {
|
||||
if (base.equals("")) {
|
||||
// remove existing dependency to other patch set
|
||||
baseRev = change.getDest().get();
|
||||
break;
|
||||
return change.getDest().get();
|
||||
}
|
||||
|
||||
ReviewDb db = dbProvider.get();
|
||||
@@ -109,7 +124,9 @@ public class Rebase implements RestModifyView<RevisionResource, RebaseInput>,
|
||||
}
|
||||
|
||||
Change baseChange = db.changes().get(basePatchSet.getId().getParentKey());
|
||||
if (baseChange != null) {
|
||||
if (baseChange == null) {
|
||||
return null;
|
||||
}
|
||||
if (!baseChange.getProject().equals(change.getProject())) {
|
||||
throw new ResourceConflictException("base change is in wrong project: "
|
||||
+ baseChange.getProject());
|
||||
@@ -124,20 +141,7 @@ public class Rebase implements RestModifyView<RevisionResource, RebaseInput>,
|
||||
+ " is a descendant of the current "
|
||||
+ " change - recursion not allowed");
|
||||
}
|
||||
baseRev = 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());
|
||||
return basePatchSet.getRevision().get();
|
||||
}
|
||||
|
||||
private boolean isMergedInto(RevWalk rw, PatchSet base, PatchSet tip)
|
||||
|
||||
Reference in New Issue
Block a user