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:
@@ -1012,6 +1012,10 @@ Default is `30 seconds`.
|
|||||||
|
|
||||||
----
|
----
|
||||||
[download]
|
[download]
|
||||||
|
command = checkout
|
||||||
|
command = cherry_pick
|
||||||
|
command = pull
|
||||||
|
command = format_patch
|
||||||
scheme = ssh
|
scheme = ssh
|
||||||
scheme = http
|
scheme = http
|
||||||
scheme = anon_http
|
scheme = anon_http
|
||||||
@@ -1021,6 +1025,34 @@ Default is `30 seconds`.
|
|||||||
|
|
||||||
The download section configures the allowed download methods.
|
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::
|
[[download.scheme]]download.scheme::
|
||||||
+
|
+
|
||||||
Schemes that should be used to download changes.
|
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.
|
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.
|
downloads are allowed.
|
||||||
|
|
||||||
[[gerrit]]Section gerrit
|
[[gerrit]]Section gerrit
|
||||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.common.data;
|
|||||||
import com.google.gerrit.common.auth.openid.OpenIdProviderPattern;
|
import com.google.gerrit.common.auth.openid.OpenIdProviderPattern;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.client.Account.FieldName;
|
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.AccountGeneralPreferences.DownloadScheme;
|
||||||
import com.google.gerrit.reviewdb.client.AuthType;
|
import com.google.gerrit.reviewdb.client.AuthType;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
@@ -38,6 +39,7 @@ public class GerritConfig implements Cloneable {
|
|||||||
protected boolean allowRegisterNewEmail;
|
protected boolean allowRegisterNewEmail;
|
||||||
protected AuthType authType;
|
protected AuthType authType;
|
||||||
protected Set<DownloadScheme> downloadSchemes;
|
protected Set<DownloadScheme> downloadSchemes;
|
||||||
|
protected Set<DownloadCommand> downloadCommands;
|
||||||
protected String gitDaemonUrl;
|
protected String gitDaemonUrl;
|
||||||
protected String gitHttpUrl;
|
protected String gitHttpUrl;
|
||||||
protected String sshdAddress;
|
protected String sshdAddress;
|
||||||
@@ -114,6 +116,14 @@ public class GerritConfig implements Cloneable {
|
|||||||
downloadSchemes = s;
|
downloadSchemes = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<DownloadCommand> getDownloadCommands() {
|
||||||
|
return downloadCommands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownloadCommands(final Set<DownloadCommand> downloadCommands) {
|
||||||
|
this.downloadCommands = downloadCommands;
|
||||||
|
}
|
||||||
|
|
||||||
public GitwebConfig getGitwebLink() {
|
public GitwebConfig getGitwebLink() {
|
||||||
return gitweb;
|
return gitweb;
|
||||||
}
|
}
|
||||||
|
@@ -209,6 +209,7 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel
|
|||||||
final DownloadCommandPanel commands = new DownloadCommandPanel();
|
final DownloadCommandPanel commands = new DownloadCommandPanel();
|
||||||
final DownloadUrlPanel urls = new DownloadUrlPanel(commands);
|
final DownloadUrlPanel urls = new DownloadUrlPanel(commands);
|
||||||
final Set<DownloadScheme> allowedSchemes = Gerrit.getConfig().getDownloadSchemes();
|
final Set<DownloadScheme> allowedSchemes = Gerrit.getConfig().getDownloadSchemes();
|
||||||
|
final Set<DownloadCommand> allowedCommands = Gerrit.getConfig().getDownloadCommands();
|
||||||
|
|
||||||
copyLabel.setStyleName(Gerrit.RESOURCES.css().downloadLinkCopyLabel());
|
copyLabel.setStyleName(Gerrit.RESOURCES.css().downloadLinkCopyLabel());
|
||||||
|
|
||||||
@@ -323,39 +324,52 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!urls.isEmpty()) {
|
if (!urls.isEmpty()) {
|
||||||
commands.add(new DownloadCommandLink(DownloadCommand.CHECKOUT, "checkout") {
|
if (allowedCommands.contains(DownloadCommand.CHECKOUT)
|
||||||
@Override
|
|| allowedCommands.contains(DownloadCommand.DEFAULT_DOWNLOADS)) {
|
||||||
void setCurrentUrl(DownloadUrlLink link) {
|
commands.add(new DownloadCommandLink(DownloadCommand.CHECKOUT,
|
||||||
urls.setVisible(true);
|
"checkout") {
|
||||||
copyLabel.setText("git fetch " + link.urlData
|
@Override
|
||||||
+ " && git checkout FETCH_HEAD");
|
void setCurrentUrl(DownloadUrlLink link) {
|
||||||
}
|
urls.setVisible(true);
|
||||||
});
|
copyLabel.setText("git fetch " + link.urlData
|
||||||
commands.add(new DownloadCommandLink(DownloadCommand.PULL, "pull") {
|
+ " && git checkout FETCH_HEAD");
|
||||||
@Override
|
}
|
||||||
void setCurrentUrl(DownloadUrlLink link) {
|
});
|
||||||
urls.setVisible(true);
|
}
|
||||||
copyLabel.setText("git pull " + link.urlData);
|
if (allowedCommands.contains(DownloadCommand.PULL)
|
||||||
}
|
|| allowedCommands.contains(DownloadCommand.DEFAULT_DOWNLOADS)) {
|
||||||
});
|
commands.add(new DownloadCommandLink(DownloadCommand.PULL, "pull") {
|
||||||
commands.add(new DownloadCommandLink(DownloadCommand.CHERRY_PICK,
|
@Override
|
||||||
"cherry-pick") {
|
void setCurrentUrl(DownloadUrlLink link) {
|
||||||
@Override
|
urls.setVisible(true);
|
||||||
void setCurrentUrl(DownloadUrlLink link) {
|
copyLabel.setText("git pull " + link.urlData);
|
||||||
urls.setVisible(true);
|
}
|
||||||
copyLabel.setText("git fetch " + link.urlData
|
});
|
||||||
+ " && git cherry-pick FETCH_HEAD");
|
}
|
||||||
}
|
if (allowedCommands.contains(DownloadCommand.CHERRY_PICK)
|
||||||
});
|
|| allowedCommands.contains(DownloadCommand.DEFAULT_DOWNLOADS)) {
|
||||||
commands.add(new DownloadCommandLink(DownloadCommand.FORMAT_PATCH,
|
commands.add(new DownloadCommandLink(DownloadCommand.CHERRY_PICK,
|
||||||
"patch") {
|
"cherry-pick") {
|
||||||
@Override
|
@Override
|
||||||
void setCurrentUrl(DownloadUrlLink link) {
|
void setCurrentUrl(DownloadUrlLink link) {
|
||||||
urls.setVisible(true);
|
urls.setVisible(true);
|
||||||
copyLabel.setText("git fetch " + link.urlData
|
copyLabel.setText("git fetch " + link.urlData
|
||||||
+ " && git format-patch -1 --stdout FETCH_HEAD");
|
+ " && 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();
|
final FlowPanel fp = new FlowPanel();
|
||||||
|
@@ -22,7 +22,7 @@ import com.google.gerrit.server.account.Realm;
|
|||||||
import com.google.gerrit.server.config.AllProjectsName;
|
import com.google.gerrit.server.config.AllProjectsName;
|
||||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||||
import com.google.gerrit.server.config.AuthConfig;
|
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.config.GerritServerConfig;
|
||||||
import com.google.gerrit.server.contact.ContactStore;
|
import com.google.gerrit.server.contact.ContactStore;
|
||||||
import com.google.gerrit.server.mail.EmailSender;
|
import com.google.gerrit.server.mail.EmailSender;
|
||||||
@@ -48,7 +48,7 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
|||||||
private final Realm realm;
|
private final Realm realm;
|
||||||
private final Config cfg;
|
private final Config cfg;
|
||||||
private final AuthConfig authConfig;
|
private final AuthConfig authConfig;
|
||||||
private final DownloadSchemeConfig schemeConfig;
|
private final DownloadConfig downloadConfig;
|
||||||
private final GitWebConfig gitWebConfig;
|
private final GitWebConfig gitWebConfig;
|
||||||
private final AllProjectsName wildProject;
|
private final AllProjectsName wildProject;
|
||||||
private final SshInfo sshInfo;
|
private final SshInfo sshInfo;
|
||||||
@@ -63,12 +63,12 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
|||||||
GerritConfigProvider(final Realm r, @GerritServerConfig final Config gsc,
|
GerritConfigProvider(final Realm r, @GerritServerConfig final Config gsc,
|
||||||
final AuthConfig ac, final GitWebConfig gwc, final AllProjectsName wp,
|
final AuthConfig ac, final GitWebConfig gwc, final AllProjectsName wp,
|
||||||
final SshInfo si, final ApprovalTypes at, final ContactStore cs,
|
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) {
|
final @AnonymousCowardName String acn) {
|
||||||
realm = r;
|
realm = r;
|
||||||
cfg = gsc;
|
cfg = gsc;
|
||||||
authConfig = ac;
|
authConfig = ac;
|
||||||
schemeConfig = dc;
|
downloadConfig = dc;
|
||||||
gitWebConfig = gwc;
|
gitWebConfig = gwc;
|
||||||
sshInfo = si;
|
sshInfo = si;
|
||||||
wildProject = wp;
|
wildProject = wp;
|
||||||
@@ -111,7 +111,8 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
|||||||
config.setGitDaemonUrl(cfg.getString("gerrit", null, "canonicalgiturl"));
|
config.setGitDaemonUrl(cfg.getString("gerrit", null, "canonicalgiturl"));
|
||||||
config.setGitHttpUrl(cfg.getString("gerrit", null, "gitHttpUrl"));
|
config.setGitHttpUrl(cfg.getString("gerrit", null, "gitHttpUrl"));
|
||||||
config.setUseContactInfo(contactStore != null && contactStore.isEnabled());
|
config.setUseContactInfo(contactStore != null && contactStore.isEnabled());
|
||||||
config.setDownloadSchemes(schemeConfig.getDownloadScheme());
|
config.setDownloadSchemes(downloadConfig.getDownloadSchemes());
|
||||||
|
config.setDownloadCommands(downloadConfig.getDownloadCommands());
|
||||||
config.setAuthType(authConfig.getAuthType());
|
config.setAuthType(authConfig.getAuthType());
|
||||||
config.setWildProject(wildProject);
|
config.setWildProject(wildProject);
|
||||||
config.setApprovalTypes(approvalTypes);
|
config.setApprovalTypes(approvalTypes);
|
||||||
|
@@ -32,7 +32,7 @@ public final class AccountGeneralPreferences {
|
|||||||
|
|
||||||
/** Preferred method to download a change. */
|
/** Preferred method to download a change. */
|
||||||
public static enum DownloadCommand {
|
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 {
|
public static enum DateFormat {
|
||||||
|
@@ -14,8 +14,9 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.config;
|
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.AccountGeneralPreferences.DownloadScheme;
|
||||||
|
import com.google.gerrit.reviewdb.client.SystemConfig;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
@@ -28,22 +29,33 @@ import java.util.Set;
|
|||||||
|
|
||||||
/** Download protocol from {@code gerrit.config}. */
|
/** Download protocol from {@code gerrit.config}. */
|
||||||
@Singleton
|
@Singleton
|
||||||
public class DownloadSchemeConfig {
|
public class DownloadConfig {
|
||||||
private final Set<DownloadScheme> downloadSchemes;
|
private final Set<DownloadScheme> downloadSchemes;
|
||||||
|
private final Set<DownloadCommand> downloadCommands;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
DownloadSchemeConfig(@GerritServerConfig final Config cfg,
|
DownloadConfig(@GerritServerConfig final Config cfg,
|
||||||
final SystemConfig s) {
|
final SystemConfig s) {
|
||||||
List<DownloadScheme> all =
|
List<DownloadScheme> allSchemes =
|
||||||
ConfigUtil.getEnumList(cfg, "download", null, "scheme",
|
ConfigUtil.getEnumList(cfg, "download", null, "scheme",
|
||||||
DownloadScheme.DEFAULT_DOWNLOADS);
|
DownloadScheme.DEFAULT_DOWNLOADS);
|
||||||
|
|
||||||
downloadSchemes =
|
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. */
|
/** Scheme used to download. */
|
||||||
public Set<DownloadScheme> getDownloadScheme() {
|
public Set<DownloadScheme> getDownloadSchemes() {
|
||||||
return downloadSchemes;
|
return downloadSchemes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Command used to download. */
|
||||||
|
public Set<DownloadCommand> getDownloadCommands() {
|
||||||
|
return downloadCommands;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user