diff -r c15b9555ecf3 -r c112fad21bf6 src/main/kotlin/de/uapcore/lightpit/vcs/HgConnector.kt --- a/src/main/kotlin/de/uapcore/lightpit/vcs/HgConnector.kt Sat Jul 22 11:32:27 2023 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * Copyright 2023 Mike Becker. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -package de.uapcore.lightpit.vcs - -import java.nio.file.Files -import kotlin.io.path.ExperimentalPathApi -import kotlin.io.path.deleteRecursively - -/** - * A connector for Mercurial repositories. - * - * @param path the path to the Mercurial binary - */ -class HgConnector(path: String) : VcsConnector(path) { - - /** - * Checks, if the specified binary is available and executable. - */ - fun checkAvailability(): Boolean { - return when (val versionInfo = invokeCommand("--version")) { - is VcsConnectorResult.Success -> versionInfo.content.contains("Mercurial") - else -> false - } - } - - /** - * Reads the commit log and parses every reference to an issue. - * - * The [pathOrUrl] must be a valid path or URL recognized by the VCS binary. - * Currently, no authentication is supported and the repository must therefore be publicly readable. - */ - @OptIn(ExperimentalPathApi::class) - fun readCommitLog(pathOrUrl: String): VcsConnectorResult> { - val tmpDir = try { - Files.createTempDirectory("lightpit-vcs-") - } catch (e: Throwable) { - return VcsConnectorResult.Error("Creating temporary directory for VCS connection failed: " + e.message) - } - val init = invokeCommand("init", workingDir = tmpDir) - if (init is VcsConnectorResult.Error) { - return init - } - - val commitLogContent = when (val result = invokeCommand( - "incoming", pathOrUrl, "-n", "--template", "::lpitref::{node}:{desc}\\n", - workingDir = tmpDir, - timeout = 60 - )) { - is VcsConnectorResult.Error -> return result - is VcsConnectorResult.Success -> result.content - } - - val commitRefs = parseCommitRefs(commitLogContent) - - tmpDir.deleteRecursively() - return VcsConnectorResult.Success(commitRefs) - } -} \ No newline at end of file