Source:
<code>public RebaseResult call() throws NoHeadException, RefNotFoundException, JGitInternalException, GitAPIException { checkCallable(); checkParameters(); try { switch (operation) { case ABORT: try { return abort(); } catch (IOException ioe) { throw new JGitInternalException(ioe.getMessage(), ioe); } case SKIP: case CONTINUE: String upstreamCommitName = readFile(rebaseDir, "onto"); this.upstreamCommit = walk.parseCommit(repo .resolve(upstreamCommitName)); break; case BEGIN: RebaseResult res = initFilesAndRewind(); if (res != null) return res; } if (this.operation == Operation.CONTINUE) throw new UnsupportedOperationException( "--continue Not yet implemented"); if (this.operation == Operation.SKIP) throw new UnsupportedOperationException( "--skip Not yet implemented"); RevCommit newHead = null; String nextPatchCommit = getNextCommit(false); while (nextPatchCommit != null) { RevCommit commitToPick = walk.parseCommit(repo .resolve(nextPatchCommit)); monitor.beginTask("Applying " + commitToPick.getShortMessage(), ProgressMonitor.UNKNOWN); <START> newHead = new Git(repo).cherryPick().include(commitToPick) <END> .call(); monitor.endTask(); if (newHead == null) return new RebaseResult(Status.STOPPED); nextPatchCommit = getNextCommit(true); } RebaseResult result = new RebaseResult(Status.OK); if (newHead != null) { String headName = readFile(rebaseDir, "head-name"); RefUpdate rup = repo.updateRef(headName); rup.setNewObjectId(newHead); rup.forceUpdate(); rup = repo.updateRef(Constants.HEAD); rup.link(headName); deleteRecursive(rebaseDir); } return result; } catch (IOException ioe) { throw new JGitInternalException(ioe.getMessage(), ioe); } }</code><technical_language>add a TODO for here, want avoid cherryPick() if parent of commitToPick is current HEAD. Instead fast-forward commitToPick, branch modified. C Git this avoid unnecessary object rewriting, is useful Gerrit Code Review upstream review system accidentally git rebase -i HEAD~toofarback. long of commits modified, SHA-1 Gerrit "rebased"</technical_language>

Target:
public RebaseResult call() throws NoHeadException, RefNotFoundException, JGitInternalException, GitAPIException { checkCallable(); checkParameters(); try { switch (operation) { case ABORT: try { return abort(); } catch (IOException ioe) { throw new JGitInternalException(ioe.getMessage(), ioe); } case SKIP: case CONTINUE: String upstreamCommitName = readFile(rebaseDir, "onto"); this.upstreamCommit = walk.parseCommit(repo .resolve(upstreamCommitName)); break; case BEGIN: RebaseResult res = initFilesAndRewind(); if (res != null) return res; } if (this.operation == Operation.CONTINUE) throw new UnsupportedOperationException( "--continue Not yet implemented"); if (this.operation == Operation.SKIP) throw new UnsupportedOperationException( "--skip Not yet implemented"); RevCommit newHead = null; List<Step> steps = loadSteps(); ObjectReader or = repo.newObjectReader(); int stepsToPop = 0; for (Step step : steps) { if (step.action != Action.PICK) continue; Collection<ObjectId> ids = or.resolve(step.commit); if (ids.size() != 1) throw new JGitInternalException( "Could not resolve uniquely the abbreviated object ID"); RevCommit commitToPick = walk .parseCommit(ids.iterator().next()); monitor.beginTask("Applying " + commitToPick.getShortMessage(), ProgressMonitor.UNKNOWN); newHead = new Git(repo).cherryPick().include(commitToPick) .call(); monitor.endTask(); if (newHead == null) { popSteps(stepsToPop); return new RebaseResult(Status.STOPPED); } stepsToPop++; } RebaseResult result = new RebaseResult(Status.OK); if (newHead != null) { String headName = readFile(rebaseDir, "head-name"); RefUpdate rup = repo.updateRef(headName); rup.setNewObjectId(newHead); rup.forceUpdate(); rup = repo.updateRef(Constants.HEAD); rup.link(headName); deleteRecursive(rebaseDir); } return result; } catch (IOException ioe) { throw new JGitInternalException(ioe.getMessage(), ioe); } }