Mercurial > hg > mercurial
view mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitsInfoBuilderSupport.java @ 662:c3c0ebc63d77
CommitsInfoBuilder command now returns all commits without respect to state parameter (API update will follow)
author | eugene.petrenko@gmail.com |
---|---|
date | Mon, 30 Sep 2013 21:26:55 +0200 |
parents | 5a40adf2ca9e |
children | e01fa9602447 |
line wrap: on
line source
package jetbrains.buildServer.buildTriggers.vcs.mercurial; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.ChangeSet; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.ChangeSetRevision; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot; import jetbrains.buildServer.vcs.*; import jetbrains.vcs.api.CommitInfo; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.command.LogCommand.ZERO_PARENT_ID; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.command.LogCommand.ZERO_PARENT_SHORT_ID; /** * 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 public List<CommitInfo> collectCommits(@NotNull VcsRoot root, @NotNull CheckoutRules rules, @NotNull RepositoryStateData headState) throws VcsException { return collectCommits(root, rules); } @NotNull public List<CommitInfo> collectCommits(@NotNull VcsRoot root, @NotNull CheckoutRules rules) throws VcsException { final HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root); final ServerHgRepo repo = mySupport.createRepo(hgRoot); mySupport.syncRepository(hgRoot); final Map<String, CommitDataBean> commitToBean = processChanges(repo); //collect tags info Map<String, String> tags = repo.tags().call(); for (Map.Entry<String, String> e : tags.entrySet()) { CommitDataBean bean = commitToBean.get(e.getValue()); if (bean != null) bean.addTag(e.getKey()); } return new ArrayList<CommitInfo>(commitToBean.values()); } @NotNull private Map<String, CommitDataBean> processChanges(@NotNull ServerHgRepo repo) throws VcsException { final List<ChangeSet> tip = repo.logNoFiles() .showCommitsFromAllBranches() .call(); final Map<String, CommitDataBean> result = new HashMap<String, CommitDataBean>(); for (ChangeSet set : tip) { final CommitDataBean bean = new CommitDataBean(set.getId(), set.getFullVersion(), set.getTimestamp()); for (ChangeSetRevision p : set.getParents()) { final String commitId = p.getId(); if (ZERO_PARENT_ID.equals(commitId)) continue; if (ZERO_PARENT_SHORT_ID.equals(commitId)) continue; bean.addParentRevision(commitId); } bean.addBranch(set.getBranch()); result.put(bean.getVersion(), bean); } return result; } }