Rebase: Minor cleanup

Whitespace fixes. Remove unnecessary finals. Consistent comment
formatting.

Change-Id: I284224cd1a7eb4497e46a2b3506f84a386150e59
This commit is contained in:
Dave Borowitz
2015-05-20 18:52:14 -07:00
parent 7c8c7b7f86
commit 4ab21befbc

View File

@@ -49,8 +49,7 @@ import java.io.IOException;
public class Rebase implements RestModifyView<RevisionResource, RebaseInput>, public class Rebase implements RestModifyView<RevisionResource, RebaseInput>,
UiAction<RevisionResource> { UiAction<RevisionResource> {
private static final Logger log = private static final Logger log = LoggerFactory.getLogger(Rebase.class);
LoggerFactory.getLogger(Rebase.class);
private final GitRepositoryManager repoManager; private final GitRepositoryManager repoManager;
private final Provider<RebaseChange> rebaseChange; private final Provider<RebaseChange> rebaseChange;
@@ -128,18 +127,18 @@ public class Rebase implements RestModifyView<RevisionResource, RebaseInput>,
return 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(
+ baseChange.getProject()); "base change is in wrong project: " + baseChange.getProject());
} else if (!baseChange.getDest().equals(change.getDest())) { } else if (!baseChange.getDest().equals(change.getDest())) {
throw new ResourceConflictException("base change is targetting wrong branch: " throw new ResourceConflictException(
+ baseChange.getDest()); "base change is targeting wrong branch: " + baseChange.getDest());
} else if (baseChange.getStatus() == Status.ABANDONED) { } else if (baseChange.getStatus() == Status.ABANDONED) {
throw new ResourceConflictException("base change is abandoned: " throw new ResourceConflictException(
+ baseChange.getKey()); "base change is abandoned: " + baseChange.getKey());
} else if (isMergedInto(rw, rsrc.getPatchSet(), basePatchSet)) { } else if (isMergedInto(rw, rsrc.getPatchSet(), basePatchSet)) {
throw new ResourceConflictException("base change " + baseChange.getKey() throw new ResourceConflictException(
+ " is a descendant of the current " "base change " + baseChange.getKey()
+ " change - recursion not allowed"); + " is a descendant of the current change - recursion not allowed");
} }
return basePatchSet.getRevision().get(); return basePatchSet.getRevision().get();
} }
@@ -151,33 +150,35 @@ public class Rebase implements RestModifyView<RevisionResource, RebaseInput>,
return rw.isMergedInto(rw.parseCommit(baseId), rw.parseCommit(tipId)); return rw.isMergedInto(rw.parseCommit(baseId), rw.parseCommit(tipId));
} }
private PatchSet parseBase(final String base) throws OrmException { private PatchSet parseBase(String base) throws OrmException {
ReviewDb db = dbProvider.get(); ReviewDb db = dbProvider.get();
PatchSet.Id basePatchSetId = PatchSet.Id.fromRef(base); PatchSet.Id basePatchSetId = PatchSet.Id.fromRef(base);
if (basePatchSetId != null) { if (basePatchSetId != null) {
// try parsing the base as a ref string // Try parsing the base as a ref string.
return db.patchSets().get(basePatchSetId); return db.patchSets().get(basePatchSetId);
} }
// try parsing base as a change number (assume current patch set) // Try parsing base as a change number (assume current patch set).
PatchSet basePatchSet = null; PatchSet basePatchSet = null;
try { try {
Change.Id baseChangeId = Change.Id.parse(base); Change.Id baseChangeId = Change.Id.parse(base);
if (baseChangeId != null) { if (baseChangeId != null) {
for (PatchSet ps : db.patchSets().byChange(baseChangeId)) { for (PatchSet ps : db.patchSets().byChange(baseChangeId)) {
if (basePatchSet == null || basePatchSet.getId().get() < ps.getId().get()){ if (basePatchSet == null
|| basePatchSet.getId().get() < ps.getId().get()) {
basePatchSet = ps; basePatchSet = ps;
} }
} }
} }
} catch (NumberFormatException e) { // probably a SHA1 } catch (NumberFormatException e) { // Probably a SHA-1.
} }
// try parsing as SHA1 // Try parsing as SHA-1.
if (basePatchSet == null) { if (basePatchSet == null) {
for (PatchSet ps : db.patchSets().byRevision(new RevId(base))) { for (PatchSet ps : db.patchSets().byRevision(new RevId(base))) {
if (basePatchSet == null || basePatchSet.getId().get() < ps.getId().get()) { if (basePatchSet == null
|| basePatchSet.getId().get() < ps.getId().get()) {
basePatchSet = ps; basePatchSet = ps;
} }
} }
@@ -186,9 +187,9 @@ public class Rebase implements RestModifyView<RevisionResource, RebaseInput>,
return basePatchSet; return basePatchSet;
} }
private boolean hasOneParent(final PatchSet.Id patchSetId) { private boolean hasOneParent(PatchSet.Id patchSetId) {
try { try {
// prevent rebase of exotic changes (merge commit, no ancestor). // Prevent rebase of exotic changes (merge commit, no ancestor).
return (dbProvider.get().patchSetAncestors() return (dbProvider.get().patchSetAncestors()
.ancestorsOf(patchSetId).toList().size() == 1); .ancestorsOf(patchSetId).toList().size() == 1);
} catch (OrmException e) { } catch (OrmException e) {