Skip to content

Commit 416efef

Browse files
committed
JENKINS-5347 Fixed - Added use commit times on files
1 parent ab3a078 commit 416efef

4 files changed

Lines changed: 77 additions & 3 deletions

File tree

src/main/java/hudson/scm/SubversionSCM.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ public class SubversionSCM extends SCM implements Serializable {
244244

245245
private boolean ignoreDirPropChanges;
246246
private boolean filterChangelog;
247+
private boolean useCommitTimes;
247248

248249
/**
249250
* A cache of the svn:externals (keyed by project).
@@ -334,15 +335,22 @@ public SubversionSCM(List<ModuleLocation> locations, WorkspaceUpdater workspaceU
334335
public SubversionSCM(List<ModuleLocation> locations, WorkspaceUpdater workspaceUpdater,
335336
SubversionRepositoryBrowser browser, String excludedRegions, String excludedUsers, String excludedRevprop, String excludedCommitMessages,
336337
String includedRegions, boolean ignoreDirPropChanges) {
337-
this(locations, workspaceUpdater, browser, excludedRegions, excludedUsers, excludedRevprop, excludedCommitMessages, includedRegions, ignoreDirPropChanges, false, null);
338+
this(locations, workspaceUpdater, browser, excludedRegions, excludedUsers, excludedRevprop, excludedCommitMessages, includedRegions, ignoreDirPropChanges, false, null, false);
339+
}
340+
341+
public SubversionSCM(List<ModuleLocation> locations, WorkspaceUpdater workspaceUpdater,
342+
SubversionRepositoryBrowser browser, String excludedRegions, String excludedUsers, String excludedRevprop, String excludedCommitMessages,
343+
String includedRegions, boolean ignoreDirPropChanges, boolean useCommitTimes) {
344+
this(locations, workspaceUpdater, browser, excludedRegions, excludedUsers, excludedRevprop, excludedCommitMessages, includedRegions, ignoreDirPropChanges, false, null, useCommitTimes);
338345
}
339346

340347
@DataBoundConstructor
341348
public SubversionSCM(List<ModuleLocation> locations, WorkspaceUpdater workspaceUpdater,
342349
SubversionRepositoryBrowser browser, String excludedRegions, String excludedUsers,
343350
String excludedRevprop, String excludedCommitMessages,
344351
String includedRegions, boolean ignoreDirPropChanges, boolean filterChangelog,
345-
List<AdditionalCredentials> additionalCredentials) {
352+
List<AdditionalCredentials> additionalCredentials, boolean useCommitTimes) {
353+
this.useCommitTimes = useCommitTimes;
346354
for (Iterator<ModuleLocation> itr = locations.iterator(); itr.hasNext(); ) {
347355
ModuleLocation ml = itr.next();
348356
String remote = Util.fixEmptyAndTrim(ml.remote);
@@ -664,6 +672,11 @@ public boolean isIgnoreDirPropChanges() {
664672
public boolean isFilterChangelog() {
665673
return filterChangelog;
666674
}
675+
676+
@Exported
677+
public boolean isUsingCommitTimes() {
678+
return useCommitTimes;
679+
}
667680

668681
/**
669682
* Sets the <tt>SVN_REVISION_n</tt> and <tt>SVN_URL_n</tt> environment variables during the build.
@@ -947,6 +960,7 @@ private synchronized Map<Job, List<External>> getProjectExternalsCache() {
947960
*/
948961
private static class CheckOutTask extends UpdateTask implements FileCallable<List<External>> {
949962
private final UpdateTask task;
963+
private final boolean isUsingCommitTimes;
950964

951965
public CheckOutTask(Run<?, ?> build, SubversionSCM parent, ModuleLocation location, Date timestamp, TaskListener listener, EnvVars env) {
952966
this.authProvider = parent.createAuthenticationProvider(build.getParent(), location);
@@ -955,6 +969,7 @@ public CheckOutTask(Run<?, ?> build, SubversionSCM parent, ModuleLocation locati
955969
this.location = location;
956970
this.revisions = build.getAction(RevisionParameterAction.class);
957971
this.task = parent.getWorkspaceUpdater().createTask();
972+
this.isUsingCommitTimes = parent.isUsingCommitTimes();
958973
}
959974

960975
public Set<String> getUnauthenticatedRealms() {
@@ -966,6 +981,11 @@ public Set<String> getUnauthenticatedRealms() {
966981

967982
public List<External> invoke(File ws, VirtualChannel channel) throws IOException {
968983
clientManager = createClientManager(authProvider);
984+
DefaultSVNOptions defaultSVNOptions = createDefaultSVNOptions();
985+
if (isUsingCommitTimes) {
986+
defaultSVNOptions.setUseCommitTimes(isUsingCommitTimes);
987+
}
988+
clientManager = new SvnClientManager(SVNClientManager.newInstance(defaultSVNOptions, createSvnAuthenticationManager(authProvider)));
969989
manager = clientManager.getCore();
970990
this.ws = ws;
971991
try {

src/main/resources/hudson/scm/SubversionSCM/config.jelly

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,8 @@ THE SOFTWARE.
5656
<f:entry title="${%Filter changelog}" field="filterChangelog">
5757
<f:checkbox />
5858
</f:entry>
59+
<f:entry title="${%Set check out file dates to the 'last commit time'}" field="usingCommitTimes">
60+
<f:checkbox />
61+
</f:entry>
5962
</f:advanced>
6063
</j:jelly>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div>
2+
<p>If set Jenkins will set the file timestamps to the last commit time (of each file) when doing a checkout or an update. Otherwise Jenkins will set the current date as the timestamp of each file.</p>
3+
<p>
4+
Normally the working copy files have timestamps that reflect the last time they were touched by any process. This is generally convenient for most build systems as they look at timestamps as a way of deciding which files need to be recompiled.
5+
In other situations, however, it's sometimes nice for the working copy files to have timestamps that reflect the last time they were changed in the repository. The svn export command always places these 'last-commit timestamps' on trees that it produces.
6+
See <a href="http://svnbook.red-bean.com/en/1.7/svn-book.html#svn.advanced.confarea.opts.config">SVN Red Book</a> for more information.
7+
</p>
8+
</div>

src/test/java/hudson/scm/SubversionSCMTest.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474

7575
import static hudson.scm.SubversionSCM.compareSVNAuthentications;
7676
import static org.jvnet.hudson.test.recipes.PresetData.DataSet.ANONYMOUS_READONLY;
77+
import static org.hamcrest.Matchers.is;
78+
import static org.hamcrest.Matchers.not;
79+
import static org.junit.Assert.assertThat;
7780

7881
/**
7982
* @author Kohsuke Kawaguchi
@@ -885,7 +888,7 @@ private void verifyChangelogFilter(boolean shouldFilterLog) throws Exception,
885888
File repo = new CopyExisting(getClass().getResource("JENKINS-10449.zip")).allocate();
886889
SubversionSCM scm = new SubversionSCM(ModuleLocation.parse(new String[]{"file://" + repo.toURI().toURL().getPath()},
887890
new String[]{"."},null,null),
888-
new UpdateUpdater(), null, "/z.*", "", "", "", "", false, shouldFilterLog, null);
891+
new UpdateUpdater(), null, "/z.*", "", "", "", "", false, shouldFilterLog, null, false);
889892

890893
FreeStyleProject p = createFreeStyleProject(String.format("testFilterChangelog-%s", shouldFilterLog));
891894
p.setScm(scm);
@@ -1706,4 +1709,44 @@ private void invokeTestPollingExternalsForFile() throws Exception {
17061709
// should detect change
17071710
assertTrue(p.poll(StreamTaskListener.fromStdout()).hasChanges());
17081711
}
1712+
1713+
/**
1714+
* Test related to https://issues.jenkins-ci.org/browse/JENKINS-5347
1715+
*
1716+
* @throws Throwable
1717+
*/
1718+
public void testUseCommitTimes() throws Throwable {
1719+
// Given a subversion workspace where the commit times should be used
1720+
// When the workspace is checked out
1721+
// Then verify that the last modified time stamp of the format file is 2010-12-31
1722+
1723+
FreeStyleProject p = createFreeStyleProject();
1724+
File repo = new CopyExisting(getClass().getResource("small.zip")).allocate();
1725+
SubversionSCM scm = new SubversionSCM(ModuleLocation.parse(new String[]{"file://" + repo.toURI().toURL().getPath()},
1726+
new String[]{"."}, null, null), new UpdateUpdater(), null, "/z.*", "", "", "", "", false, false, null, true);
1727+
p.setScm(scm);
1728+
FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0, new Cause.UserIdCause()).get());
1729+
// Using long matching to prevent Timezone issues, divided by 1000 as some OS does not return the exact milliseconds
1730+
assertThat(b.getWorkspace().child("b").lastModified() / 1000, is(1293845528l));
1731+
}
1732+
1733+
/**
1734+
* Test related to https://issues.jenkins-ci.org/browse/JENKINS-5347
1735+
*
1736+
* @throws Throwable
1737+
*/
1738+
public void testNotUseCommitTimes() throws Throwable {
1739+
// Given a subversion workspace where the commit times should NOT be used
1740+
// When the workspace is checked out
1741+
// Then verify that the last modified time stamp of the format file NOT is 2011-01-01
1742+
1743+
FreeStyleProject p = createFreeStyleProject();
1744+
File repo = new CopyExisting(getClass().getResource("small.zip")).allocate();
1745+
SubversionSCM scm = new SubversionSCM(ModuleLocation.parse(new String[]{"file://" + repo.toURI().toURL().getPath()},
1746+
new String[]{"."}, null, null), new UpdateUpdater(), null, "/z.*", "", "", "", "", false, false, null, false);
1747+
p.setScm(scm);
1748+
FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0, new Cause.UserIdCause()).get());
1749+
// Using long matching to prevent Timezone issues, divided by 1000 as some OS does not return the exact milliseconds
1750+
assertThat(b.getWorkspace().child("b").lastModified() / 1000, not(is(1293845528l)));
1751+
}
17091752
}

0 commit comments

Comments
 (0)