diff --git a/Documentation/cmd-index-changes.txt b/Documentation/cmd-index-changes.txt new file mode 100644 index 0000000000..8566827a47 --- /dev/null +++ b/Documentation/cmd-index-changes.txt @@ -0,0 +1,40 @@ += gerrit index changes + +== NAME +gerrit index changes - Index one or more changes. + +== SYNOPSIS +-- +'ssh' -p 'gerrit index changes' [ ...] +-- + +== DESCRIPTION +Indexes one or more changes. + +Changes can be specified in the link:rest-api-changes.html#change-id[same format] +supported by the REST API. + +== ACCESS +Caller must have the 'Maintain Server' capability, or be the owner of the change +to be indexed. + +== SCRIPTING +This command is intended to be used in scripts. + +== OPTIONS +--CHANGE:: + Required; changes to be indexed. + +== EXAMPLES +Index changes with legacy ID numbers 1 and 2. + +==== + $ ssh -p 29418 user@review.example.com gerrit index changes 1 2 +==== + +GERRIT +------ +Part of link:index.html[Gerrit Code Review] + +SEARCHBOX +--------- diff --git a/Documentation/cmd-index.txt b/Documentation/cmd-index.txt index 90212fb51f..e244228028 100644 --- a/Documentation/cmd-index.txt +++ b/Documentation/cmd-index.txt @@ -126,6 +126,9 @@ link:cmd-index-activate.html[gerrit index activate]:: link:cmd-index-start.html[gerrit index start]:: Start the online indexer. +link:cmd-index-changes.html[gerrit index changes]:: + Index one or more changes. + link:cmd-logging-ls-level.html[gerrit logging ls-level]:: List loggers and their logging level. diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/IndexChangesCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/IndexChangesCommand.java new file mode 100644 index 0000000000..f2c858e5ae --- /dev/null +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/IndexChangesCommand.java @@ -0,0 +1,71 @@ +// Copyright (C) 2016 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.sshd.commands; + +import com.google.gerrit.extensions.restapi.RestApiException; +import com.google.gerrit.reviewdb.client.Change; +import com.google.gerrit.server.change.ChangeResource; +import com.google.gerrit.server.change.Index; +import com.google.gerrit.sshd.ChangeArgumentParser; +import com.google.gerrit.sshd.CommandMetaData; +import com.google.gerrit.sshd.SshCommand; +import com.google.gwtorm.server.OrmException; +import com.google.inject.Inject; + +import org.kohsuke.args4j.Argument; + +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; + +@CommandMetaData(name = "changes", description = "Index changes") +final class IndexChangesCommand extends SshCommand { + @Inject + private Index index; + + @Inject + private ChangeArgumentParser changeArgumentParser; + + @Argument(index = 0, required = true, multiValued = true, metaVar = "CHANGE", + usage = "changes to index") + void addChange(String token) { + try { + changeArgumentParser.addChange(token, changes); + } catch (UnloggedFailure e) { + throw new IllegalArgumentException(e.getMessage(), e); + } catch (OrmException e) { + throw new IllegalArgumentException("database is down", e); + } + } + + private Map changes = new LinkedHashMap<>(); + + @Override + protected void run() throws UnloggedFailure { + boolean ok = true; + for (ChangeResource rsrc : changes.values()) { + try { + index.apply(rsrc, new Index.Input()); + } catch (IOException | RestApiException e) { + ok = false; + writeError("error", String.format( + "failed to index change %s: %s", rsrc.getId(), e.getMessage())); + } + } + if (!ok) { + throw die("failed to index one or more changes"); + } + } +} diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/IndexCommandsModule.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/IndexCommandsModule.java index 3e7b293208..633bca8861 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/IndexCommandsModule.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/IndexCommandsModule.java @@ -28,5 +28,6 @@ public class IndexCommandsModule extends CommandModule { command(index).toProvider(new DispatchCommandProvider(index)); command(index, IndexActivateCommand.class); command(index, IndexStartCommand.class); + command(index, IndexChangesCommand.class); } }