Skip to content

Commit

Permalink
Add option to disable changelog calculation
Browse files Browse the repository at this point in the history
In some very very large repositories, the changelog calculation can take
quite a bit of time.  For users that do not care about seeing the
changelog in Jenkins, this allows disabling the calculation, thus
speeding up builds.

JENKINS-16654
  • Loading branch information
blt04 committed Feb 13, 2014
1 parent 03c6acd commit b9d53cb
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/main/java/hudson/plugins/mercurial/MercurialSCM.java
Expand Up @@ -110,6 +110,8 @@ public enum RevisionType {

private final String credentialsId;

private final boolean disableChangeLog;

@Deprecated
public MercurialSCM(String installation, String source, String branch, String modules, String subdir, HgBrowser browser, boolean clean) {
this(installation, source, branch, modules, subdir, browser, clean, null);
Expand All @@ -120,7 +122,12 @@ public MercurialSCM(String installation, String source, String branch, String mo
this(installation, source, RevisionType.BRANCH, branch, modules, subdir, browser, clean, credentialsId);
}

@DataBoundConstructor public MercurialSCM(String installation, String source, @NonNull RevisionType revisionType, @NonNull String revision, String modules, String subdir, HgBrowser browser, boolean clean, String credentialsId) {
@Deprecated
public MercurialSCM(String installation, String source, @NonNull RevisionType revisionType, @NonNull String revision, String modules, String subdir, HgBrowser browser, boolean clean, String credentialsId) {
this(installation, source, revisionType, revision, modules, subdir, browser, clean, credentialsId, false);
}

@DataBoundConstructor public MercurialSCM(String installation, String source, @NonNull RevisionType revisionType, @NonNull String revision, String modules, String subdir, HgBrowser browser, boolean clean, String credentialsId, boolean disableChangeLog) {
this.installation = installation;
this.source = Util.fixEmptyAndTrim(source);
this.modules = Util.fixNull(modules);
Expand All @@ -131,6 +138,7 @@ public MercurialSCM(String installation, String source, String branch, String mo
this.revision = Util.fixEmpty(revision) == null ? (revisionType == RevisionType.BRANCH ? "default" : "???") : revision;
this.browser = browser;
this.credentialsId = credentialsId;
this.disableChangeLog = disableChangeLog;
}

private void parseModules() {
Expand Down Expand Up @@ -183,6 +191,10 @@ public String getCredentialsId() {
return credentialsId;
}

public boolean isDisableChangeLog() {
return disableChangeLog;
}

@CheckForNull StandardUsernameCredentials getCredentials(AbstractProject<?,?> owner) {
if (credentialsId != null) {
for (StandardUsernameCredentials c : availableCredentials(owner, source)) {
Expand Down Expand Up @@ -516,6 +528,11 @@ private boolean canReuseWorkspace(FilePath repo,
}

private void determineChanges(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, File changelogFile, FilePath repository, String revToBuild) throws IOException, InterruptedException {
if (isDisableChangeLog()) {
createEmptyChangeLog(changelogFile, listener, "changelog");
return;
}

AbstractBuild<?, ?> previousBuild = build.getPreviousBuild();
MercurialTagAction prevTag = previousBuild != null ? findTag(previousBuild) : null;
if (prevTag == null) {
Expand Down
Expand Up @@ -34,6 +34,9 @@
<f:entry field="subdir" title="${%Subdirectory}">
<f:textbox/>
</f:entry>
<f:entry field="disableChangeLog" title="${%Disable Changelog}">
<f:checkbox/>
</f:entry>
</f:advanced>

<t:listScmBrowsers name="mercurial.browser" />
Expand Down
@@ -0,0 +1,5 @@
<div>
When checked, Hudson will not calculate the Mercurial changelog for each build.
Disabling the changelog can decrease the amount of time needed to update a
very large repository.
</div>
53 changes: 53 additions & 0 deletions src/test/java/hudson/plugins/mercurial/DisableChangeLogTest.java
@@ -0,0 +1,53 @@
package hudson.plugins.mercurial;

import hudson.model.AbstractBuild;
import hudson.model.FreeStyleProject;
import hudson.tools.ToolProperty;

import java.io.File;
import java.util.Collections;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import org.jvnet.hudson.test.JenkinsRule;

public class DisableChangeLogTest {
@Rule public JenkinsRule j = new JenkinsRule();
@Rule public MercurialRule m = new MercurialRule(j);
@Rule public TemporaryFolder tmp = new TemporaryFolder();
private File repo;

private static final String DISABLE_CHANGELOG_INSTALLATION = "changelog";

@Before public void setUp() throws Exception {
repo = tmp.getRoot();
j.jenkins
.getDescriptorByType(MercurialInstallation.DescriptorImpl.class)
.setInstallations(
new MercurialInstallation(DISABLE_CHANGELOG_INSTALLATION, "", "hg",
true, false, false, Collections
.<ToolProperty<?>> emptyList()));
}

protected String hgInstallation() {
return DISABLE_CHANGELOG_INSTALLATION;
}

@Test public void changelogIsDisabled() throws Exception {
AbstractBuild<?, ?> b;
FreeStyleProject p = j.createFreeStyleProject();
p.setScm(new MercurialSCM(hgInstallation(), repo.getPath(),
MercurialSCM.RevisionType.BRANCH, null, null,
null, null, false, null, true));
m.hg(repo, "init");
m.touchAndCommit(repo, "dir1/f1");
b = p.scheduleBuild2(0).get();
assertTrue(b.getChangeSet().isEmptySet());
m.touchAndCommit(repo, "dir2/f1");
b = p.scheduleBuild2(0).get();
assertTrue(b.getChangeSet().isEmptySet());
}
}

0 comments on commit b9d53cb

Please sign in to comment.