Mercurial > hg > mercurial
view mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerHgRepo.java @ 1109:e3fd42482b1b
fix TW-79815: retrieve the changed files with help of hg status command
author | pavel.sher |
---|---|
date | Mon, 10 Jul 2023 15:42:48 +0200 |
parents | 1168c4c64d49 |
children |
line wrap: on
line source
/* * 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 com.intellij.openapi.util.Pair; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.*; import jetbrains.buildServer.util.graph.DAG; import jetbrains.buildServer.util.graph.DAGs; import jetbrains.buildServer.vcs.ModificationData; import jetbrains.buildServer.vcs.VcsChange; import jetbrains.buildServer.vcs.VcsException; import org.jetbrains.annotations.NotNull; import java.io.File; import java.util.List; import java.util.Map; import static java.util.Collections.emptyList; /** * @author dmitry.neverov */ public class ServerHgRepo extends HgRepo { public final static HgVersion REVSET_HG_VERSION = new HgVersion(1, 7, 0); public final static HgVersion MERGE_WITHOUT_CHANGED_FILES_VERSION = new HgVersion(5, 2, 0); private final CommandSettingsFactory myCommandSettingsFactory; private final ServerPluginConfig myConfig; protected final MercurialClasspathTemplate myLogTemplate = new MercurialClasspathTemplate("/buildServerResources/log.template", "hg.log.template"); protected final MercurialClasspathTemplate myLogNoFilesTemplate = new MercurialClasspathTemplate("/buildServerResources/log.no.files.template", "hg.short.log.template"); protected final MercurialClasspathTemplate myDagTemplate = new MercurialClasspathTemplate("/buildServerResources/dag.template", "hg.dag.template"); protected final MercurialClasspathTemplate myFastLogTemplate = new MercurialClasspathTemplate("/buildServerResources/fastlog.template", "hg.fastlog.template"); private CollectChangesContext myContext; public ServerHgRepo(@NotNull CommandSettingsFactory commandSettingsFactory, @NotNull ServerPluginConfig config, @NotNull File workingDir, @NotNull String hgPath, @NotNull AuthSettings authSettings) { super(commandSettingsFactory, workingDir, hgPath, authSettings); myCommandSettingsFactory = commandSettingsFactory; myConfig = config; } public void setOperationContext(@NotNull CollectChangesContext context) { myContext = context; } public LogCommand log() { return new LogCommand(myCommandSettingsFactory.create(), myHgPath, myWorkingDir, myAuthSettings).withTemplate(myLogTemplate); } @NotNull public LogCommand logNoFiles() { return log().withTemplate(myLogNoFilesTemplate); } public LogCommand log(@NotNull HgVcsRoot root) { final MercurialTemplate template = root.isSubrepo() && !myConfig.reportSubrepoChangesFileStatus() ? myFastLogTemplate : myLogTemplate; return new LogCommand(myCommandSettingsFactory.create(), myHgPath, myWorkingDir, myAuthSettings).withTemplate(template); } public MergeBaseCommand mergeBase() throws VcsException { HgVersion hgVersion = getHgVersion(); if (hgVersion.isEqualsOrGreaterThan(REVSET_HG_VERSION)) return new MergeBaseWithRevsets(this); else return new MergeBaseNoRevsets(this); } @NotNull public CollectChangesCommand collectChanges(@NotNull HgVcsRoot root) throws VcsException { if (myConfig.dontUseRevsets()) return new CollectChangesNoRevsets(root, this, myLogNoFilesTemplate); HgVersion hgVersion = getHgVersion(); if (hgVersion.isEqualsOrGreaterThan(REVSET_HG_VERSION)) { return new CollectChangesWithRevsets(root, this); } else { return new CollectChangesNoRevsets(root, this, myLogNoFilesTemplate); } } public boolean supportRevsets() throws VcsException { HgVersion hgVersion = getHgVersion(); return hgVersion.isEqualsOrGreaterThan(REVSET_HG_VERSION); } // mercurial > 5.1 no longer reports changed files for the merge commits, see https://youtrack.jetbrains.com/issue/TW-79815 public boolean supportsChangedFilesForMerges() throws VcsException { HgVersion hgVersion = getHgVersion(); return hgVersion.isLessThan(MERGE_WITHOUT_CHANGED_FILES_VERSION); } private HgVersion getHgVersion() throws VcsException { if (myContext != null) return myContext.getHgVersion(this); return version().call(); } @NotNull public DAG<String> loadDag() throws VcsException { LoadDagCommand loadDag = new LoadDagCommand(myCommandSettingsFactory.create(), myHgPath, myWorkingDir, myAuthSettings, myDagTemplate); loadDag.setMaxDagNodesCount(myConfig.getMaxDagNodesCount()); List<Pair<String, String>> edges = loadDag.call(); return DAGs.createFromEdges(edges); } public Map<String, SubRepo> getSubrepositories(@NotNull ModificationData m) { if (hasSubrepoConfigChanges(m)) return getSubrepositories(m.getVersion()); for (String p : m.getParentRevisions()) { Map<String, SubRepo> cached = mySubreposCache.get(p); if (cached != null) { mySubreposCache.put(m.getVersion(), cached); return cached; } } return getSubrepositories(m.getVersion()); } public List<HgSubrepoConfigChange> getSubrepoConfigChanges(@NotNull ModificationData m) { if (hasSubrepoConfigChanges(m)) return getSubrepoConfigChanges(m.getVersion(), m.getParentRevisions()); return emptyList(); } private boolean hasSubrepoConfigChanges(@NotNull ModificationData m) { for (VcsChange c : m.getChanges()) { //use endsWith instead of equals because files are mapped by checkout rules if (c.getFileName().endsWith(".hgsub") || c.getFileName().endsWith(".hgsubstate")) return true; } return false; } }