From ec0d78d0939ee8ce30bd349bd885186c13d3b645 Mon Sep 17 00:00:00 2001 From: Stefan Lay Date: Thu, 28 Nov 2013 11:18:16 +0100 Subject: [PATCH] Use static factory methods instead of overloaded constructors Change-Id: Ib10e0798dcfb9f1b611caec393926c95eff4c2a2 --- .../org/eclipse/jgit/api/RebaseCommand.java | 10 ++--- .../org/eclipse/jgit/api/RebaseResult.java | 41 +++++++++++-------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index d077cff15..3bbac4a85 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -321,7 +321,7 @@ public RebaseResult call() throws GitAPIException, NoHeadException, } return finishRebase(newHead, lastStepWasForward); } catch (CheckoutConflictException cce) { - return new RebaseResult(cce.getConflictingPaths()); + return RebaseResult.conflicts(cce.getConflictingPaths()); } catch (IOException ioe) { throw new JGitInternalException(ioe.getMessage(), ioe); } @@ -340,7 +340,7 @@ private RebaseResult processStep(RebaseTodoLine step, boolean shouldPick) RevCommit commitToPick = walk.parseCommit(ids.iterator().next()); if (shouldPick) { if (monitor.isCancelled()) - return new RebaseResult(commitToPick, Status.STOPPED); + return RebaseResult.result(Status.STOPPED, commitToPick); RebaseResult result = cherryPickCommit(commitToPick); if (result != null) return result; @@ -403,8 +403,8 @@ private RebaseResult cherryPickCommit(RevCommit commitToPick) switch (cherryPickResult.getStatus()) { case FAILED: if (operation == Operation.BEGIN) - return abort(new RebaseResult( - cherryPickResult.getFailingPaths())); + return abort(RebaseResult.failed(cherryPickResult + .getFailingPaths())); else return stop(commitToPick, Status.STOPPED); case CONFLICTING: @@ -735,7 +735,7 @@ private RebaseResult stop(RevCommit commitToPick, RebaseResult.Status status) // Remove cherry pick state file created by CherryPickCommand, it's not // needed for rebase repo.writeCherryPickHead(null); - return new RebaseResult(commitToPick, status); + return RebaseResult.result(status, commitToPick); } String toAuthorScript(PersonIdent author) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseResult.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseResult.java index aaa75d9b8..0587b4301 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseResult.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseResult.java @@ -190,28 +190,36 @@ private RebaseResult(Status status) { currentCommit = null; } - /** - * Create RebaseResult with status {@link Status#STOPPED} - * - * @param commit - * current commit - * @param status - */ - RebaseResult(RevCommit commit, RebaseResult.Status status) { + private RebaseResult(Status status, RevCommit commit) { this.status = status; currentCommit = commit; } + /** + * Create RebaseResult + * + * @param status + * @param commit + * current commit + * @return the RebaseResult + */ + static RebaseResult result(RebaseResult.Status status, + RevCommit commit) { + return new RebaseResult(status, commit); + } + /** * Create RebaseResult with status {@link Status#FAILED} * * @param failingPaths * list of paths causing this rebase to fail + * @return the RebaseResult */ - RebaseResult(Map failingPaths) { - status = Status.FAILED; - currentCommit = null; - this.failingPaths = failingPaths; + static RebaseResult failed( + Map failingPaths) { + RebaseResult result = new RebaseResult(Status.FAILED); + result.failingPaths = failingPaths; + return result; } /** @@ -219,11 +227,12 @@ private RebaseResult(Status status) { * * @param conflicts * the list of conflicting paths + * @return the RebaseResult */ - RebaseResult(List conflicts) { - status = Status.CONFLICTS; - currentCommit = null; - this.conflicts = conflicts; + static RebaseResult conflicts(List conflicts) { + RebaseResult result = new RebaseResult(Status.CONFLICTS); + result.conflicts = conflicts; + return result; } /**