Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use showconfig rather than Ini4J for getting information about the current configuration #9

Merged
merged 1 commit into from Nov 8, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions pom.xml
Expand Up @@ -109,11 +109,6 @@
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<version>0.5.2</version>
</dependency>
</dependencies>

<build>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/hudson/plugins/mercurial/HgExe.java
Expand Up @@ -176,6 +176,13 @@ private Set<String> heads(FilePath repo, boolean useTimeout, boolean usingHg15Sy
return id;
}

/**
* Gets the current value of a specified config item.
*/
public String config(FilePath repository, String name) throws IOException, InterruptedException {
return popen(repository, listener, false, new ArgumentListBuilder("showconfig", name)).trim();
}

public List<String> toArgList() {
return base.toList();
}
Expand Down
84 changes: 0 additions & 84 deletions src/main/java/hudson/plugins/mercurial/HgRc.java

This file was deleted.

102 changes: 44 additions & 58 deletions src/main/java/hudson/plugins/mercurial/MercurialSCM.java
Expand Up @@ -4,7 +4,6 @@
import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
import hudson.FilePath.FileCallable;
import hudson.Launcher;
import hudson.Launcher.ProcStarter;
import hudson.Util;
Expand All @@ -16,7 +15,6 @@
import hudson.model.Node;
import hudson.plugins.mercurial.browser.HgBrowser;
import hudson.plugins.mercurial.browser.HgWeb;
import hudson.remoting.VirtualChannel;
import hudson.scm.ChangeLogParser;
import hudson.scm.PollingResult;
import hudson.scm.PollingResult.Change;
Expand Down Expand Up @@ -372,8 +370,8 @@ public boolean checkout(AbstractBuild<?,?> build, Launcher launcher, FilePath wo
final boolean jobShouldUseSharing = mercurialInstallation != null && mercurialInstallation.isUseSharing();

FilePath repository = workspace2Repo(workspace);
boolean canReuseExistingWorkspace = repository.act(
new CheckForReusableWorkspace(jobShouldUseSharing, listener));
boolean canReuseExistingWorkspace =
canReuseWorkspace(repository, jobShouldUseSharing, build, launcher, listener);

boolean success;
if (canReuseExistingWorkspace) {
Expand All @@ -391,6 +389,48 @@ public boolean checkout(AbstractBuild<?,?> build, Launcher launcher, FilePath wo
return false;
}
}

private boolean canReuseWorkspace(FilePath repo,
boolean jobShouldUseSharing, AbstractBuild<?,?> build,
Launcher launcher, BuildListener listener)
throws IOException, InterruptedException {
if (!new FilePath(repo, ".hg/hgrc").exists()) {
return false;
}

boolean jobUsesSharing = new FilePath(repo, ".hg/sharedpath").exists();
if (jobShouldUseSharing && !jobUsesSharing) {
return false;
}
if (jobUsesSharing && !jobShouldUseSharing) {
return false;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These five lines could I think be reduced to:

if (jobShouldUseSharing ^ new FilePath(repo, ".hg/sharedpath").exists()) {
    return false;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They could be. I'd slightly prefer the following. It's an extra line, but using the variable name "jobUsesSharing" makes it clearer what the expression is actually checking. Also, while equivalent, I think many more people are familiar with the not equal operator than the logical exclusive or operator.

boolean jobUsesSharing = new FilePath(repo, ".hg/sharedpath").exists();
if (jobShouldUseSharing != jobUsesSharing) {
    return false;
}

EnvVars env = build.getEnvironment(listener);
HgExe hg = new HgExe(this,launcher,build,listener,env);
String upstream = hg.config(repo, "paths.default");
if (upstream == null) {
return false;
}
if (upstream.equals(source)) {
return true;
}
if ((upstream + '/').equals(source)) {
return true;
}
if (upstream.equals(source + '/')) {
return true;
}
if (source.startsWith("file:/") && new File(upstream).toURI().toString().equals(source)) {
return true;
}

listener.error(
"Workspace reports paths.default as " + upstream +
"\nwhich looks different than " + source +
"\nso falling back to fresh clone rather than incremental update");
return false;
}

private void determineChanges(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, File changelogFile, FilePath repository) throws IOException, InterruptedException {

Expand Down Expand Up @@ -616,60 +656,6 @@ public String getModules() {
}
}

private final class CheckForReusableWorkspace implements FileCallable<Boolean> {
private final boolean jobShouldUseSharing;
private final BuildListener listener;
private static final long serialVersionUID = 1L;

private CheckForReusableWorkspace(boolean jobShouldUseSharing,
BuildListener listener) {
this.jobShouldUseSharing = jobShouldUseSharing;
this.listener = listener;
}

public Boolean invoke(File ws, VirtualChannel channel) throws IOException {
if (!HgRc.getHgRcFile(ws).exists()) {
return false;
}

boolean jobUsesSharing = HgRc.getShareFile(ws).exists();

if (jobShouldUseSharing && !jobUsesSharing) {
return false;
}
if (jobUsesSharing && !jobShouldUseSharing) {
return false;
}

HgRc hgrc = new HgRc(ws);
return canUpdate(hgrc);
}

private boolean canUpdate(HgRc ini) {
String upstream = ini.getSection("paths").get("default");
if (upstream == null) {
return false;
}
if (upstream.equals(source)) {
return true;
}
if ((upstream + '/').equals(source)) {
return true;
}
if (upstream.equals(source + '/')) {
return true;
}
if (source.startsWith("file:/") && new File(upstream).toURI().toString().equals(source)) {
return true;
}
listener.error(
"Workspace reports paths.default as " + upstream +
"\nwhich looks different than " + source +
"\nso falling back to fresh clone rather than incremental update");
return false;
}
}

private static class PossiblyCachedRepo {
private final String repoLocation;
private final boolean useCaches;
Expand Down
15 changes: 0 additions & 15 deletions src/test/java/hudson/plugins/mercurial/HgRcTest.java

This file was deleted.