eugene@706: #!/usr/bin/env python eugene@711: ## eugene@711: ## Copyright 2000-2014 JetBrains eugene@711: ## eugene@711: ## Licensed under the Apache License, Version 2.0 (the "License"); eugene@711: ## you may not use this file except in compliance with the License. eugene@711: ## You may obtain a copy of the License at eugene@711: ## eugene@711: ## http://www.apache.org/licenses/LICENSE-2.0 eugene@711: ## eugene@711: ## Unless required by applicable law or agreed to in writing, software eugene@711: ## distributed under the License is distributed on an "AS IS" BASIS, eugene@711: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. eugene@711: ## See the License for the specific language governing permissions and eugene@711: ## limitations under the License. eugene@711: ## eugene@711: ## eugene@711: ## http://www.gnu.org/licenses/gpl-faq.html#GPLModuleLicense eugene@711: ## http://www.gnu.org/licenses/license-list.html#apache2 eugene@711: ## http://en.wikipedia.org/wiki/Apache_License#GPL_compatibility eugene@711: ## eugene@711: ## eugene@711: """ eugene@706: load-substates-command eugene@711: """ eugene@706: eugene@706: import base64 eugene@711: from mercurial import util, node eugene@711: from threading import Thread eugene@706: eugene@706: eugene@706: def load_substates_command(ui, repo, outputFile, **opts): eugene@706: """Tons of docs""" eugene@706: eugene@711: ui.write("Fetching commits...") eugene@706: eugene@711: def b64(x): eugene@711: if x is None or x == "": eugene@711: return "=====" eugene@706: eugene@711: return base64.b64encode( x ) eugene@706: eugene@711: def fetch_commits(): eugene@711: ui.write("Iterating over commits graph...") eugene@711: with open(outputFile + ".commits", "w", 5 * 1024 * 1024) as result: eugene@711: result.write("format: prefix commitID base64(.hgsub) base64(.hgsubstate) \n") eugene@711: result.flush() eugene@711: eugene@711: for r in list(repo.changelog): eugene@711: node = repo[r] eugene@711: eugene@711: result.write("$$@@@@ ") # magic eugene@711: result.write( str( node.rev() ) ) # commit Num eugene@711: result.write(" ") eugene@711: result.write( node.hex() ) # commit ID eugene@711: result.write(" ") eugene@711: result.write( str( len( node.parents()) ) ) # num parents eugene@711: eugene@711: for p in node.parents(): # parents eugene@711: result.write(" ") eugene@711: result.write(p.hex()) eugene@711: eugene@711: result.write(" ") eugene@711: result.write( b64( node.branch() ) ) # commit branch eugene@711: eugene@711: result.write(" ") eugene@711: result.write( str( len( node.tags() ) ) ) # num tags eugene@711: eugene@711: for tag in node.tags(): # tags eugene@711: result.write(" ") eugene@711: result.write( b64 ( tag ) ) eugene@711: eugene@711: result.write(" ") # user eugene@711: result.write( b64( node.user() ) ) eugene@711: eugene@711: result.write(" ") # message eugene@711: result.write( b64( node.description() ) ) eugene@711: eugene@711: result.write(" ") # date eugene@711: result.write( util.datestr( node.date(), "%Y-%m-%dZ%H:%M:%ST%1:%2") ) eugene@711: eugene@711: if ".hgsub" in node.files() or ".hgsubstate" in node.files(): eugene@712: result.write(" .hgsub") eugene@711: eugene@711: result.write("\n") eugene@711: eugene@711: ui.write("Commits iteration completed") eugene@711: eugene@711: def fetch_file_revisions(filename): eugene@711: ui.write("All revisions of file " + filename + " are fetched\n") eugene@711: with open(outputFile + filename, "w", 5 * 1024 * 1024) as result: eugene@711: result.write("format: prefix commitID base64(" + filename + ")\n") eugene@711: result.flush() eugene@711: eugene@711: log = repo.file(filename) eugene@711: for r in log: eugene@711: result.write("$$@@@@ " + node.hex(log.node(r)) + " " + b64(log.read(r)) + "\n") eugene@711: eugene@711: ui.write("All revisions of file " + filename + " are fetched\n") eugene@711: eugene@711: tasks = [ eugene@711: Thread(target=fetch_commits, args=[], name="Fetch commits graph"), eugene@711: Thread(target=fetch_file_revisions, args=[".hgsub"], name="Fetch .hgsub"), eugene@711: Thread(target=fetch_file_revisions, args=[".hgsubstate"], name="Fetch .hgsubstate"), eugene@711: ] eugene@711: eugene@711: for task in tasks: eugene@711: task.start() eugene@711: eugene@711: for task in tasks: eugene@711: task.join() eugene@706: eugene@706: ui.write("\n##Completed##\n") eugene@706: eugene@706: eugene@706: #so here goes command registration and options eugene@706: cmdtable = { eugene@711: "load-substates": (load_substates_command, [ ], " [options] OUTPUT_FILE") eugene@706: } eugene@706: eugene@706: testedwith = '2.2.2' eugene@706: buglink = "@jonnyzzz" eugene@706: