changeset 1008:a890b9326f7e

merge
author Evgeny Pasynkov <evgeny.pasynkov@jetbrains.com>
date Fri, 19 Oct 2018 13:18:48 +0200
parents b29a61718d05 (diff) dc66807c0c28 (current diff)
children b05a042511da
files
diffstat 3 files changed, 166 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsCommand.java	Fri Oct 19 12:44:08 2018 +0300
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsCommand.java	Fri Oct 19 13:18:48 2018 +0200
@@ -16,7 +16,9 @@
 
 package jetbrains.buildServer.buildTriggers.vcs.mercurial.command;
 
-import jetbrains.buildServer.buildTriggers.vcs.mercurial.*;
+import jetbrains.buildServer.buildTriggers.vcs.mercurial.HgFileUtil;
+import jetbrains.buildServer.buildTriggers.vcs.mercurial.HgRepo;
+import jetbrains.buildServer.buildTriggers.vcs.mercurial.HgVersion;
 import jetbrains.buildServer.util.FileUtil;
 import jetbrains.buildServer.vcs.VcsException;
 import org.jetbrains.annotations.NotNull;
@@ -36,6 +38,7 @@
  */
 public class CommitsAndMountPointsCommand extends VcsRootCommand {
   private static final HgVersion REQUIRED_VERSION = new HgVersion(2, 0, 0);
+  private static final HgVersion VERSION_4_6 = new HgVersion(4, 6, 0);
   private final HgRepo myRepo;
 
   public CommitsAndMountPointsCommand(@NotNull final HgRepo hgRepo,
@@ -87,12 +90,17 @@
             @Nullable String hgsubstateNodeId);
   }
 
-  private void callImpl(@NotNull final File root,
+  private void callImpl(@NotNull final HgVersion hgVersion,
+                        @NotNull final File root,
                         @NotNull final Callback consumer) throws VcsException {
     final MercurialCommandLine cli = createCommandLine();
     cli.addParameter("--debug");
 
-    setupExtensionsFromResource(cli, root, "load-substates-command.py");
+    if (hgVersion.isEqualsOrGreaterThan(VERSION_4_6)) {
+      setupExtensionsFromResource(cli, root, "load-substates-command-46.py");
+    } else {
+      setupExtensionsFromResource(cli, root, "load-substates-command.py");
+    }
 
     cli.addParameter("load-substates");
     cli.addParameter(new File(root, "result").getPath());
@@ -132,7 +140,4 @@
       throw new VcsException("Failed to parse response files for 'load-substates' command. " + e.getMessage(), e);
     }
   }
