changeset 760:388b7f309865

inverse control
author eugene.petrenko@jetbrains.com
date Tue, 25 Feb 2014 11:48:56 +0100
parents f6aa84ab05bd
children 196f62e515db
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialLogTemplate.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LoadDagCommand.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java
diffstat 3 files changed, 89 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialLogTemplate.java	Tue Feb 25 11:42:22 2014 +0100
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialLogTemplate.java	Tue Feb 25 11:48:56 2014 +0100
@@ -55,6 +55,16 @@
     }
   }
 
+  public interface WithTemplate<T> {
+    @NotNull
+    T action(@NotNull final File template) throws VcsException;
+  }
+
+  @NotNull
+  public <T> T withTemplate(@NotNull final WithTemplate<T> action) throws VcsException {
+    return action.action(getTemplate());
+  }
+
   public void dispose() {
     delete(myFile);
   }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LoadDagCommand.java	Tue Feb 25 11:42:22 2014 +0100
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LoadDagCommand.java	Tue Feb 25 11:48:56 2014 +0100
@@ -46,31 +46,42 @@
 
   @NotNull
   public List<Pair<String, String>> call() throws VcsException {
-    List<Pair<String, String>> edges = new ArrayList<Pair<String, String>>();
-    MercurialCommandLine cli = createCommandLine();
-    cli.addParameter("log");
-    cli.addParameter("--style=" + myDagLogTemplate.getTemplate().getAbsolutePath());
-    if (myMaxDagNodesCount > 0)
-      cli.addParameters("--limit", String.valueOf(myMaxDagNodesCount));
-    CommandResult res = runCommand(cli);
-    String output = res.getStdout();
-    String fromNode = null;
-    for (String line : StringUtil.splitByLines(output)) {
-      String[] revs = line.split(" ");
-      if (revs.length == 0)
-        continue;
-      if (fromNode != null) {
-        edges.add(Pair.create(fromNode, revs[0]));
-        fromNode = null;
+    return myDagLogTemplate.withTemplate(new MercurialLogTemplate.WithTemplate<List<Pair<String, String>>>() {
+      @NotNull
+      public List<Pair<String, String>> action(@NotNull File template) throws VcsException {
+        final List<Pair<String, String>> edges = new ArrayList<Pair<String, String>>();
+        final MercurialCommandLine cli = createCommandLine();
+        cli.addParameter("log");
+        cli.addParameter("--style=" + template.getAbsolutePath());
+        if (myMaxDagNodesCount > 0) {
+          cli.addParameters("--limit", String.valueOf(myMaxDagNodesCount));
+        }
+
+        final CommandResult res = runCommand(cli);
+
+
+        final String output = res.getStdout();
+        String fromNode = null;
+        for (String line : StringUtil.splitByLines(output)) {
+          final String[] revs = line.split(" ");
+          if (revs.length == 0) continue;
+
+          if (fromNode != null) {
+            edges.add(Pair.create(fromNode, revs[0]));
+            fromNode = null;
+          }
+
+          if (revs.length == 1) {
+            fromNode = revs[0];
+          } else {
+            edges.add(Pair.create(revs[0], revs[1]));
+            if (revs.length == 3) {
+              edges.add(Pair.create(revs[0], revs[2]));
+            }
+          }
+        }
+        return edges;
       }
-      if (revs.length == 1) {
-        fromNode = revs[0];
-      } else {
-        edges.add(Pair.create(revs[0], revs[1]));
-        if (revs.length == 3)
-          edges.add(Pair.create(revs[0], revs[2]));
-      }
-    }
-    return edges;
+    });
   }
 }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java	Tue Feb 25 11:42:22 2014 +0100
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/LogCommand.java	Tue Feb 25 11:48:56 2014 +0100
@@ -104,44 +104,52 @@
     return this;
   }
 
+  @NotNull
   public List<ChangeSet> call() throws VcsException {
-    MercurialCommandLine cli = createCommandLine();
-    cli.setCharset(Charset.forName("UTF-8"));
-    cli.addParameters("--encoding", "UTF-8");
-    cli.addParameter("log");
-    cli.addParameter("-v");
-    if (myTemplate != null)
-      cli.addParameter("--style=" + myTemplate.getTemplate().getAbsolutePath());
-    if (myBranchName != null) {
-      cli.addParameter("-b");
-      cli.addParameter(myBranchName);
-    }
-    cli.addParameter("-r");
-    if (myRevsets != null) {
-      cli.addParameter(myRevsets);
-    } else {
-      String from = myFromId != null ? myFromId : "0";
-      String to = myToId != null ? myToId : "tip";
-      cli.addParameter(from + ":" + to);
-    }
-    if (myLimit != null) {
-      cli.addParameter("--limit");
-      cli.addParameter(myLimit.toString());
-    }
+    return myTemplate.withTemplate(new MercurialLogTemplate.WithTemplate<List<ChangeSet>>() {
+      @NotNull
+      public List<ChangeSet> action(@NotNull File template) throws VcsException {
+        final MercurialCommandLine cli = createCommandLine();
+        cli.setCharset(Charset.forName("UTF-8"));
+        cli.addParameters("--encoding", "UTF-8");
+        cli.addParameter("log");
+        cli.addParameter("-v");
+        if (myTemplate != null) {
+          cli.addParameter("--style=" + template.getAbsolutePath());
+        }
 
-    cli.addParameters(myFiles);
+        if (myBranchName != null) {
+          cli.addParameter("-b");
+          cli.addParameter(myBranchName);
+        }
+        cli.addParameter("-r");
+        if (myRevsets != null) {
+          cli.addParameter(myRevsets);
+        } else {
+          String from = myFromId != null ? myFromId : "0";
+          String to = myToId != null ? myToId : "tip";
+          cli.addParameter(from + ":" + to);
+        }
+        if (myLimit != null) {
+          cli.addParameter("--limit");
+          cli.addParameter(myLimit.toString());
+        }
 
-    CommandResult res = runCommand(cli);
-    String output = res.getStdout();
-    try {
-      List<ChangeSet> changes = parseChangeSetsXml(output);
-      if (myCalculateParents)
-        assignTrivialParents(changes);
-      return changes;
-    } catch (Exception e) {
-      LOG.error("Error while parsing log output:\n" + output, e);
-      throw new VcsException("Error while parsing log output, see teamcity-vcs.log for details", e);
-    }
+        cli.addParameters(myFiles);
+
+        final CommandResult res = runCommand(cli);
+        final String output = res.getStdout();
+        try {
+          List<ChangeSet> changes = parseChangeSetsXml(output);
+          if (myCalculateParents)
+            assignTrivialParents(changes);
+          return changes;
+        } catch (Exception e) {
+          LOG.error("Error while parsing log output:\n" + output, e);
+          throw new VcsException("Error while parsing log output, see teamcity-vcs.log for details", e);
+        }
+      }
+    });
   }
 
   private List<ChangeSet> parseChangeSetsXml(@NotNull final String xml) throws SAXException, ParserConfigurationException, IOException {