Make commands to download patch sets configurable

For patch sets on the ChangeScreen different commands for downloading
the patch sets are offered. For some installations not all commands are
needed. Allow Gerrit administrators to configure which download
commands should be offered.

Bug: issue 548
Change-Id: Ida3e00f3b98e37280ecded2e25b20fc0a21abec0
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin 2012-09-14 16:32:57 +02:00
parent eaac316bf3
commit 08b03a2984
6 changed files with 116 additions and 47 deletions

View File

@ -1012,6 +1012,10 @@ Default is `30 seconds`.
----
[download]
command = checkout
command = cherry_pick
command = pull
command = format_patch
scheme = ssh
scheme = http
scheme = anon_http
@ -1021,6 +1025,34 @@ Default is `30 seconds`.
The download section configures the allowed download methods.
[[download.command]]download.command::
+
Commands that should be offered to download changes.
+
Multiple commands are supported:
+
* `checkout`
+
Command to fetch and checkout the patch set.
+
* `cherry_pick`
+
Command to fetch the patch set and to cherry-pick it onto the current
commit.
+
* `pull`
+
Command to pull the patch set.
+
* `format_patch`
+
Command to fetch the patch set and to feed it into the `format-patch`
command.
+
If `download.command` is not specified, all download commands are
offered.
[[download.scheme]]download.scheme::
+
Schemes that should be used to download changes.
@ -1053,7 +1085,7 @@ generally worked on with the repo multi-repository tool. This is
not default, as not all instances will deploy repo.
+
If download.scheme is not specified, SSH, HTTP and Anonymous HTTP
If `download.scheme` is not specified, SSH, HTTP and Anonymous HTTP
downloads are allowed.
[[gerrit]]Section gerrit

View File

@ -17,6 +17,7 @@ package com.google.gerrit.common.data;
import com.google.gerrit.common.auth.openid.OpenIdProviderPattern;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Account.FieldName;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gerrit.reviewdb.client.Project;
@ -38,6 +39,7 @@ public class GerritConfig implements Cloneable {
protected boolean allowRegisterNewEmail;
protected AuthType authType;
protected Set<DownloadScheme> downloadSchemes;
protected Set<DownloadCommand> downloadCommands;
protected String gitDaemonUrl;
protected String gitHttpUrl;
protected String sshdAddress;
@ -114,6 +116,14 @@ public class GerritConfig implements Cloneable {
downloadSchemes = s;
}
public Set<DownloadCommand> getDownloadCommands() {
return downloadCommands;
}
public void setDownloadCommands(final Set<DownloadCommand> downloadCommands) {
this.downloadCommands = downloadCommands;
}
public GitwebConfig getGitwebLink() {
return gitweb;
}

View File

@ -209,6 +209,7 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel
final DownloadCommandPanel commands = new DownloadCommandPanel();
final DownloadUrlPanel urls = new DownloadUrlPanel(commands);
final Set<DownloadScheme> allowedSchemes = Gerrit.getConfig().getDownloadSchemes();
final Set<DownloadCommand> allowedCommands = Gerrit.getConfig().getDownloadCommands();
copyLabel.setStyleName(Gerrit.RESOURCES.css().downloadLinkCopyLabel());
@ -323,39 +324,52 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel
}
if (!urls.isEmpty()) {
commands.add(new DownloadCommandLink(DownloadCommand.CHECKOUT, "checkout") {
@Override
void setCurrentUrl(DownloadUrlLink link) {
urls.setVisible(true);
copyLabel.setText("git fetch " + link.urlData
+ " && git checkout FETCH_HEAD");
}
});
commands.add(new DownloadCommandLink(DownloadCommand.PULL, "pull") {
@Override
void setCurrentUrl(DownloadUrlLink link) {
urls.setVisible(true);
copyLabel.setText("git pull " + link.urlData);
}
});
commands.add(new DownloadCommandLink(DownloadCommand.CHERRY_PICK,
"cherry-pick") {
@Override
void setCurrentUrl(DownloadUrlLink link) {
urls.setVisible(true);
copyLabel.setText("git fetch " + link.urlData
+ " && git cherry-pick FETCH_HEAD");
}
});
commands.add(new DownloadCommandLink(DownloadCommand.FORMAT_PATCH,
"patch") {
@Override
void setCurrentUrl(DownloadUrlLink link) {
urls.setVisible(true);
copyLabel.setText("git fetch " + link.urlData
+ " && git format-patch -1 --stdout FETCH_HEAD");
}
});
if (allowedCommands.contains(DownloadCommand.CHECKOUT)
|| allowedCommands.contains(DownloadCommand.DEFAULT_DOWNLOADS)) {
commands.add(new DownloadCommandLink(DownloadCommand.CHECKOUT,
"checkout") {
@Override
void setCurrentUrl(DownloadUrlLink link) {
urls.setVisible(true);
copyLabel.setText("git fetch " + link.urlData
+ " && git checkout FETCH_HEAD");
}
});
}
if (allowedCommands.contains(DownloadCommand.PULL)
|| allowedCommands.contains(DownloadCommand.DEFAULT_DOWNLOADS)) {
commands.add(new DownloadCommandLink(DownloadCommand.PULL, "pull") {
@Override
void setCurrentUrl(DownloadUrlLink link) {
urls.setVisible(true);
copyLabel.setText("git pull " + link.urlData);
}
});
}
if (allowedCommands.contains(DownloadCommand.CHERRY_PICK)
|| allowedCommands.contains(DownloadCommand.DEFAULT_DOWNLOADS)) {
commands.add(new DownloadCommandLink(DownloadCommand.CHERRY_PICK,
"cherry-pick") {
@Override
void setCurrentUrl(DownloadUrlLink link) {
urls.setVisible(true);
copyLabel.setText("git fetch " + link.urlData
+ " && git cherry-pick FETCH_HEAD");
}
});
}
if (allowedCommands.contains(DownloadCommand.FORMAT_PATCH)
|| allowedCommands.contains(DownloadCommand.DEFAULT_DOWNLOADS)) {
commands.add(new DownloadCommandLink(DownloadCommand.FORMAT_PATCH,
"patch") {
@Override
void setCurrentUrl(DownloadUrlLink link) {
urls.setVisible(true);
copyLabel.setText("git fetch " + link.urlData
+ " && git format-patch -1 --stdout FETCH_HEAD");
}
});
}
}
final FlowPanel fp = new FlowPanel();

