# HG changeset patch # User Andreas Eisele # Date 1717680462 -7200 # Node ID 17b119b3cb9a10caa3bb31e52493a1c316c9169f # Parent e6e3f80c9313f23389d644a8ca7faab2c4821009# Parent cb5e6f9a2bcd450e660c89305b190f5ed272e0d6 TW-88158: remove MercurialCommitsInfoBuilderSupport and CommitsAndMountPointsCommand together with the custom hg extension. - The extension point was introduced for Upsource and is no longer needed. - The hg extension was not compatible with python 3 and led to test errors. diff -r e6e3f80c9313 -r 17b119b3cb9a mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java Wed Oct 18 09:44:31 2023 +0200 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java Thu Jun 06 15:27:42 2024 +0200 @@ -80,11 +80,6 @@ return new LogCommand(myCommandSettingsFactory.create(), myHgPath, myWorkingDir, myAuthSettings); } - @NotNull - public CommitsAndMountPointsCommand logSubstates() throws VcsException { - return new CommitsAndMountPointsCommand(this, myCommandSettingsFactory.create(), myHgPath, myWorkingDir, myAuthSettings); - } - public UpdateCommand update() { return new UpdateCommand(myCommandSettingsFactory.create(), myHgPath, myWorkingDir, myAuthSettings); } diff -r e6e3f80c9313 -r 17b119b3cb9a mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsCommand.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsCommand.java Wed Oct 18 09:44:31 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,122 +0,0 @@ -/* - * Copyright 2000-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jetbrains.buildServer.buildTriggers.vcs.mercurial.command; - -import jetbrains.buildServer.buildTriggers.vcs.mercurial.HgFileUtil; -import jetbrains.buildServer.buildTriggers.vcs.mercurial.HgRepo; -import jetbrains.buildServer.buildTriggers.vcs.mercurial.HgVersion; -import jetbrains.buildServer.util.FileUtil; -import jetbrains.buildServer.vcs.VcsException; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.io.IOException; -import java.util.Date; - -import static jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommitsAndMountPointsParser.parseCommits; -import static jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommitsAndMountPointsParser.parseFileLog; - -/** - * Created 03.01.14 14:53 - * - * @author Eugene Petrenko (eugene.petrenko@jetbrains.com) - */ -public class CommitsAndMountPointsCommand extends VcsRootCommand { - private static final HgVersion REQUIRED_VERSION = new HgVersion(2, 0, 0); - private static final HgVersion VERSION_4_6 = new HgVersion(4, 6, 0); - private final HgRepo myRepo; - - public CommitsAndMountPointsCommand(@NotNull final HgRepo hgRepo, - @NotNull final CommandSettings commandSettings, - @NotNull final String hgPath, - @NotNull final File workingDir, - @NotNull final AuthSettings authSettings) { - super(commandSettings.addHgEnv("HGENCODING", "UTF-8"), hgPath, workingDir, authSettings); - myRepo = hgRepo; - } - - @NotNull - private File createTmpDir() throws VcsException { - try { - return HgFileUtil.createTempDir(); - } catch (IOException e) { - throw new VcsException("Unable to create temporary directory", e); - } - } - - public void call(@NotNull final Callback consumer) throws VcsException { - final HgVersion hgVersion = myRepo.version().call(); - if (!hgVersion.isEqualsOrGreaterThan(REQUIRED_VERSION)) { - throw new VcsException("Current mercurial version is " + hgVersion + ", please use " + REQUIRED_VERSION + " or newer"); - } - - final File root = createTmpDir(); - - try { - callImpl(hgVersion, root, consumer); - } finally { - FileUtil.delete(root); - } - } - - public interface Callback { - void processHGSubFile(@NotNull final String fileId, @NotNull final String file); - void processHGSubStateFile(@NotNull final String fileId, @NotNull final String file); - void onCommit( - @NotNull String commitNum, - @NotNull String commitId, - @NotNull String[] parents, - @NotNull String branch, - @NotNull String[] tags, - @NotNull String author, - @NotNull String message, - @NotNull final Date timestamp, - @Nullable String hgsubNodeId, - @Nullable String hgsubstateNodeId); - } - - private void callImpl(@NotNull final HgVersion hgVersion, - @NotNull final File root, - @NotNull final Callback consumer) throws VcsException { - final MercurialCommandLine cli = createCommandLine(); - cli.addParameter("--debug"); - - if (hgVersion.isEqualsOrGreaterThan(VERSION_4_6)) { - setupExtensionsFromResource(cli, root, "load-substates-command-46.py"); - } else { - setupExtensionsFromResource(cli, root, "load-substates-command.py"); - } - - cli.addParameter("load-substates"); - cli.addParameter(new File(root, "result").getPath()); - - final CommandResult res = runCommand(cli); - final String rawOutput = res.getRawStdout(); - - if (!rawOutput.contains("##Completed##")) throw new VcsException("Command failed: " + res.getSecureStdout()); - - try { - parseFileLog(new File(root, "result.hgsub"), consumer::processHGSubFile); - parseFileLog(new File(root, "result.hgsubstate"), consumer::processHGSubStateFile); - - parseCommits(new File(root, "result.commits"), consumer::onCommit); - } catch (IOException e) { - throw new VcsException("Failed to parse response files for 'load-substates' command. " + e.getMessage(), e); - } - } -} diff -r e6e3f80c9313 -r 17b119b3cb9a mercurial-common/src/python/load-substates-command-46.py --- a/mercurial-common/src/python/load-substates-command-46.py Wed Oct 18 09:44:31 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,154 +0,0 @@ -#!/usr/bin/env python -## -## Copyright 2000-2014 JetBrains -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -## -## http://www.gnu.org/licenses/gpl-faq.html#GPLModuleLicense -## http://www.gnu.org/licenses/license-list.html#apache2 -## http://en.wikipedia.org/wiki/Apache_License#GPL_compatibility -## -## -""" -load-substates-command -""" - -import base64 -from mercurial import util, node -from mercurial.utils import dateutil -from threading import Thread - - -def load_substates_command(ui, repo, outputFile, **opts): - """Tons of docs""" - - ui.write("Fetching commits...") - - NONE = "=====" - - def b64(x): - if x is None or x == "": - return NONE - return base64.b64encode( x ) - - def fetch_commits(): - ui.write("Iterating over commits...\n") - with open(outputFile + ".commits", "w", 5 * 1024 * 1024) as result: - result.write("format: prefix commitID commitHash num_parents parent branch num_tags tag user message date [.hgsub] [.hgsubstate]\n") - result.flush() - - commit_to_substates = {} - - def update_sub_states(ctx): - def filenode(ctx, filename, i): - if filename in ctx.files(): - try: - return node.hex(ctx.filenode(filename)) - except: - # file could have been deleted => so there would be no filenode for it - # this also means we should avoid parents as file source - return NONE - else: - for p in ctx.parents(): - if commit_to_substates.has_key(p.hex()): - v = commit_to_substates[p.hex()][i] - if v != NONE: - return v - return NONE - - best_sub = filenode(ctx, ".hgsub", 0) - best_state = filenode(ctx, ".hgsubstate", 1) - commit_to_substates[ctx.hex()] = (best_sub, best_state) - return best_sub, best_state - - for r in list(repo.changelog): - ctx = repo[r] - - result.write("$$@@@@ ") # magic - result.write( str( ctx.rev() ) ) # commit Num - result.write(" ") - result.write( ctx.hex() ) # commit ID - result.write(" ") - result.write( str( len( ctx.parents()) ) ) # num parents - - for p in ctx.parents(): # parents - result.write(" ") - result.write(p.hex()) - - result.write(" ") - result.write( b64( ctx.branch() ) ) # commit branch - - result.write(" ") - result.write( str( len( ctx.tags() ) ) ) # num tags - - for tag in ctx.tags(): # tags - result.write(" ") - result.write( b64 ( tag ) ) - - result.write(" ") # user - result.write( b64( ctx.user() ) ) - - result.write(" ") # message - result.write( b64( ctx.description() ) ) - - result.write(" ") # date - result.write( dateutil.datestr( ctx.date(), "%Y-%m-%dZ%H:%M:%ST%1%2") ) - - #resolve sub-repo mounts - (sub_node, state_node) = update_sub_states(ctx) - result.write(" " + sub_node + " " + state_node) - result.write("\n") - - ui.write("Commits iteration completed") - - def fetch_file_revisions(filename): - ui.write("Fetching revisions of " + filename + " file\n") - with open(outputFile + filename, "w", 5 * 1024 * 1024) as result: - result.write("format: prefix commitID base64(" + filename + ")\n") - result.flush() - - log = repo.file(filename) - for r in log: - result.write("$$@@@@ " + node.hex(log.node(r)) + " " + b64(log.read(r)) + "\n") - - ui.write("All revisions of file " + filename + " are fetched\n") - - tasks = [ - Thread(target=fetch_commits, args=[], name="Fetch commits graph"), - Thread(target=fetch_file_revisions, args=[".hgsub"], name="Fetch .hgsub"), - Thread(target=fetch_file_revisions, args=[".hgsubstate"], name="Fetch .hgsubstate"), - ] - - for task in tasks: - task.start() - - for task in tasks: - task.join() - - ui.write("\n##Completed##\n") - - -#so here goes command registration and options -cmdtable = { - b"load-substates": (load_substates_command, [ ], b" [options] OUTPUT_FILE") -} - -load_substates_command.norepo = False -load_substates_command.optionalrepo = False -load_substates_command.inferrepo = False -load_substates_command.intents = None - -testedwith = '5.6.1' -buglink = "upsource-support@jetbrains.com" - diff -r e6e3f80c9313 -r 17b119b3cb9a mercurial-common/src/python/load-substates-command.py --- a/mercurial-common/src/python/load-substates-command.py Wed Oct 18 09:44:31 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,152 +0,0 @@ -#!/usr/bin/env python -## -## Copyright 2000-2014 JetBrains -## -## Licensed under the Apache License, Version 2.0 (the "License"); -## you may not use this file except in compliance with the License. -## You may obtain a copy of the License at -## -## http://www.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## -## -## http://www.gnu.org/licenses/gpl-faq.html#GPLModuleLicense -## http://www.gnu.org/licenses/license-list.html#apache2 -## http://en.wikipedia.org/wiki/Apache_License#GPL_compatibility -## -## -""" -load-substates-command -""" - -import base64 -from mercurial import util, node -from threading import Thread - - -def load_substates_command(ui, repo, outputFile, **opts): - """Tons of docs""" - - ui.write("Fetching commits...") - - NONE = "=====" - - def b64(x): - if x is None or x == "": - return NONE - return base64.b64encode( x ) - - def fetch_commits(): - ui.write("Iterating over commits...\n") - with open(outputFile + ".commits", "w", 5 * 1024 * 1024) as result: - result.write("format: prefix commitID commitHash num_parents parent branch num_tags tag user message date [.hgsub] [.hgsubstate]\n") - result.flush() - - commit_to_substates = {} - - def update_sub_states(ctx): - def filenode(ctx, filename, i): - if filename in ctx.files(): - try: - return node.hex(ctx.filenode(filename)) - except: - # file could have been deleted => so there would be no filenode for it - # this also means we should avoid parents as file source - return NONE - else: - for p in ctx.parents(): - if commit_to_substates.has_key(p.hex()): - v = commit_to_substates[p.hex()][i] - if v != NONE: - return v - return NONE - - best_sub = filenode(ctx, ".hgsub", 0) - best_state = filenode(ctx, ".hgsubstate", 1) - commit_to_substates[ctx.hex()] = (best_sub, best_state) - return best_sub, best_state - - for r in list(repo.changelog): - ctx = repo[r] - - result.write("$$@@@@ ") # magic - result.write( str( ctx.rev() ) ) # commit Num - result.write(" ") - result.write( ctx.hex() ) # commit ID - result.write(" ") - result.write( str( len( ctx.parents()) ) ) # num parents - - for p in ctx.parents(): # parents - result.write(" ") - result.write(p.hex()) - - result.write(" ") - result.write( b64( ctx.branch() ) ) # commit branch - - result.write(" ") - result.write( str( len( ctx.tags() ) ) ) # num tags - - for tag in ctx.tags(): # tags - result.write(" ") - result.write( b64 ( tag ) ) - - result.write(" ") # user - result.write( b64( ctx.user() ) ) - - result.write(" ") # message - result.write( b64( ctx.description() ) ) - - result.write(" ") # date - result.write( util.datestr( ctx.date(), "%Y-%m-%dZ%H:%M:%ST%1%2") ) - - #resolve sub-repo mounts - (sub_node, state_node) = update_sub_states(ctx) - result.write(" " + sub_node + " " + state_node) - result.write("\n") - - ui.write("Commits iteration completed") - - def fetch_file_revisions(filename): - ui.write("Fetching revisions of " + filename + " file\n") - with open(outputFile + filename, "w", 5 * 1024 * 1024) as result: - result.write("format: prefix commitID base64(" + filename + ")\n") - result.flush() - - log = repo.file(filename) - for r in log: - result.write("$$@@@@ " + node.hex(log.node(r)) + " " + b64(log.read(r)) + "\n") - - ui.write("All revisions of file " + filename + " are fetched\n") - - tasks = [ - Thread(target=fetch_commits, args=[], name="Fetch commits graph"), - Thread(target=fetch_file_revisions, args=[".hgsub"], name="Fetch .hgsub"), - Thread(target=fetch_file_revisions, args=[".hgsubstate"], name="Fetch .hgsubstate"), - ] - - for task in tasks: - task.start() - - for task in tasks: - task.join() - - ui.write("\n##Completed##\n") - - -#so here goes command registration and options -cmdtable = { - b"load-substates": (load_substates_command, [ ], b" [options] OUTPUT_FILE") -} - -load_substates_command.norepo = False -load_substates_command.optionalrepo = False -load_substates_command.inferrepo = False - -testedwith = '4.2.1' -buglink = "upsource-support@jetbrains.com" - diff -r e6e3f80c9313 -r 17b119b3cb9a mercurial-server/src/META-INF/build-server-plugin-mercurial.xml --- a/mercurial-server/src/META-INF/build-server-plugin-mercurial.xml Wed Oct 18 09:44:31 2023 +0200 +++ b/mercurial-server/src/META-INF/build-server-plugin-mercurial.xml Thu Jun 06 15:27:42 2024 +0200 @@ -30,8 +30,6 @@ - - diff -r e6e3f80c9313 -r 17b119b3cb9a mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitsInfoBuilderStates.java --- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitsInfoBuilderStates.java Wed Oct 18 09:44:31 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright 2000-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jetbrains.buildServer.buildTriggers.vcs.mercurial; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -/** - * Created 13.01.14 19:45 - * - * @author Eugene Petrenko (eugene.petrenko@jetbrains.com) - */ -public class MercurialCommitsInfoBuilderStates { - private final Map myHgStateNodes = new HashMap<>(); - private final Map myHgSubNodes = new HashMap<>(); - - public void addSubNode(@NotNull final String hash, @NotNull final String text) { - myHgSubNodes.put(hash, text); - } - - public void addStateNode(@NotNull final String hash, @NotNull final String text) { - myHgStateNodes.put(hash, text); - } - - - @NotNull - public Map mounts(@Nullable final String subHash, - @Nullable final String stateHash) { - if (subHash == null || stateHash == null) return Collections.emptyMap(); - - //TODO: may cache parsed contents to make it work faster - return HgSubs.readSubrepositories( - myHgSubNodes.get(subHash), - myHgStateNodes.get(stateHash)); - } -} diff -r e6e3f80c9313 -r 17b119b3cb9a mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitsInfoBuilderSupport.java --- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitsInfoBuilderSupport.java Wed Oct 18 09:44:31 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -/* - * Copyright 2000-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jetbrains.buildServer.buildTriggers.vcs.mercurial; - -import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommitsAndMountPointsCommand; -import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot; -import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.LogCommand; -import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.exception.WrongSubrepoUrlException; -import jetbrains.buildServer.dataStructures.MultiMapToList; -import jetbrains.buildServer.vcs.*; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Date; -import java.util.Map; - -/** - * Created 30.09.13 13:05 - * - * @author Eugene Petrenko (eugene.petrenko@jetbrains.com) - */ -public class MercurialCommitsInfoBuilderSupport implements CommitsInfoBuilder, MercurialServerExtension { - private final MercurialVcsSupport mySupport; - private final HgVcsRootFactory myHgVcsRootFactory; - - public MercurialCommitsInfoBuilderSupport(@NotNull MercurialVcsSupport vcs, - @NotNull HgVcsRootFactory vcsRootFactory) { - vcs.addExtension(this); - mySupport = vcs; - myHgVcsRootFactory = vcsRootFactory; - } - - @NotNull - private static MultiMapToList commitToBranchs(@NotNull final Map branchToCommit) { - final MultiMapToList map = new MultiMapToList<>(); - for (Map.Entry e : branchToCommit.entrySet()) { - map.add(e.getValue(), e.getKey()); - } - return map; - } - - public void collectCommits(@NotNull final VcsRoot root, - @NotNull final CheckoutRules rules, - @NotNull final CommitsConsumer consumer) throws VcsException { - - final HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root); - final ServerHgRepo repo = mySupport.createRepo(hgRoot); - VcsCallable> cmd = () -> commitToBranchs(mySupport.getCollectChangesPolicy().getHeads(hgRoot)); - final MultiMapToList heads = mySupport.syncRepository(hgRoot, new SyncSettings<>(cmd)); - repo.logSubstates().call(new CommitsAndMountPointsCommand.Callback() { - private final MercurialCommitsInfoBuilderStates subs = new MercurialCommitsInfoBuilderStates(); - - public void processHGSubFile(@NotNull String fileId, @NotNull String text) { - subs.addSubNode(fileId, text); - } - - public void processHGSubStateFile(@NotNull String fileId, @NotNull String text) { - subs.addStateNode(fileId, text); - } - - public void onCommit(@NotNull String commitNum, - @NotNull String commitId, - @NotNull String[] parents, - @NotNull String branch, - @NotNull String[] tags, - @NotNull String author, - @NotNull String message, - @NotNull Date timestamp, - @Nullable String hgsubNodeId, - @Nullable String hgsubstateNodeId) { - - final CommitDataBean bean = new CommitDataBean( - HgRepo.shortId(commitId), - HgRepo.shortId(commitId), - timestamp - ); - - for (String parent : parents) { - if (LogCommand.ZERO_PARENT_ID.equals(parent)) continue; - if (LogCommand.ZERO_PARENT_SHORT_ID.equals(parent)) continue; - bean.addParentRevision(HgRepo.shortId(parent)); - } - - for (String tag : tags) { - if ("tip".equals(tag)) continue; - - bean.addTag(tag); - } - - bean.addBranch(branch); - bean.setCommitAuthor(author); - bean.setCommitMessage(message); - - for (SubRepo subRepo : subs.mounts(hgsubNodeId, hgsubstateNodeId).values()) { - try { - bean.addMountPoint(new CommitMountPointDataBean( - subRepo.vcsType().getVcsPluginName(), - subRepo.resolveUrl(hgRoot.getRepository()), - subRepo.path(), - subRepo.revision() - )); - } catch (WrongSubrepoUrlException e) { - //NOP - } - } - - bean.setHeads(heads.getValues(bean.getVersion())); - - consumer.consumeCommit(bean); - } - }); - } - -} diff -r e6e3f80c9313 -r 17b119b3cb9a mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CommitsInfoBuilderSupportTest.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/CommitsInfoBuilderSupportTest.java Wed Oct 18 09:44:31 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,161 +0,0 @@ -/* - * Copyright 2000-2018 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jetbrains.buildServer.buildTriggers.vcs.mercurial; - -import jetbrains.buildServer.TestLogger; -import jetbrains.buildServer.vcs.*; -import jetbrains.vcs.api.CommitInfo; -import org.jetbrains.annotations.NotNull; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.io.File; -import java.io.IOException; -import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; - -import static jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialSupportBuilder.mercurialSupport; -import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; -import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot; - -/** - * Created 30.09.13 13:07 - * - * @author Eugene Petrenko (eugene.petrenko@jetbrains.com) - */ -@RequiredHgVersion(min = "2.0.0") //support subrepos only for hg with revsets -@Test(dataProviderClass = HgVersionConstraint.class, dataProvider = "installedHgVersion") -public class CommitsInfoBuilderSupportTest extends BaseMercurialTestCase { - private File myRemoteRepo; - private MercurialVcsSupport myVcs; - private MercurialCommitsInfoBuilderSupport mySupport; - private TestLogger myTestLogger; - - - @Override - @BeforeMethod - public void setUp() throws Exception { - super.setUp(); - myTestLogger = new TestLogger(); - ServerPluginConfig pluginConfig = new ServerPluginConfigBuilder() -// .hgPath("hg") - .cachesDir(myTempFiles.createTempDir()) - .build(); - MercurialSupportBuilder mercurialBuilder = mercurialSupport().withConfig(pluginConfig); - myVcs = mercurialBuilder.build(); - mySupport = new MercurialCommitsInfoBuilderSupport(myVcs, mercurialBuilder.getHgRootFactory()); - myRemoteRepo = myTempFiles.createTempDir(); - copyRepository(new File("mercurial-tests/testData/rep2"), myRemoteRepo); - } - - @Override - @AfterMethod - public void tearDown() { - super.tearDown(); - myTestLogger.disableDebug(); - } - - public void simpleTest(@NotNull HgVersion version) throws IOException, VcsException { - myTestLogger.enableDebug(); - - VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build(); - - - final List commitInfos = new ArrayList<>(); - mySupport.collectCommits(root, CheckoutRules.DEFAULT, commitInfos::add); - Assert.assertFalse(commitInfos.isEmpty()); - - for (CommitInfo commitInfo : commitInfos) { - System.out.println(commitInfo); - } - - final Set branches = new TreeSet<>(); - final Set tags = new TreeSet<>(); - final Set commits = new TreeSet<>(); - final Set parents = new TreeSet<>(); - for (CommitInfo commitInfo : commitInfos) { - branches.addAll(commitInfo.getBranches()); - tags.addAll(commitInfo.getTags()); - - //commit should be returned once - Assert.assertTrue(commits.add(commitInfo.getVersion())); - Assert.assertNotNull(commitInfo.getCommitAuthor()); - parents.addAll(commitInfo.getParentRevisions()); - } - - Assert.assertEquals(branches, new TreeSet<>(Arrays.asList("default", "personal-branch", "test", "topic", " Branch with exitics)(*&^%$#@!", "NULL"))); - Assert.assertEquals(tags, new TreeSet<>(Arrays.asList("t1"))); - - //check all parent commits are included into the set - Assert.assertTrue(commits.containsAll(parents), "Unknown commits: " + new TreeSet(parents){{removeAll(commits);}}); - - final String v = "4780519e01aa"; ///30 - Assert.assertFalse(parents.contains(v)); - } - - public void should_not_have_parse_errors(@NotNull HgVersion version) throws IOException, VcsException { - myTestLogger.enableDebug(); - - VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build(); - - final List commitInfos = new ArrayList<>(); - mySupport.collectCommits(root, CheckoutRules.DEFAULT, commitInfos::add); - Assert.assertFalse(commitInfos.isEmpty()); - - for (CommitInfo commitInfo : commitInfos) { - System.out.println(commitInfo); - } - } - - private void should_return_subrepos_graphcommits(@NotNull HgVersion version) throws Exception { - myRemoteRepo = myTempFiles.createTempDir(); - copyRepository(new File("mercurial-tests/testData/subrepos/r1"), myRemoteRepo); - - VcsRoot root = vcsRoot().withUrl(myRemoteRepo).build(); - - final AtomicBoolean hasSubRepo = new AtomicBoolean(false); - final long start = System.currentTimeMillis(); - mySupport.collectCommits(root, CheckoutRules.DEFAULT, commit -> { - if (commit.getMountPoints().size() > 0) hasSubRepo.set(true); - }); - - final long actual = System.currentTimeMillis() - start; - System.out.println("computed in " + actual + " ms"); - - Assert.assertTrue(hasSubRepo.get(), "Must have sub-repos"); - } - - @Test(enabled = false) - public void should_return_graphcommits(@NotNull HgVersion version) throws Exception { - VcsRoot root = vcsRoot().withLocalRepository(new File("F:\\Work\\ReSharper")).build(); - - final AtomicBoolean hasSubRepo = new AtomicBoolean(false); - final long start = System.currentTimeMillis(); - mySupport.collectCommits(root, CheckoutRules.DEFAULT, commit -> { - if (commit.getMountPoints().size() > 0) hasSubRepo.set(true); - }); - - final long actual = System.currentTimeMillis() - start; - System.out.println("computed in " + actual + " ms"); - - Assert.assertTrue(hasSubRepo.get(), "Must have sub-repos"); - } - - -} diff -r e6e3f80c9313 -r 17b119b3cb9a mercurial-tests/src/testng-via-cmd.xml --- a/mercurial-tests/src/testng-via-cmd.xml Wed Oct 18 09:44:31 2023 +0200 +++ b/mercurial-tests/src/testng-via-cmd.xml Thu Jun 06 15:27:42 2024 +0200 @@ -37,7 +37,6 @@ - diff -r e6e3f80c9313 -r 17b119b3cb9a mercurial-tests/src/testng.xml --- a/mercurial-tests/src/testng.xml Wed Oct 18 09:44:31 2023 +0200 +++ b/mercurial-tests/src/testng.xml Thu Jun 06 15:27:42 2024 +0200 @@ -51,7 +51,6 @@ -