Index: src/main/java/hudson/plugins/mercurial/MercurialSCM.java =================================================================== --- src/main/java/hudson/plugins/mercurial/MercurialSCM.java (revision 10725) +++ src/main/java/hudson/plugins/mercurial/MercurialSCM.java (working copy) @@ -26,7 +26,7 @@ /** * Mercurial SCM. - * + * * @author Kohsuke Kawaguchi */ public class MercurialSCM extends SCM implements Serializable { @@ -34,7 +34,7 @@ * Source repository URL from which we pull. */ private final String source; - + /** * Prefixes of files within the repository which we're dependent on. * Storing as member variable so as to only parse the dependencies string once. @@ -42,9 +42,9 @@ private transient final Set _modules = new HashSet(); // Same thing, but not parsed for jelly. private final String modules; - + /** - * In-repository branch to follow. Null indicates "default". + * In-repository branch to follow. Null indicates "default". */ private final String branch; @@ -62,19 +62,21 @@ r[i] = r[i].replaceAll("\\\\ ", " "); // Strip leading slashes - while (r[i].startsWith("/")) + while (r[i].startsWith("/")) { r[i] = r[i].substring(1); + } // Use unix file path separators r[i] = r[i].replace('\\', '/'); } - this._modules.addAll(Arrays.asList(r)); + _modules.addAll(Arrays.asList(r)); // normalization branch = Util.fixEmpty(branch); - if(branch!=null && branch.equals("default")) + if(branch!=null && branch.equals("default")) { branch = null; + } this.branch = branch; this.browser = browser; @@ -113,11 +115,16 @@ tmpTxt.write(FILES_STYLE); // Get the list of changed files. + ArgumentListBuilder args = new ArgumentListBuilder(); + args.add(getDescriptor().getHgExe(), "incoming", "--style", tmpFile.getCanonicalPath()); + if (branch != null) { + args.add("-r", branch); + } + launcher.launch( - new String[]{getDescriptor().getHgExe(), "incoming", "--style", tmpFile.getCanonicalPath()}, + args.toCommandArray(), EnvVars.masterEnvVars, new ForkOutputStream(baos, output), workspace).join(); - Set changedFileNames = new HashSet(); parseIncomingOutput(baos, changedFileNames); @@ -182,25 +189,31 @@ public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspace, BuildListener listener, File changelogFile) throws IOException, InterruptedException { boolean canUpdate = workspace.act(new FileCallable() { public Boolean invoke(File ws, VirtualChannel channel) throws IOException { - if(!HgRc.getHgRcFile(ws).exists()) + if(!HgRc.getHgRcFile(ws).exists()) { 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==null) { + return false; + } - if(upstream.equals(source)) return true; + if(upstream.equals(source)) { + return true; + } return source.startsWith("file:/") && new File(upstream).toURI().toString().equals(source); } }); - if(canUpdate) + if(canUpdate) { return update(build,launcher,workspace,listener,changelogFile); - else + } else { return clone(build,launcher,workspace,listener,changelogFile); + } } /** @@ -250,7 +263,9 @@ args.add("--debug"); } - if(branch!=null) args.add("-r",branch); + if(branch!=null) { + args.add("-r",branch); + } ByteArrayOutputStream errorLog = new ByteArrayOutputStream(); @@ -276,7 +291,7 @@ } // pull - if(r==0 && hgBundle.exists()) + if(r==0 && hgBundle.exists()) { // if incoming didn't fetch anything, it will return 1. That was for 0.9.3. // in 0.9.4 apparently it returns 0. try { @@ -290,6 +305,7 @@ listener.error("Failed to pull"); return false; } + } hgBundle.delete(); // do not leave it in workspace @@ -310,8 +326,11 @@ ArgumentListBuilder args = new ArgumentListBuilder(); args.add(getDescriptor().getHgExe(),"clone"); - if(branch!=null) args.add("-r",branch); - args.add(source,workspace.getRemote()); + if(branch!=null) { + args.add(source + "#" + branch,workspace.getRemote()); + } else { + args.add(source,workspace.getRemote()); + } try { if(launcher.launch(args.toCommandArray(),build.getEnvVars(),listener.getLogger(),null).join()!=0) { listener.error("Failed to clone "+source); @@ -354,6 +373,7 @@ load(); } + @Override public String getDisplayName() { return "Mercurial"; } @@ -362,7 +382,9 @@ * Path to mercurial executable. */ public String getHgExe() { - if(hgExe==null) return "hg"; + if(hgExe==null) { + return "hg"; + } return hgExe; }