Mercurial > hg > mercurial
view mercurial-common/src/python/load-substates-command.py @ 712:eea966084204
fix whitespace
author | eugene.petrenko@jetbrains.com |
---|---|
date | Mon, 13 Jan 2014 15:22:15 +0100 |
parents | 7d9e79de81e6 |
children | 41013464149f |
line wrap: on
line source
#!/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 threading import Thread def load_substates_command(ui, repo, outputFile, **opts): """Tons of docs""" ui.write("Fetching commits...") def b64(x): if x is None or x == "": return "=====" 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": (load_substates_command, [ ], " [options] OUTPUT_FILE") } testedwith = '2.2.2' buglink = "@jonnyzzz"