diff --git a/pom.xml b/pom.xml
index b26bcb8e..6c912406 100644
--- a/pom.xml
+++ b/pom.xml
@@ -109,11 +109,6 @@
${project.parent.version}
provided
-
- org.ini4j
- ini4j
- 0.5.2
-
diff --git a/src/main/java/hudson/plugins/mercurial/HgExe.java b/src/main/java/hudson/plugins/mercurial/HgExe.java
index f2ff7ba4..37768532 100644
--- a/src/main/java/hudson/plugins/mercurial/HgExe.java
+++ b/src/main/java/hudson/plugins/mercurial/HgExe.java
@@ -176,6 +176,13 @@ private Set 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 toArgList() {
return base.toList();
}
diff --git a/src/main/java/hudson/plugins/mercurial/HgRc.java b/src/main/java/hudson/plugins/mercurial/HgRc.java
deleted file mode 100644
index 075d30cf..00000000
--- a/src/main/java/hudson/plugins/mercurial/HgRc.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package hudson.plugins.mercurial;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Map;
-import java.util.TreeMap;
-import org.apache.commons.io.IOUtils;
-import org.ini4j.Ini;
-
-/**
- * Parses the .hgrc file.
- */
-final class HgRc {
- private final Ini ini;
-
- HgRc(File repository) throws IOException {
- this(load(repository), getHgRcFile(repository));
- }
-
- private static InputStream load(File repository) throws IOException {
- File hgrc = getHgRcFile(repository);
- if (!hgrc.exists()) {
- throw new IOException("No such file: " + hgrc);
- }
- return new FileInputStream(hgrc);
- }
-
- HgRc(InputStream input, File hgrc) throws IOException {
- try {
- ini = new Ini(input);
- } finally {
- IOUtils.closeQuietly(input);
- }
- }
-
- public static File getHgRcFile(File repository) {
- return new File(repository, ".hg/hgrc");
- }
-
- public static File getShareFile(File repository) {
- return new File(repository, ".hg/sharedpath");
- }
-
- /**
- * Gets the section. If no such section exists, return an empty constant
- * section.
- */
- public Section getSection(String name) {
- return new Section(ini, name);
- }
-
- @Override
- public String toString() {
- Map sections = new TreeMap();
- for (String s : ini.keySet()) {
- sections.put(s, getSection(s));
- }
- return sections.toString();
- }
-
- public static final class Section {
-
- private final Ini ini;
- private final String name;
-
- private Section(Ini ini, String name) {
- this.ini = ini;
- this.name = name;
- }
-
- public String get(String key) {
- return ini.get(name, key);
- }
-
- @Override
- public String toString() {
- Map vals = ini.get(name);
- return vals != null ? new TreeMap(vals).toString() : "{}";
- }
- }
-
-}
diff --git a/src/main/java/hudson/plugins/mercurial/MercurialSCM.java b/src/main/java/hudson/plugins/mercurial/MercurialSCM.java
index 01774d27..d6c536b1 100644
--- a/src/main/java/hudson/plugins/mercurial/MercurialSCM.java
+++ b/src/main/java/hudson/plugins/mercurial/MercurialSCM.java
@@ -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;
@@ -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;
@@ -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) {
@@ -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;
+ }
+
+ 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 {
@@ -616,60 +656,6 @@ public String getModules() {
}
}
- private final class CheckForReusableWorkspace implements FileCallable {
- 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;
diff --git a/src/test/java/hudson/plugins/mercurial/HgRcTest.java b/src/test/java/hudson/plugins/mercurial/HgRcTest.java
deleted file mode 100644
index 6858f800..00000000
--- a/src/test/java/hudson/plugins/mercurial/HgRcTest.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package hudson.plugins.mercurial;
-
-import java.io.ByteArrayInputStream;
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-public class HgRcTest {
-
- @Test
- public void parsing() throws Exception {
- HgRc rc = new HgRc(new ByteArrayInputStream("[foo]\nbar=baz\n\n#comment\n[encode]\n*.{x,y} = run: gzopp\n[extensions]\nfrobnitz = ".getBytes()), null);
- assertEquals("{encode={*.{x,y}=run: gzopp}, extensions={frobnitz=}, foo={bar=baz}}", rc.toString());
- }
-
-}
\ No newline at end of file