Merge branch 'stable-2.11'

* stable-2.11:
  Update cookbook plugin to latest revision on stable-2.11 branch
  Throw NotImplementedException in {Publish|Rebase}ChangeEdit
  REST API: translate NotImplementedException to "501 not implemented"
  Rebase should use Rebase.Input, not PublishDraftPatchSet.Input
  Side-By-Side: Adjust line number when using 'm' to edit commit message

Change-Id: I66bf79835b30bac20fcd33d6ec117848d0e88423
This commit is contained in:
David Pursehouse 2015-03-02 18:44:33 +09:00
commit d3de678eb1
4 changed files with 62 additions and 12 deletions

View File

@ -894,12 +894,59 @@ public class SideBySide extends Screen {
};
}
private int adjustCommitMessageLine(int line) {
/* When commit messages are shown in the side-by-side screen they include
a header block that looks like this:
1 Parent: deadbeef (Parent commit title)
2 Author: A. U. Thor <author@example.com>
3 AuthorDate: 2015-02-27 19:20:52 +0900
4 Commit: A. U. Thor <author@example.com>
5 CommitDate: 2015-02-27 19:20:52 +0900
6 [blank line]
7 Commit message title
8
9 Commit message body
10 ...
11 ...
If the commit is a merge commit, both parent commits are listed in the
first two lines instead of a 'Parent' line:
1 Merge Of: deadbeef (Parent 1 commit title)
2 beefdead (Parent 2 commit title)
*/
// Offset to compensate for header lines until the blank line
// after 'CommitDate'
int offset = 6;
// Adjust for merge commits, which have two parent lines
if (diff.text_b().startsWith("Merge")) {
offset += 1;
}
// If the cursor is inside the header line, reset to the first line of the
// commit message. Otherwise if the cursor is on an actual line of the commit
// message, adjust the line number to compensate for the header lines, so the
// focus is on the correct line.
if (line <= offset) {
return 1;
} else {
return line - offset;
}
}
private Runnable modifyInEditScreen(final CodeMirror cm) {
return new Runnable() {
@Override
public void run() {
LineHandle handle = cm.extras().activeLine();
int line = cm.getLineNumber(handle) + 1;
if (Patch.COMMIT_MSG.equals(path)) {
line = adjustCommitMessageLine(line);
}
String token = Dispatcher.toEditScreen(revision, path, line);
if (!Gerrit.isSignedIn()) {
Gerrit.doSignIn(token);

View File

@ -25,6 +25,7 @@ import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static javax.servlet.http.HttpServletResponse.SC_METHOD_NOT_ALLOWED;
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
import static javax.servlet.http.HttpServletResponse.SC_NOT_IMPLEMENTED;
import static javax.servlet.http.HttpServletResponse.SC_NOT_MODIFIED;
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
import static javax.servlet.http.HttpServletResponse.SC_OK;
@ -61,6 +62,7 @@ import com.google.gerrit.extensions.restapi.DefaultInput;
import com.google.gerrit.extensions.restapi.ETagView;
import com.google.gerrit.extensions.restapi.IdString;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.NotImplementedException;
import com.google.gerrit.extensions.restapi.PreconditionFailedException;
import com.google.gerrit.extensions.restapi.RawInput;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
@ -375,6 +377,9 @@ public class RestApiServlet extends HttpServlet {
} catch (UnprocessableEntityException e) {
replyError(req, res, status = 422, messageOr(e, "Unprocessable Entity"),
e.caching(), e);
} catch (NotImplementedException e) {
replyError(req, res, status = SC_NOT_IMPLEMENTED,
messageOr(e, "Not Implemented"), e);
} catch (Exception e) {
status = SC_INTERNAL_SERVER_ERROR;
handleException(e, req, res);

View File

@ -20,8 +20,8 @@ import com.google.gerrit.extensions.restapi.AcceptsPost;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.ChildCollection;
import com.google.gerrit.extensions.restapi.IdString;
import com.google.gerrit.extensions.restapi.NotImplementedException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.RestModifyView;
@ -50,18 +50,17 @@ public class PublishChangeEdit implements
@Override
public DynamicMap<RestView<ChangeEditResource>> views() {
throw new IllegalStateException("not yet implemented");
throw new NotImplementedException();
}
@Override
public RestView<ChangeResource> list() {
throw new IllegalStateException("not yet implemented");
throw new NotImplementedException();
}
@Override
public ChangeEditResource parse(ChangeResource parent, IdString id)
throws ResourceNotFoundException, Exception {
throw new IllegalStateException("not yet implemented");
public ChangeEditResource parse(ChangeResource parent, IdString id) {
throw new NotImplementedException();
}
@SuppressWarnings("unchecked")

View File

@ -20,8 +20,8 @@ import com.google.gerrit.extensions.restapi.AcceptsPost;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.ChildCollection;
import com.google.gerrit.extensions.restapi.IdString;
import com.google.gerrit.extensions.restapi.NotImplementedException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.RestModifyView;
@ -53,18 +53,17 @@ public class RebaseChangeEdit implements
@Override
public DynamicMap<RestView<ChangeEditResource>> views() {
throw new IllegalStateException("not yet implemented");
throw new NotImplementedException();
}
@Override
public RestView<ChangeResource> list() {
throw new IllegalStateException("not yet implemented");
throw new NotImplementedException();
}
@Override
public ChangeEditResource parse(ChangeResource parent, IdString id)
throws ResourceNotFoundException, Exception {
throw new IllegalStateException("not yet implemented");
public ChangeEditResource parse(ChangeResource parent, IdString id) {
throw new NotImplementedException();
}
@SuppressWarnings("unchecked")