changeset 86:948a35b430e1 Darjeeling-5.0.x

report parent changesets
author Pavel.Sher
date Tue, 08 Dec 2009 19:49:28 +0300
parents 86c7235a11fa
children a18bc3ca271d
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ChangeSet.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ChangeSetRevision.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommandTest.java mercurial.ipr
diffstat 7 files changed, 159 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ChangeSet.java	Thu Dec 03 15:01:44 2009 +0300
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ChangeSet.java	Tue Dec 08 19:49:28 2009 +0300
@@ -16,22 +16,23 @@
 package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
 
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 
 /**
  * Represents Mercurial change set
  */
-public class ChangeSet {
-  private int myRevNumber;
-  @NotNull private String myId;
+public class ChangeSet extends ChangeSetRevision {
   @NotNull private String myUser;
   @NotNull private Date myTimestamp;
   private String mySummary;
+  private List<ChangeSetRevision> myParents;
 
   public ChangeSet(final int revNumber, @NotNull final String id) {
-    myRevNumber = revNumber;
-    myId = id;
+    super(revNumber, id);
   }
 
   /**
@@ -39,18 +40,7 @@
    * @param fullVersion full changeset version as reported by hg log command
    */
   public ChangeSet(@NotNull final String fullVersion) {
-    try {
-      int colon = fullVersion.indexOf(":");
-      if (colon != -1) {
-        myRevNumber = Integer.parseInt(fullVersion.substring(0, colon));
-        myId = fullVersion.substring(colon+1);
-      } else {
-        myRevNumber = -1;
-        myId = fullVersion;
-      }
-    } catch (Throwable e) {
-      throw new IllegalArgumentException(e);
-    }
+    super(fullVersion);
   }
 
   public void setUser(@NotNull final String user) {
@@ -65,30 +55,11 @@
     mySummary = summary;
   }
 
-  /**
-   * Returns changeset revision id
-   * @return changeset revision id
-   */
-  @NotNull
-  public String getId() {
-    return myId;
-  }
-
-  /**
-   * Returns changeset revision number
-   * @return changeset revision number
-   */
-  public int getRevNumber() {
-    return myRevNumber;
-  }
-
-  /**
-   * Returns full changeset version as reported by hg log command: revnum:revid
-   * @return full changeset version as reported by hg log
-   */
-  @NotNull
-  public String getFullVersion() {
-    return myRevNumber + ":" + myId;
+  public void addParent(@NotNull ChangeSetRevision rev) {
+    if (myParents == null) {
+      myParents = new ArrayList<ChangeSetRevision>();
+    }
+    myParents.add(rev);
   }
 
   /**
@@ -116,4 +87,13 @@
   public String getSummary() {
     return mySummary;
   }
+
+  /**
+   * Returns parrents of this change set, or null if there were no parents.
+   * @return see above
+   */
+  @Nullable
+  public List<ChangeSetRevision> getParents() {
+    return myParents;
+  }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/ChangeSetRevision.java	Tue Dec 08 19:49:28 2009 +0300
@@ -0,0 +1,79 @@
+package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
+
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Pavel.Sher
+ */
+public class ChangeSetRevision {
+  private final int myRevNumber;
+  @NotNull
+  private final String myId;
+
+  public ChangeSetRevision(final int revNumber, @NotNull final String id) {
+    myRevNumber = revNumber;
+    myId = id;
+  }
+
+  /**
+   * Constructor for version in the form revnum:changeset_id or just changeset_id (in this case rev number is set to -1)
+   * @param fullVersion full changeset version as reported by hg log command
+   */
+  public ChangeSetRevision(@NotNull final String fullVersion) {
+    try {
+      int colon = fullVersion.indexOf(":");
+      if (colon != -1) {
+        myRevNumber = Integer.parseInt(fullVersion.substring(0, colon));
+        myId = fullVersion.substring(colon+1);
+      } else {
+        myRevNumber = -1;
+        myId = fullVersion;
+      }
+    } catch (Throwable e) {
+      throw new IllegalArgumentException(e);
+    }
+  }
+
+  /**
+   * Returns changeset revision id
+   * @return changeset revision id
+   */
+  @NotNull
+  public String getId() {
+    return myId;
+  }
+
+  /**
+   * Returns changeset revision number
+   * @return changeset revision number
+   */
+  public int getRevNumber() {
+    return myRevNumber;
+  }
+
+  /**
+   * Returns full changeset version as reported by hg log command: revnum:revid
+   * @return full changeset version as reported by hg log
+   */
+  @NotNull
+  public String getFullVersion() {
+    return myRevNumber + ":" + myId;
+  }
+
+  @Override
+  public boolean equals(final Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    final ChangeSetRevision that = (ChangeSetRevision) o;
+
+    return myRevNumber == that.myRevNumber && myId.equals(that.myId);
+  }
+
+  @Override
+  public int hashCode() {
+    int result = myRevNumber;
+    result = 31 * result + myId.hashCode();
+    return result;
+  }
+}
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java	Thu Dec 03 15:01:44 2009 +0300
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java	Tue Dec 08 19:49:28 2009 +0300
@@ -35,6 +35,7 @@
   private ArrayList<String> myPaths;
   private static final String CHANGESET_PREFIX = "changeset:";
   private static final String USER_PREFIX = "user:";
+  private static final String PARENT_PREFIX = "parent:";
   private static final String DATE_PREFIX = "date:";
   private static final String DATE_FORMAT = "EEE MMM d HH:mm:ss yyyy Z";
   private static final String SUMMARY_PREFIX = "summary:";
@@ -104,6 +105,12 @@
         continue;
       }
 
+      if (line.startsWith(PARENT_PREFIX)) {
+        String parentRev = line.substring(PARENT_PREFIX.length()).trim();
+        current.addParent(new ChangeSetRevision(parentRev));
+        continue;
+      }
+
       if (line.startsWith(DATE_PREFIX)) {
         String date = line.substring(DATE_PREFIX.length()).trim();
         try {
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Thu Dec 03 15:01:44 2009 +0300
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Tue Dec 08 19:49:28 2009 +0300
@@ -89,9 +89,9 @@
     List<ModificationData> result = new ArrayList<ModificationData>();
     Settings settings = createSettings(root);
     LogCommand lc = new LogCommand(settings);
-    String fromId = new ChangeSet(fromVersion).getId();
+    String fromId = new ChangeSetRevision(fromVersion).getId();
     lc.setFromRevId(fromId);
-    lc.setToRevId(new ChangeSet(currentVersion).getId());
+    lc.setToRevId(new ChangeSetRevision(currentVersion).getId());
     List<ChangeSet> changeSets = lc.execute();
     if (changeSets.isEmpty()) {
       return result;
@@ -100,8 +100,7 @@
     // 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 (int i=0; i<changeSets.size(); i++) {
-      ChangeSet cur = changeSets.get(i);
+    for (ChangeSet cur : changeSets) {
       if (cur.getId().equals(fromId)) continue; // skip already reported changeset
 
       st.setFromRevId(prev.getId());
@@ -145,17 +144,17 @@
   }
 
   @NotNull
-  public byte[] getContent(final VcsModification vcsModification,
-                           final VcsChangeInfo change,
-                           final VcsChangeInfo.ContentType contentType,
-                           final VcsRoot vcsRoot) throws VcsException {
+  public byte[] getContent(@NotNull final VcsModification vcsModification,
+                           @NotNull final VcsChangeInfo change,
+                           @NotNull final VcsChangeInfo.ContentType contentType,
+                           @NotNull final VcsRoot vcsRoot) throws VcsException {
     syncClonedRepository(vcsRoot);
     String version = contentType == VcsChangeInfo.ContentType.AFTER_CHANGE ? change.getAfterChangeRevisionNumber() : change.getBeforeChangeRevisionNumber();
     return getContent(change.getRelativeFileName(), vcsRoot, version);
   }
 
   @NotNull
-  public byte[] getContent(final String filePath, final VcsRoot vcsRoot, final String version) throws VcsException {
+  public byte[] getContent(@NotNull final String filePath, @NotNull final VcsRoot vcsRoot, @NotNull final String version) throws VcsException {
     syncClonedRepository(vcsRoot);
     Settings settings = createSettings(vcsRoot);
     CatCommand cc = new CatCommand(settings);
@@ -178,10 +177,12 @@
     return new byte[0];
   }
 
+  @NotNull
   public String getName() {
     return Constants.VCS_NAME;
   }
 
+  @NotNull
   @Used("jsp")
   public String getDisplayName() {
     return "Mercurial";
@@ -206,12 +207,13 @@
     };
   }
 
+  @NotNull
   public String getVcsSettingsJspFilePath() {
     return "mercurialSettings.jsp";
   }
 
   @NotNull
-  public String getCurrentVersion(final VcsRoot root) throws VcsException {
+  public String getCurrentVersion(@NotNull final VcsRoot root) throws VcsException {
     // we will return full version of the most recent change as current version
     syncClonedRepository(root);
     Settings settings = createSettings(root);
@@ -224,6 +226,7 @@
     return result.get(settings.getBranchName()).getFullVersion();
   }
 
+  @NotNull
   public String describeVcsRoot(final VcsRoot vcsRoot) {
     return "mercurial: " + vcsRoot.getProperty(Constants.REPOSITORY_PROP);
   }
@@ -233,7 +236,7 @@
   }
 
   @Nullable
-  public String testConnection(final VcsRoot vcsRoot) throws VcsException {
+  public String testConnection(@NotNull final VcsRoot vcsRoot) throws VcsException {
     Settings settings = createSettings(vcsRoot);
     IdentifyCommand id = new IdentifyCommand(settings);
     StringBuilder res = new StringBuilder();
@@ -261,7 +264,7 @@
     return defaults;
   }
 
-  public String getVersionDisplayName(final String version, final VcsRoot root) throws VcsException {
+  public String getVersionDisplayName(@NotNull final String version, @NotNull final VcsRoot root) throws VcsException {
     return new ChangeSet(version).getId();
   }
 
@@ -281,11 +284,11 @@
     };
   }
 
-  public void buildPatch(final VcsRoot root,
+  public void buildPatch(@NotNull final VcsRoot root,
                          @Nullable final String fromVersion,
                          @NotNull final String toVersion,
-                         final PatchBuilder builder,
-                         final CheckoutRules checkoutRules) throws IOException, VcsException {
+                         @NotNull final PatchBuilder builder,
+                         @NotNull final CheckoutRules checkoutRules) throws IOException, VcsException {
     syncClonedRepository(root);
     Settings settings = createSettings(root);
     if (fromVersion == null) {
@@ -430,7 +433,7 @@
   }
 
   @Override
-  public boolean ignoreServerCachesFor(final VcsRoot root) {
+  public boolean ignoreServerCachesFor(@NotNull final VcsRoot root) {
     // since a copy of repository for each VCS root is already stored on disk
     // we do not need separate cache for our patches 
     return true;
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Thu Dec 03 15:01:44 2009 +0300
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Tue Dec 08 19:49:28 2009 +0300
@@ -64,8 +64,8 @@
   public void test_get_current_version() throws Exception {
     VcsRootImpl vcsRoot = createVcsRoot();
 
-    assertEquals(myVcs.getCurrentVersion(vcsRoot), "6:b9deb9a1c6f4");
-    assertEquals("b9deb9a1c6f4", myVcs.getVersionDisplayName("6:b9deb9a1c6f4", vcsRoot));
+    assertEquals(myVcs.getCurrentVersion(vcsRoot), "12:1870e1100fab");
+    assertEquals("1870e1100fab", myVcs.getVersionDisplayName("12:1870e1100fab", vcsRoot));
 
     assertEquals(myVcs.getCurrentVersion(createVcsRoot("test_branch")), "8:04c3ae4c6312");
 
@@ -263,6 +263,15 @@
     assertEquals(md1.getDescription(), "file modified");
   }
 
+  public void test_collect_changes_after_merge() throws IOException, VcsException {
+    VcsRootImpl vcsRoot = createVcsRoot();
+
+    List<ModificationData> changes = myVcs.collectBuildChanges(vcsRoot, "6:b9deb9a1c6f4", "12:1870e1100fab", new CheckoutRules(""));
+    for (ModificationData md: changes) {
+      System.out.println(md);
+    }
+  }
+
   public void test_full_patch_from_branch() throws IOException, VcsException {
     setName("patch3");
     VcsRootImpl vcsRoot = createVcsRoot("test_branch");
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommandTest.java	Thu Dec 03 15:01:44 2009 +0300
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommandTest.java	Tue Dec 08 19:49:28 2009 +0300
@@ -17,6 +17,7 @@
 
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
+import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import java.io.IOException;
@@ -24,8 +25,14 @@
 
 @Test
 public class LogCommandTest extends BaseCommandTestCase {
+  @BeforeMethod
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    setRepository("mercurial-tests/testData/rep1", true);
+  }
+
   public void testOneChangeSet() throws Exception {
-    setRepository("mercurial-tests/testData/rep1", true);
     final String toId = "9875b412a788";
     List<ChangeSet> changes = runLog(null, toId);
     assertEquals(1, changes.size());
@@ -34,10 +41,10 @@
     assertEquals(toId, changeSet.getId());
     assertEquals("pavel@localhost", changeSet.getUser());
     assertEquals("dir1 created", changeSet.getSummary());
+    assertNull(changeSet.getParents());
   }
 
   public void testMoreThanOneChangeSet() throws Exception {
-    setRepository("mercurial-tests/testData/rep1", true);
     final String fromId = "9875b412a788";
     final String toId = "7209b1f1d793";
     List<ChangeSet> changes = runLog(fromId, toId);
@@ -55,6 +62,19 @@
     assertEquals("file4.txt added", changeSet1.getSummary());
   }
 
+  public void changeset_parents() throws VcsException, IOException {
+    List<ChangeSet> changes = runLog("ae4f72cfa9d4", "ae4f72cfa9d4");
+    assertEquals(1, changes.size());
+    ChangeSet cs = changes.get(0);
+    assertNotNull(cs.getParents());
+    assertEquals(1, cs.getParents().size());
+    assertEquals(new ChangeSetRevision("6:b9deb9a1c6f4"), cs.getParents().get(0));
+
+    changes = runLog("1870e1100fab", "1870e1100fab");
+    assertEquals(1, changes.size());
+    assertEquals(2, changes.get(0).getParents().size());
+  }
+
   private List<ChangeSet> runLog(final String fromId, final String toId) throws IOException, VcsException {
     return runCommand(new CommandExecutor<List<ChangeSet>>() {
       public List<ChangeSet> execute(@NotNull final Settings settings) throws VcsException {
--- a/mercurial.ipr	Thu Dec 03 15:01:44 2009 +0300
+++ b/mercurial.ipr	Tue Dec 08 19:49:28 2009 +0300
@@ -119,13 +119,6 @@
       <item index="4" class="java.lang.String" itemvalue="SERVER PROBLEM" />
     </list>
   </component>
-  <component name="JavacSettings">
-    <option name="DEBUGGING_INFO" value="true" />
-    <option name="GENERATE_NO_WARNINGS" value="false" />
-    <option name="DEPRECATION" value="true" />
-    <option name="ADDITIONAL_OPTIONS_STRING" value="" />
-    <option name="MAXIMUM_HEAP_SIZE" value="128" />
-  </component>
   <component name="JavadocGenerationManager">
     <option name="OUTPUT_DIRECTORY" />
     <option name="OPTION_SCOPE" value="protected" />
@@ -328,13 +321,6 @@
       </value>
     </option>
   </component>
-  <component name="RmicSettings">
-    <option name="IS_EANABLED" value="false" />
-    <option name="DEBUGGING_INFO" value="true" />
-    <option name="GENERATE_NO_WARNINGS" value="false" />
-    <option name="GENERATE_IIOP_STUBS" value="false" />
-    <option name="ADDITIONAL_OPTIONS_STRING" value="" />
-  </component>
   <component name="ScopeChooserConfigurable.UI">
     <option name="proportions">
       <SplitterProportionsDataImpl />