Mercurial > hg > mercurial
changeset 446:8a1231dc6a2c
Collect changes between states
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Mon, 25 Jun 2012 11:09:36 +0400 |
parents | b47cfe5cbaba |
children | d4c061183a5f |
files | mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java |
diffstat | 2 files changed, 95 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Fri Jun 22 12:41:23 2012 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Mon Jun 25 11:09:36 2012 +0400 @@ -50,7 +50,7 @@ * <p>Personal builds (remote runs) are not yet supported, they require corresponding functionality from the IDE. */ public class MercurialVcsSupport extends ServerVcsSupport implements LabelingSupport, VcsFileContentProvider, BranchSupport, - CollectChangesBetweenRoots, BuildPatchByCheckoutRules { + CollectChangesBetweenRoots, CollectChangesBetweenRepositories, BuildPatchByCheckoutRules { private final VcsManager myVcsManager; private final MirrorManager myMirrorManager; private final ServerPluginConfig myConfig; @@ -508,6 +508,39 @@ } @NotNull + public List<ModificationData> collectChanges(@NotNull VcsRoot fromRoot, + @NotNull RepositoryState fromState, + @NotNull VcsRoot toRoot, + @NotNull RepositoryState toState, + @NotNull CheckoutRules rules) throws VcsException { + return collectChanges(toRoot, fromState, toState, rules); + } + + @NotNull + public List<ModificationData> collectChanges(@NotNull VcsRoot root, + @NotNull RepositoryState fromState, + @NotNull RepositoryState toState, + @NotNull CheckoutRules rules) throws VcsException { + Set<String> reportedCsetIds = new HashSet<String>(); + List<ModificationData> changes = new ArrayList<ModificationData>(); + for (Map.Entry<String, String> entry : toState.getBranchRevisions().entrySet()) { + String branch = entry.getKey(); + String toRevision = entry.getValue(); + String fromRevision = fromState.getBranchRevisions().get(branch); + if (fromRevision == null) + fromRevision = fromState.getBranchRevisions().get(fromState.getDefaultBranchName()); + if (toRevision.equals(fromRevision)) + continue; + List<ModificationData> branchChanges = collectChanges(root, fromRevision, toRevision, rules); + for (ModificationData change : branchChanges) { + if (reportedCsetIds.add(change.getVersion())) + changes.add(change); + } + } + return changes; + } + + @NotNull public List<ModificationData> collectChanges(@NotNull VcsRoot fromRoot, @NotNull String fromRootRevision, @NotNull VcsRoot toRoot, @Nullable String toRootRevision, @NotNull CheckoutRules checkoutRules) throws VcsException {
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Fri Jun 22 12:41:23 2012 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Mon Jun 25 11:09:36 2012 +0400 @@ -20,6 +20,8 @@ import jetbrains.buildServer.vcs.*; import jetbrains.buildServer.vcs.impl.VcsRootImpl; import junit.framework.Assert; +import org.hamcrest.Description; +import org.hamcrest.TypeSafeMatcher; import org.jetbrains.annotations.NotNull; import org.jmock.Mockery; import org.testng.annotations.BeforeMethod; @@ -35,6 +37,10 @@ import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.buildPatch; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot; +import static jetbrains.buildServer.util.Util.map; +import static jetbrains.buildServer.vcs.RepositoryStateFactory.createRepositoryState; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItem; @Test public class MercurialVcsSupportTest extends BaseMercurialTestCase { @@ -549,6 +555,61 @@ } + public void collect_changes_between_states() throws Exception { + VcsRootImpl root = createVcsRoot(myRep2Path); + List<ModificationData> changes = myVcs.collectChanges(root, + createRepositoryState(map("default", "1e620196c4b6"), "default"), + createRepositoryState(map("default", "505c5b9d01e6", "personal-branch", "96b78d73081d"), "default"), + CheckoutRules.DEFAULT); + assertEquals(changes.size(), 4); + assertThat(changes, hasItem(withVersion("dec47d2d49bf"))); + assertThat(changes, hasItem(withVersion("78e67807f916"))); + assertThat(changes, hasItem(withVersion("96b78d73081d"))); + assertThat(changes, hasItem(withVersion("505c5b9d01e6"))); + } + + + public void collect_changes_between_states_does_not_report_duplicate_changes() throws Exception { + VcsRootImpl root = createVcsRoot(myRep2Path); + List<ModificationData> changes = myVcs.collectChanges(root, + createRepositoryState(map("default", "8c44244d6645"), "default"), + createRepositoryState(map("default", "505c5b9d01e6", "personal-branch", "9ec402c74298"), "default"), + CheckoutRules.DEFAULT); + assertEquals(changes.size(), 8); + assertThat(changes, hasItem(withVersion("9ec402c74298"))); + assertThat(changes, hasItem(withVersion("505c5b9d01e6"))); + assertThat(changes, hasItem(withVersion("96b78d73081d"))); + assertThat(changes, hasItem(withVersion("78e67807f916"))); + assertThat(changes, hasItem(withVersion("dec47d2d49bf"))); + assertThat(changes, hasItem(withVersion("1e620196c4b6"))); + assertThat(changes, hasItem(withVersion("48177654181c"))); + assertThat(changes, hasItem(withVersion("fc524efc2bc4"))); + } + + + private ModificationDataVersionMatcher withVersion(@NotNull String version) { + return new ModificationDataVersionMatcher(version); + } + + class ModificationDataVersionMatcher extends TypeSafeMatcher<ModificationData> { + + private final String myVersion; + + public ModificationDataVersionMatcher(@NotNull String version) { + myVersion = version; + } + + @Override + public boolean matchesSafely(ModificationData m) { + return myVersion.equals(m.getVersion()); + } + + public void describeTo(Description description) { + description.appendText("modification with version").appendValue(myVersion); + } + } + + private void assertFiles(final List<String> expectedFiles, final ModificationData modificationData) { Set<String> actualFiles = new HashSet<String>(); for (VcsChange vc: modificationData.getChanges()) {