Mercurial > hg > mercurial
diff mercurial-common/src/python/load-substates-command.py @ 711:7d9e79de81e6
updated log-substates command that logs:
- all changes graph
- all subrepo-related infos
author | eugene.petrenko@jetbrains.com |
---|---|
date | Mon, 13 Jan 2014 15:04:03 +0100 |
parents | c27e501ed0c3 |
children | eea966084204 |
line wrap: on
line diff
--- a/mercurial-common/src/python/load-substates-command.py Wed Jan 08 22:47:35 2014 +0100 +++ b/mercurial-common/src/python/load-substates-command.py Mon Jan 13 15:04:03 2014 +0100 @@ -1,40 +1,121 @@ #!/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 - -Copyright 2014 JetBrains <eugene.petrenko@jetbrains.com> -Mercurial extension commands for JetBrains' Mercurial integration -''' +""" import base64 -from mercurial import util, node, scmutil, subrepo -from mercurial.i18n import _ -from os import path, makedirs +from mercurial import util, node +from threading import Thread def load_substates_command(ui, repo, outputFile, **opts): """Tons of docs""" - ui.write("Searching for mappings...\n") - - with open(outputFile, "w", 5 * 1024 * 1024) as result: - result.write("format: prefix commitID base64(.hgsub) base64(.hgsubstate) \n") - result.flush() + ui.write("Fetching commits...") - for r in repo.changelog: - ctx = repo[r] + def b64(x): + if x is None or x == "": + return "=====" - if '.hgsubstate' in ctx and '.hgsub' in ctx: - commitId = node.hex(ctx.node()) - result.write("$$@@@@ " + commitId + " " + base64.b64encode(ctx['.hgsub'].data()) + " " + base64.b64encode(ctx['.hgsubstate'].data()) + "\n") + return base64.b64encode( x ) + def fetch_commits(): + ui.write("Iterating over commits graph...") + with open(outputFile + ".commits", "w", 5 * 1024 * 1024) as result: + result.write("format: prefix commitID base64(.hgsub) base64(.hgsubstate) \n") + result.flush() + + for r in list(repo.changelog): + node = repo[r] + + result.write("$$@@@@ ") # magic + result.write( str( node.rev() ) ) # commit Num + result.write(" ") + result.write( node.hex() ) # commit ID + result.write(" ") + result.write( str( len( node.parents()) ) ) # num parents + + for p in node.parents(): # parents + result.write(" ") + result.write(p.hex()) + + result.write(" ") + result.write( b64( node.branch() ) ) # commit branch + + result.write(" ") + result.write( str( len( node.tags() ) ) ) # num tags + + for tag in node.tags(): # tags + result.write(" ") + result.write( b64 ( tag ) ) + + result.write(" ") # user + result.write( b64( node.user() ) ) + + result.write(" ") # message + result.write( b64( node.description() ) ) + + result.write(" ") # date + result.write( util.datestr( node.date(), "%Y-%m-%dZ%H:%M:%ST%1:%2") ) + + if ".hgsub" in node.files() or ".hgsubstate" in node.files(): + result.write(".hgsub") + + result.write("\n") + + ui.write("Commits iteration completed") + + def fetch_file_revisions(filename): + ui.write("All revisions of file " + filename + " are fetched\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-command": (load_substates_command, [ ], " [options] OUTPUT_FILE") + "load-substates": (load_substates_command, [ ], " [options] OUTPUT_FILE") } testedwith = '2.2.2'