-
-
-
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-common/src/python/load-substates-command-46.py	Fri Oct 19 13:18:48 2018 +0200
@@ -0,0 +1,154 @@
+#!/usr/bin/env python
+##
+##    Copyright 2000-2014 JetBrains
+##
+##     Licensed under the Apache License, Version 2.0 (the "License");
+##       you may not use this file except in compliance with the License.
+##      You may obtain a copy of the License at
+##
+##          http://www.apache.org/licenses/LICENSE-2.0
+##
+##       Unless required by applicable law or agreed to in writing, software
+##       distributed under the License is distributed on an "AS IS" BASIS,
+##       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+##       See the License for the specific language governing permissions and
+##       limitations under the License.
+##
+##
+##  http://www.gnu.org/licenses/gpl-faq.html#GPLModuleLicense
+##  http://www.gnu.org/licenses/license-list.html#apache2
+##  http://en.wikipedia.org/wiki/Apache_License#GPL_compatibility
+##
+##
+"""
+load-substates-command
+"""
+
+import base64
+from mercurial import util, node
+from mercurial.utils import dateutil
+from threading import Thread
+
+
+def load_substates_command(ui, repo, outputFile, **opts):
+    """Tons of docs"""
+
+    ui.write("Fetching commits...")
+
+    NONE = "====="
+
+    def b64(x):
+      if x is None or x == "":
+        return NONE
+      return base64.b64encode( x )
+
+    def fetch_commits():
+      ui.write("Iterating over commits...\n")
+      with open(outputFile + ".commits", "w", 5 * 1024 * 1024) as result:
+        result.write("format: prefix commitID commitHash num_parents parent branch num_tags tag user message date [.hgsub] [.hgsubstate]\n")
+        result.flush()
+
+        commit_to_substates = {}
+
+        def update_sub_states(ctx):
+          def filenode(ctx, filename, i):
+            if filename in ctx.files():
+              try:
+                return node.hex(ctx.filenode(filename))
+              except:
+                # file could have been deleted => so there would be no filenode for it
+                # this also means we should avoid parents as file source
+                return NONE
+            else:
+              for p in ctx.parents():
+                if commit_to_substates.has_key(p.hex()):
+                  v = commit_to_substates[p.hex()][i]
+                  if v != NONE:
+                    return v
+            return NONE
+
+          best_sub = filenode(ctx, ".hgsub", 0)
+          best_state = filenode(ctx, ".hgsubstate", 1)
+          commit_to_substates[ctx.hex()] = (best_sub, best_state)
+          return best_sub, best_state
+
+        for r in list(repo.changelog):
+          ctx = repo[r]
+
+          result.write("$$@@@@ ")                           # magic
+          result.write( str( ctx.rev() ) )                 # commit Num
+          result.write(" ")
+          result.write( ctx.hex() )                        # commit ID
+          result.write(" ")
+          result.write( str( len( ctx.parents()) ) )       # num parents
+
+          for p in ctx.parents():                          # parents
+             result.write(" ")
+             result.write(p.hex())
+
+          result.write(" ")
+          result.write( b64( ctx.branch() ) )              # commit branch
+
+          result.write(" ")
+          result.write( str( len( ctx.tags() ) ) )         # num tags
+
+          for tag in ctx.tags():                           # tags
+             result.write(" ")
+             result.write( b64 ( tag ) )
+
+          result.write(" ")                                 # user
+          result.write( b64( ctx.user()  ) )
+
+          result.write(" ")                                 # message
+          result.write( b64( ctx.description() ) )
+
+          result.write(" ")                                 # date
+          result.write( dateutil.datestr( ctx.date(), "%Y-%m-%dZ%H:%M:%ST%1%2") )
+
+          #resolve sub-repo mounts
+          (sub_node, state_node) = update_sub_states(ctx)
+          result.write(" " + sub_node + " " + state_node)
+          result.write("\n")
+
+        ui.write("Commits iteration completed")
+
+    def fetch_file_revisions(filename):
+      ui.write("Fetching revisions of " + filename + " file\n")
+      with open(outputFile + filename, "w", 5 * 1024 * 1024) as result:
+        result.write("format: prefix commitID base64(" + filename + ")\n")
+        result.flush()
+
+        log = repo.file(filename)
+        for r in log:
+          result.write("$$@@@@ " + node.hex(log.node(r)) + " " + b64(log.read(r)) + "\n")
+
+      ui.write("All revisions of file " + filename + " are fetched\n")
+
+    tasks = [
+        Thread(target=fetch_commits, args=[], name="Fetch commits graph"),
+        Thread(target=fetch_file_revisions, args=[".hgsub"], name="Fetch .hgsub"),
+        Thread(target=fetch_file_revisions, args=[".hgsubstate"], name="Fetch .hgsubstate"),
+    ]
+
+    for task in tasks:
+        task.start()
+
+    for task in tasks:
+        task.join()
+
+    ui.write("\n##Completed##\n")
+
+
+#so here goes command registration and options
+cmdtable = {
+    "load-substates": (load_substates_command, [ ], " [options] OUTPUT_FILE")
+}
+
+load_substates_command.norepo = False
+load_substates_command.optionalrepo = False
+load_substates_command.inferrepo = False
+load_substates_command.intents = None
+
+testedwith = '4.7.2'
+buglink = "upsource-support@jetbrains.com"
+
--- a/mercurial-common/src/python/load-substates-command.py	Fri Oct 19 12:44:08 2018 +0300
+++ b/mercurial-common/src/python/load-substates-command.py	Fri Oct 19 13:18:48 2018 +0200
@@ -146,8 +146,7 @@
 load_substates_command.norepo = False
 load_substates_command.optionalrepo = False
 load_substates_command.inferrepo = False
-load_substates_command.intents = None
 
-testedwith = '4.7.2'
+testedwith = '4.2.1'
 buglink = "upsource-support@jetbrains.com"