Advertise the smart HTTP URLs to references
This way users can pull directly over http:// and don't need to fall back onto git:// or ssh:// if they don't want to. Change-Id: I5f16ac49dc75cc6adff861804112286ee103e795 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
parent
024d69b2fe
commit
0302d07f1f
@ -29,6 +29,7 @@ import com.google.gerrit.reviewdb.PatchSet;
|
||||
import com.google.gerrit.reviewdb.PatchSetInfo;
|
||||
import com.google.gerrit.reviewdb.Project;
|
||||
import com.google.gerrit.reviewdb.UserIdentity;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.logical.shared.OpenEvent;
|
||||
@ -137,28 +138,32 @@ class PatchSetPanel extends Composite implements OpenHandler<DisclosurePanel> {
|
||||
downloads.add(new CopyableLabel(r.toString()));
|
||||
}
|
||||
|
||||
if (changeDetail.isAllowsAnonymous()
|
||||
&& Gerrit.getConfig().getGitDaemonUrl() != null) {
|
||||
// Anonymous Git is claimed to be available, and this project
|
||||
// isn't secured. The anonymous Git daemon will be much more
|
||||
// efficient than our own SSH daemon, so prefer offering it.
|
||||
//
|
||||
final StringBuilder r = new StringBuilder();
|
||||
if (changeDetail.isAllowsAnonymous()) {
|
||||
if (Gerrit.getConfig().getGitDaemonUrl() != null) {
|
||||
StringBuilder r = new StringBuilder();
|
||||
r.append("git pull ");
|
||||
r.append(Gerrit.getConfig().getGitDaemonUrl());
|
||||
r.append(projectName);
|
||||
r.append(" ");
|
||||
r.append(patchSet.getRefName());
|
||||
downloads.add(new CopyableLabel(r.toString()));
|
||||
}
|
||||
|
||||
} else if (Gerrit.isSignedIn() && Gerrit.getUserAccount() != null
|
||||
&& Gerrit.getConfig().getSshdAddress() != null
|
||||
StringBuilder r = new StringBuilder();
|
||||
r.append("git pull ");
|
||||
r.append(GWT.getHostPageBaseURL());
|
||||
r.append("p/");
|
||||
r.append(projectName);
|
||||
r.append(" ");
|
||||
r.append(patchSet.getRefName());
|
||||
downloads.add(new CopyableLabel(r.toString()));
|
||||
|
||||
} else if (Gerrit.isSignedIn()
|
||||
&& Gerrit.getUserAccount().getUserName() != null
|
||||
&& Gerrit.getUserAccount().getUserName().length() > 0) {
|
||||
// The user is signed in and anonymous access isn't allowed.
|
||||
// Use our SSH daemon URL as its the only way they can get
|
||||
// to the project (that we know of anyway).
|
||||
//
|
||||
if (Gerrit.getConfig().getSshdAddress() != null) {
|
||||
String sshAddr = Gerrit.getConfig().getSshdAddress();
|
||||
final StringBuilder r = new StringBuilder();
|
||||
r.append("git pull ssh://");
|
||||
@ -178,6 +183,31 @@ class PatchSetPanel extends Composite implements OpenHandler<DisclosurePanel> {
|
||||
downloads.add(new CopyableLabel(r.toString()));
|
||||
}
|
||||
|
||||
String base = GWT.getHostPageBaseURL();
|
||||
int p = base.indexOf("://");
|
||||
int s = base.indexOf('/', p + 3);
|
||||
if (s < 0) {
|
||||
s = base.length();
|
||||
}
|
||||
String host = base.substring(p + 3, s);
|
||||
if (host.contains("@")) {
|
||||
host = host.substring(host.indexOf('@') + 1);
|
||||
}
|
||||
|
||||
final StringBuilder r = new StringBuilder();
|
||||
r.append("git pull ");
|
||||
r.append(base.substring(0, p + 3));
|
||||
r.append(Gerrit.getUserAccount().getUserName());
|
||||
r.append('@');
|
||||
r.append(host);
|
||||
r.append(base.substring(s));
|
||||
r.append("p/");
|
||||
r.append(projectName);
|
||||
r.append(" ");
|
||||
r.append(patchSet.getRefName());
|
||||
downloads.add(new CopyableLabel(r.toString()));
|
||||
}
|
||||
|
||||
infoTable.setWidget(R_DOWNLOAD, 1, downloads);
|
||||
}
|
||||
|
||||
@ -287,7 +317,8 @@ class PatchSetPanel extends Composite implements OpenHandler<DisclosurePanel> {
|
||||
|
||||
private void initRow(final int row, final String name) {
|
||||
infoTable.setText(row, 0, name);
|
||||
infoTable.getCellFormatter().addStyleName(row, 0, Gerrit.RESOURCES.css().header());
|
||||
infoTable.getCellFormatter().addStyleName(row, 0,
|
||||
Gerrit.RESOURCES.css().header());
|
||||
}
|
||||
|
||||
private void onSubmitResult(final ChangeDetail result) {
|
||||
|
Loading…
Reference in New Issue
Block a user