View File

@ -22,7 +22,7 @@ import com.google.gerrit.server.account.Realm;
import com.google.gerrit.server.config.AllProjectsName;
import com.google.gerrit.server.config.AnonymousCowardName;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gerrit.server.config.DownloadSchemeConfig;
import com.google.gerrit.server.config.DownloadConfig;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.contact.ContactStore;
import com.google.gerrit.server.mail.EmailSender;
@ -48,7 +48,7 @@ class GerritConfigProvider implements Provider<GerritConfig> {
private final Realm realm;
private final Config cfg;
private final AuthConfig authConfig;
private final DownloadSchemeConfig schemeConfig;
private final DownloadConfig downloadConfig;
private final GitWebConfig gitWebConfig;
private final AllProjectsName wildProject;
private final SshInfo sshInfo;
@ -63,12 +63,12 @@ class GerritConfigProvider implements Provider<GerritConfig> {
GerritConfigProvider(final Realm r, @GerritServerConfig final Config gsc,
final AuthConfig ac, final GitWebConfig gwc, final AllProjectsName wp,
final SshInfo si, final ApprovalTypes at, final ContactStore cs,
final ServletContext sc, final DownloadSchemeConfig dc,
final ServletContext sc, final DownloadConfig dc,
final @AnonymousCowardName String acn) {
realm = r;
cfg = gsc;
authConfig = ac;
schemeConfig = dc;
downloadConfig = dc;
gitWebConfig = gwc;
sshInfo = si;
wildProject = wp;
@ -111,7 +111,8 @@ class GerritConfigProvider implements Provider<GerritConfig> {
config.setGitDaemonUrl(cfg.getString("gerrit", null, "canonicalgiturl"));
config.setGitHttpUrl(cfg.getString("gerrit", null, "gitHttpUrl"));
config.setUseContactInfo(contactStore != null && contactStore.isEnabled());
config.setDownloadSchemes(schemeConfig.getDownloadScheme());
config.setDownloadSchemes(downloadConfig.getDownloadSchemes());
config.setDownloadCommands(downloadConfig.getDownloadCommands());
config.setAuthType(authConfig.getAuthType());
config.setWildProject(wildProject);
config.setApprovalTypes(approvalTypes);

View File

@ -32,7 +32,7 @@ public final class AccountGeneralPreferences {
/** Preferred method to download a change. */
public static enum DownloadCommand {
REPO_DOWNLOAD, PULL, CHECKOUT, CHERRY_PICK, FORMAT_PATCH;
REPO_DOWNLOAD, PULL, CHECKOUT, CHERRY_PICK, FORMAT_PATCH, DEFAULT_DOWNLOADS;
}
public static enum DateFormat {

View File

@ -14,8 +14,9 @@
package com.google.gerrit.server.config;
import com.google.gerrit.reviewdb.client.SystemConfig;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
import com.google.gerrit.reviewdb.client.SystemConfig;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@ -28,22 +29,33 @@ import java.util.Set;
/** Download protocol from {@code gerrit.config}. */
@Singleton
public class DownloadSchemeConfig {
public class DownloadConfig {
private final Set<DownloadScheme> downloadSchemes;
private final Set<DownloadCommand> downloadCommands;
@Inject
DownloadSchemeConfig(@GerritServerConfig final Config cfg,
DownloadConfig(@GerritServerConfig final Config cfg,
final SystemConfig s) {
List<DownloadScheme> all =
List<DownloadScheme> allSchemes =
ConfigUtil.getEnumList(cfg, "download", null, "scheme",
DownloadScheme.DEFAULT_DOWNLOADS);
downloadSchemes =
Collections.unmodifiableSet(new HashSet<DownloadScheme>(all));
Collections.unmodifiableSet(new HashSet<DownloadScheme>(allSchemes));
List<DownloadCommand> allCommands =
ConfigUtil.getEnumList(cfg, "download", null, "command",
DownloadCommand.DEFAULT_DOWNLOADS);
downloadCommands =
Collections.unmodifiableSet(new HashSet<DownloadCommand>(allCommands));
}
/** Scheme used to download. */
public Set<DownloadScheme> getDownloadScheme() {
public Set<DownloadScheme> getDownloadSchemes() {
return downloadSchemes;
}
/** Command used to download. */
public Set<DownloadCommand> getDownloadCommands() {
return downloadCommands;
}
}