changeset 251:75765a16ac7e

Implement method getPersonalBranchDescription()
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Fri, 29 Apr 2011 18:58:49 +0400
parents 0c89a207f0a7
children ebd553ff36c5
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, 52 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Fri Apr 29 18:57:49 2011 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Fri Apr 29 18:58:49 2011 +0400
@@ -476,6 +476,37 @@
     return options;
   }
 
+
+  @Nullable
+  public PersonalBranchDescription getPersonalBranchDescription(@NotNull VcsRoot root, @NotNull String branchName) throws VcsException {
+    Settings settings = createSettings(root);
+    VcsRoot branchRoot = createBranchRoot(root, branchName);
+    String baseVersion = getCurrentVersion(root);
+    String branchVersion = getCurrentVersion(branchRoot);
+    String branchPoint = getBranchPoint(settings, baseVersion, branchVersion);
+
+    LogCommand lc = new LogCommand(settings, getWorkingDir(settings));
+    lc.setFromRevId(new ChangeSetRevision(branchPoint).getId());
+    lc.setToRevId(new ChangeSetRevision(branchVersion).getId());
+    lc.setBranchName(null);//do not limit output to particular branch, return all commits
+    List<ChangeSet> changeSets = lc.execute();
+    if (changeSets.size() > 1) {//when branch points to the commit in original branch we get 1 cset
+      String branchId = changeSets.get(1).getId();
+      String username = changeSets.get(changeSets.size() - 1).getUser();
+      return new PersonalBranchDescription(branchId, username);
+    } else {
+      return null;
+    }
+  }
+
+
+  private VcsRoot createBranchRoot(VcsRoot original, String branchName) {
+    VcsRootImpl result = new VcsRootImpl(original.getId(), original.getProperties());
+    result.addProperty(Constants.BRANCH_NAME_PROP, branchName);
+    return result;
+  }
+
+  @NotNull
   public List<ModificationData> collectChanges(@NotNull VcsRoot fromRoot, @NotNull String fromRootRevision,
                                                @NotNull VcsRoot toRoot, @Nullable String toRootRevision,
                                                @NotNull CheckoutRules checkoutRules) throws VcsException {
@@ -486,7 +517,10 @@
     return ((CollectChangesByCheckoutRules) getCollectChangesPolicy()).collectChanges(toRoot, branchPoint, toRootRevision, checkoutRules);
   }
 
+
   private String getBranchPoint(@NotNull Settings settings, String branchOneRev, String branchTwoRev) throws VcsException {
+    if (branchOneRev.equals(branchTwoRev))
+      return branchOneRev;
     File workingDir = getWorkingDir(settings);
     LogCommand lc = new LogCommand(settings, workingDir);
     lc.setFromRevId(new ChangeSetRevision(branchOneRev).getId());
@@ -504,6 +538,7 @@
   @NotNull
   public CollectChangesPolicy getCollectChangesPolicy() {
     return new CollectChangesByCheckoutRules() {
+      @NotNull
       public List<ModificationData> collectChanges(@NotNull VcsRoot root, @NotNull String fromVersion, @Nullable String currentVersion, @NotNull CheckoutRules checkoutRules) throws VcsException {
         Settings settings = createSettings(root);
         syncRepository(settings);
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Fri Apr 29 18:57:49 2011 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Fri Apr 29 18:58:49 2011 +0400
@@ -433,6 +433,22 @@
   }
 
 
+  public void test_getPersonalBranchDescription_when_branch_contains_commits() throws Exception {
+    VcsRootImpl originalRoot = createVcsRoot(simpleRepo());
+    PersonalBranchDescription description = myVcs.getPersonalBranchDescription(originalRoot, "name with space");
+    assertNotNull(description);
+    assertEquals(description.getBranchId(), "376dcf05cd2a");
+    assertEquals(description.getUsername(), "Pavel.Sher");
+  }
+
+
+  public void test_getPersonalBranchDescription_when_branch_doesnot_contain_commits() throws Exception {
+    VcsRootImpl originalRoot = createVcsRoot(simpleRepo());
+    PersonalBranchDescription description = myVcs.getPersonalBranchDescription(originalRoot, "default");
+    assertNull(description);
+  }
+
+
   private void assertFiles(final List<String> expectedFiles, final ModificationData modificationData) {
     List<String> actualFiles = new ArrayList<String>();
     for (VcsChange vc: modificationData.getChanges()) {
@@ -462,3 +478,4 @@
     assertTrue(myVcs.getCollectChangesPolicy() instanceof CollectChangesByCheckoutRules);
   }
 }
+