Mercurial > hg > mercurial
changeset 144:2e90ef872b68
Collect changes using CheckoutRules.
We built patches with CheckoutRules anyway.
Also BranchSupport interface currently allows collecting changes
between 2 roots only using CheckoutRules. And this will have better
performance.
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Tue, 11 Jan 2011 13:05:31 +0300 |
parents | 2ab0bce4bf64 |
children | 3a8af53dea6b 67a20cc047cb |
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, 63 insertions(+), 82 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Thu Dec 23 16:51:28 2010 +0300 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Tue Jan 11 13:05:31 2011 +0300 @@ -101,19 +101,15 @@ return cfc.execute(); } - private List<VcsChange> toVcsChanges(final List<ModifiedFile> modifiedFiles, String prevVer, String curVer, final IncludeRule includeRule) { + private List<VcsChange> toVcsChanges(final List<ModifiedFile> modifiedFiles, String prevVer, String curVer) { List<VcsChange> files = new ArrayList<VcsChange>(); for (ModifiedFile mf: modifiedFiles) { - String normalizedPath = PathUtil.normalizeSeparator(mf.getPath()); - if (!normalizedPath.startsWith(includeRule.getFrom())) continue; // skip files which do not match include rule - String relPath = StringUtil.removeLeadingSlash(normalizedPath.substring(includeRule.getFrom().length())); - VcsChangeInfo.Type changeType = getChangeType(mf.getStatus()); if (changeType == null) { Loggers.VCS.warn("Unable to convert status: " + mf.getStatus() + " to VCS change type"); changeType = VcsChangeInfo.Type.NOT_CHANGED; } - files.add(new VcsChange(changeType, mf.getStatus().getName(), normalizedPath, relPath, prevVer, curVer)); + files.add(new VcsChange(changeType, mf.getStatus().getName(), mf.getPath(), mf.getPath(), prevVer, curVer)); } return files; } @@ -416,68 +412,59 @@ @NotNull public CollectChangesPolicy getCollectChangesPolicy() { - return new CollectChangesByIncludeRules() { - @NotNull - public IncludeRuleChangeCollector getChangeCollector(@NotNull final VcsRoot root, @NotNull final String fromVersion, @Nullable final String currentVersion) throws VcsException { - return new IncludeRuleChangeCollector() { - @NotNull - public List<ModificationData> collectChanges(@NotNull final IncludeRule includeRule) throws VcsException { - syncClonedRepository(root); - - // first obtain changes between specified versions - List<ModificationData> result = new ArrayList<ModificationData>(); - if (currentVersion == null) return result; + return new CollectChangesByCheckoutRules() { + public List<ModificationData> collectChanges(@NotNull VcsRoot root, @NotNull String fromVersion, @Nullable String currentVersion, @NotNull CheckoutRules checkoutRules) throws VcsException { + syncClonedRepository(root); - Settings settings = createSettings(root); - LogCommand lc = new LogCommand(settings); - String fromId = new ChangeSetRevision(fromVersion).getId(); - lc.setFromRevId(fromId); - lc.setToRevId(new ChangeSetRevision(currentVersion).getId()); - List<ChangeSet> changeSets = lc.execute(); - if (changeSets.isEmpty()) { - return result; - } - - // invoke status command for each changeset and determine what files were modified in these changesets - StatusCommand st = new StatusCommand(settings); - ChangeSet prev = new ChangeSet(fromVersion); - for (ChangeSet cur : changeSets) { - if (cur.getId().equals(fromId)) continue; // skip already reported changeset + // first obtain changes between specified versions + List<ModificationData> result = new ArrayList<ModificationData>(); + if (currentVersion == null) return result; - String prevId = prev.getId(); - List<ChangeSetRevision> curParents = cur.getParents(); - boolean merge = curParents != null && curParents.size() > 1; - if (curParents != null && !merge) { - prevId = curParents.get(0).getId(); - } + Settings settings = createSettings(root); + LogCommand lc = new LogCommand(settings); + String fromId = new ChangeSetRevision(fromVersion).getId(); + lc.setFromRevId(fromId); + lc.setToRevId(new ChangeSetRevision(currentVersion).getId()); + List<ChangeSet> changeSets = lc.execute(); + if (changeSets.isEmpty()) { + return result; + } - List<ModifiedFile> modifiedFiles = new ArrayList<ModifiedFile>(); - if (merge) { - modifiedFiles.addAll(computeModifiedFilesForMergeCommit(settings, cur)); - } else { - st.setFromRevId(prevId); - st.setToRevId(cur.getId()); - modifiedFiles = st.execute(); - } + // invoke status command for each changeset and determine what files were modified in these changesets + StatusCommand st = new StatusCommand(settings); + ChangeSet prev = new ChangeSet(fromVersion); + for (ChangeSet cur : changeSets) { + if (cur.getId().equals(fromId)) continue; // skip already reported changeset - // changeset full version will be set into VcsChange structure and - // stored in database (note that getContent method will be invoked with this version) - List<VcsChange> files = toVcsChanges(modifiedFiles, prev.getFullVersion(), cur.getFullVersion(), includeRule); - if (files.isEmpty() && !merge) continue; - ModificationData md = new ModificationData(cur.getTimestamp(), files, cur.getDescription(), cur.getUser(), root, cur.getFullVersion(), cur.getId()); - if (merge) { - md.setCanBeIgnored(false); - } - result.add(md); - prev = cur; - } - - return result; + String prevId = prev.getId(); + List<ChangeSetRevision> curParents = cur.getParents(); + boolean merge = curParents != null && curParents.size() > 1; + if (curParents != null && !merge) { + prevId = curParents.get(0).getId(); } - public void dispose() throws VcsException { + List<ModifiedFile> modifiedFiles = new ArrayList<ModifiedFile>(); + if (merge) { + modifiedFiles.addAll(computeModifiedFilesForMergeCommit(settings, cur)); + } else { + st.setFromRevId(prevId); + st.setToRevId(cur.getId()); + modifiedFiles = st.execute(); } - }; + + // changeset full version will be set into VcsChange structure and + // stored in database (note that getContent method will be invoked with this version) + List<VcsChange> files = toVcsChanges(modifiedFiles, prev.getFullVersion(), cur.getFullVersion()); + if (files.isEmpty() && !merge) continue; + ModificationData md = new ModificationData(cur.getTimestamp(), files, cur.getDescription(), cur.getUser(), root, cur.getFullVersion(), cur.getId()); + if (merge) { + md.setCanBeIgnored(false); + } + result.add(md); + prev = cur; + } + + return result; } }; }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Thu Dec 23 16:51:28 2010 +0300 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Tue Jan 11 13:05:31 2011 +0300 @@ -80,6 +80,10 @@ assertEquals(myVcs.getCurrentVersion(createVcsRoot(simpleRepo(), "name with space")), "9:9babcf2d5705"); } + private List<ModificationData> collectChanges(@NotNull VcsRoot vcsRoot, @NotNull String from, @NotNull String to, @NotNull CheckoutRules rules) throws VcsException { + return ((CollectChangesByCheckoutRules) myVcs.getCollectChangesPolicy()).collectChanges(vcsRoot, from, to, rules); + } + private List<ModificationData> collectChanges(@NotNull VcsRoot vcsRoot, @NotNull String from, @NotNull String to, @NotNull IncludeRule rule) throws VcsException { return ((CollectChangesByIncludeRules)myVcs.getCollectChangesPolicy()).getChangeCollector(vcsRoot, from, to).collectChanges(rule); } @@ -87,7 +91,7 @@ public void test_collect_changes() throws Exception { VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); - List<ModificationData> changes = collectChanges(vcsRoot, "0:9875b412a788", "3:9522278aa38d", new CheckoutRules("").getIncludeRuleFor("")); + List<ModificationData> changes = collectChanges(vcsRoot, "0:9875b412a788", "3:9522278aa38d", new CheckoutRules("")); assertEquals(3, changes.size()); ModificationData md1 = changes.get(0); @@ -115,21 +119,6 @@ assertEquals(normalizePath(files3.get(0).getRelativeFileName()), "dir1/file4.txt"); } - public void test_collect_changes_with_not_empty_include_rule() throws Exception { - VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); - - List<ModificationData> changes = collectChanges(vcsRoot, "0:9875b412a788", "5:1d2cc6f3bc29", new IncludeRule("dir1/subdir", "dir1/subdir", null)); - assertEquals(changes.size(), 1, changes.toString()); - - ModificationData md = changes.get(0); - assertEquals(md.getDescription(), "modified in subdir"); - - List<VcsChange> files = changes.get(0).getChanges(); - assertEquals(files.size(), 1, files.toString()); - assertEquals("dir1/subdir/file2.txt", files.get(0).getFileName()); - assertEquals("file2.txt", files.get(0).getRelativeFileName()); - } - private ByteArrayOutputStream buildPatch(VcsRoot vcsRoot, String from, String to, CheckoutRules rules) throws IOException, VcsException { final ByteArrayOutputStream output = new ByteArrayOutputStream(); final PatchBuilderImpl builder = new PatchBuilderImpl(output); @@ -259,7 +248,7 @@ VcsRootImpl vcsRoot = createVcsRoot(simpleRepo(), "test_branch"); // fromVersion(6:b9deb9a1c6f4) is not in the branch (it is in the default branch) - List<ModificationData> changes = collectChanges(vcsRoot, "6:b9deb9a1c6f4", "7:376dcf05cd2a", IncludeRule.createDefaultInstance()); + List<ModificationData> changes = collectChanges(vcsRoot, "6:b9deb9a1c6f4", "7:376dcf05cd2a", CheckoutRules.DEFAULT); assertEquals(1, changes.size()); ModificationData md1 = changes.get(0); @@ -270,7 +259,7 @@ assertEquals(VcsChangeInfo.Type.ADDED, files1.get(0).getType()); assertEquals(normalizePath(files1.get(0).getRelativeFileName()), "file_in_branch.txt"); - changes = collectChanges(vcsRoot, "7:376dcf05cd2a", "8:04c3ae4c6312", IncludeRule.createDefaultInstance()); + changes = collectChanges(vcsRoot, "7:376dcf05cd2a", "8:04c3ae4c6312", CheckoutRules.DEFAULT); assertEquals(1, changes.size()); md1 = changes.get(0); @@ -351,7 +340,7 @@ public void test_collect_changes_merge() throws Exception { VcsRootImpl vcsRoot = createVcsRoot(mergeCommittsRepo()); - List<ModificationData> changes = collectChanges(vcsRoot, "1:a3d15477d297", "4:6eeb8974fe67", IncludeRule.createDefaultInstance()); + List<ModificationData> changes = collectChanges(vcsRoot, "1:a3d15477d297", "4:6eeb8974fe67", CheckoutRules.DEFAULT); assertEquals(changes.size(), 3); assertEquals("2:db8a04d262f3", changes.get(0).getVersion()); @@ -366,7 +355,7 @@ public void test_collect_changes_merge_conflict() throws Exception { VcsRootImpl vcsRoot = createVcsRoot(mergeCommittsRepo()); - List<ModificationData> changes = collectChanges(vcsRoot, "6:6066b677d026", "8:b6e2d176fe8e", IncludeRule.createDefaultInstance()); + List<ModificationData> changes = collectChanges(vcsRoot, "6:6066b677d026", "8:b6e2d176fe8e", CheckoutRules.DEFAULT); assertEquals(changes.size(), 2); assertFiles(Arrays.asList("A dir4/file41.txt"), changes.get(0)); @@ -376,7 +365,7 @@ public void test_collect_changes_merge_conflict_named_branch() throws Exception { VcsRootImpl vcsRoot = createVcsRoot(mergeCommittsRepo()); - List<ModificationData> changes = collectChanges(vcsRoot, "8:b6e2d176fe8e", "12:1e620196c4b6", IncludeRule.createDefaultInstance()); + List<ModificationData> changes = collectChanges(vcsRoot, "8:b6e2d176fe8e", "12:1e620196c4b6", CheckoutRules.DEFAULT); assertEquals(changes.size(), 2); assertFiles(Arrays.asList("A dir6/file6.txt"), changes.get(0)); @@ -406,4 +395,9 @@ private Object normalizePath(final String path) { return path.replace(File.separatorChar, '/'); } + + + public void test_collect_changes_using_checkout_rules() { + assertTrue(myVcs.getCollectChangesPolicy() instanceof CollectChangesByCheckoutRules); + } }