Mercurial > hg > mercurial
view mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerHgRepo.java @ 706:c27e501ed0c3
use own command for hg subrepos
author | eugene.petrenko@jetbrains.com |
---|---|
date | Wed, 08 Jan 2014 18:32:42 +0100 |
parents | 3aff8caf7d60 |
children | 69bb18514349 |
line wrap: on
line source
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 { private final static HgVersion REVSET_HG_VERSION = new HgVersion(1, 7, 0); private final CommandSettingsFactory myCommandSettingsFactory; private final ServerPluginConfig myConfig; private File myLogTemplate; private File myLogNoFilesTemplate; private File myDagTemplate; private File myFastLogTemplate; private OperationContext 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 OperationContext context) { myContext = context; } public ServerHgRepo withLogTemplates(@NotNull File logTemplate, @NotNull File logNoFilesTemplate, @NotNull File dagTemplate, @NotNull File fastLogTemplate) { myLogTemplate = logTemplate; myLogNoFilesTemplate = logNoFilesTemplate; myDagTemplate = dagTemplate; myFastLogTemplate = fastLogTemplate; return this; } 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) { File 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); } 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); } @NotNull public LoadSubstatesCommand loadSubstates() throws VcsException { return new LoadSubstatesCommand(myCommandSettingsFactory.create(), myHgPath, myWorkingDir, myAuthSettings); } 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; } }