ChangeEdits.Create#apply: Remove dead code

The only entry point for ChangeEdits.Create#apply is from RestApiServlet
via ChangeEdits#create. The latter method is only called for a PUT on
/changes/{change-id}/edit/path_to_file and an absent change edit. If the
path_to_file isn't specified, the request will be a PUT on
/changes/{change-id}/edit/. As no handler is specified for that request
(no matter whether a change edit is present or not), a
ResourceNotFoundException is thrown. Hence, we will never end up in
ChangeEdits#create.

Change-Id: If754fdb83f02dc69914fc3bc1a88bf4d0200862b
This commit is contained in:
Alice Kober-Sotzek
2017-01-27 11:42:29 +01:00
parent 54a97dbfa4
commit 22e202403b

View File

@@ -15,7 +15,6 @@
package com.google.gerrit.server.change;
import com.google.common.base.Strings;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.common.DiffWebLinkInfo;
import com.google.gerrit.extensions.common.EditInfo;
import com.google.gerrit.extensions.registration.DynamicMap;
@@ -151,18 +150,12 @@ public class ChangeEdits implements
Create create(String path);
}
private final ChangeEditModifier editModifier;
private final GitRepositoryManager repositoryManager;
private final Put putEdit;
private final String path;
@Inject
Create(ChangeEditModifier editModifier,
GitRepositoryManager repositoryManager,
Put putEdit,
@Assisted @Nullable String path) {
this.editModifier = editModifier;
this.repositoryManager = repositoryManager;
Create(Put putEdit,
@Assisted String path) {
this.putEdit = putEdit;
this.path = path;
}
@@ -171,29 +164,9 @@ public class ChangeEdits implements
public Response<?> apply(ChangeResource resource, Put.Input input)
throws AuthException, ResourceConflictException, IOException,
OrmException {
if (Strings.isNullOrEmpty(path)) {
// TODO(aliceks): Consider the following:
// Generating an edit with a put (instead of a post) isn't mentioned in
// the documentation of the REST API. We should consider whether we want
// to keep this hidden 'feature', make it public via the documentation,
// or remove it.
createEdit(resource);
} else {
putEdit.apply(resource.getControl(), path, input.content);
}
putEdit.apply(resource.getControl(), path, input.content);
return Response.none();
}
private void createEdit(ChangeResource resource) throws AuthException,
IOException, OrmException, ResourceConflictException {
Project.NameKey project = resource.getProject();
try (Repository repository = repositoryManager.openRepository(project)) {
editModifier.createEdit(repository, resource.getControl());
} catch (InvalidChangeOperationException e) {
throw new ResourceConflictException(e.getMessage());
}
}
}
public static class DeleteFile implements