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@715: NONE = "=====" eugene@715: eugene@711: def b64(x): eugene@711: if x is None or x == "": eugene@715: return NONE eugene@711: return base64.b64encode( x ) eugene@706: eugene@711: def fetch_commits(): eugene@714: ui.write("Iterating over commits...\n") eugene@711: with open(outputFile + ".commits", "w", 5 * 1024 * 1024) as result: eugene@715: result.write("format: prefix commitID commitHash num_parents parent branch num_tags tag user message date [.hgsub] [.hgsubstate]\n") eugene@711: result.flush() eugene@711: eugene@715: commit_to_substates = {} eugene@715: eugene@715: def update_sub_states(ctx): eugene@716: def filenode(ctx, filename, i): eugene@715: if filename in ctx.files(): eugene@715: try: eugene@715: return node.hex(ctx.filenode(filename)) eugene@715: except: eugene@715: # file could have been deleted => so there would be no filenode for it eugene@716: # this also means we should avoid parents as file source eugene@715: return NONE eugene@715: else: eugene@716: for p in ctx.parents(): eugene@716: if commit_to_substates.has_key(p.hex()): eugene@716: v = commit_to_substates[p.hex()][i] eugene@716: if v != NONE: eugene@716: return v eugene@715: return NONE eugene@715: eugene@716: best_sub = filenode(ctx, ".hgsub", 0) eugene@716: best_state = filenode(ctx, ".hgsubstate", 1) eugene@716: commit_to_substates[ctx.hex()] = (best_sub, best_state) eugene@716: return best_sub, best_state eugene@715: eugene@711: for r in list(repo.changelog): eugene@715: ctx = repo[r] eugene@711: eugene@711: result.write("$$@@@@ ") # magic eugene@715: result.write( str( ctx.rev() ) ) # commit Num eugene@711: result.write(" ") eugene@715: result.write( ctx.hex() ) # commit ID eugene@711: result.write(" ") eugene@715: result.write( str( len( ctx.parents()) ) ) # num parents eugene@711: eugene@715: for p in ctx.parents(): # parents eugene@711: result.write(" ") eugene@711: result.write(p.hex()) eugene@711: eugene@711: result.write(" ") eugene@715: result.write( b64( ctx.branch() ) ) # commit branch eugene@711: eugene@711: result.write(" ") eugene@715: result.write( str( len( ctx.tags() ) ) ) # num tags eugene@711: eugene@715: for tag in ctx.tags(): # tags eugene@711: result.write(" ") eugene@711: result.write( b64 ( tag ) ) eugene@711: eugene@711: result.write(" ") # user eugene@715: result.write( b64( ctx.user() ) ) eugene@711: eugene@711: result.write(" ") # message eugene@715: result.write( b64( ctx.description() ) ) eugene@711: eugene@711: result.write(" ") # date eugene@715: result.write( util.datestr( ctx.date(), "%Y-%m-%dZ%H:%M:%ST%1%2") ) eugene@711: eugene@715: #resolve sub-repo mounts eugene@715: (sub_node, state_node) = update_sub_states(ctx) eugene@715: result.write(" " + sub_node + " " + state_node) eugene@711: result.write("\n") eugene@711: eugene@711: ui.write("Commits iteration completed") eugene@711: eugene@711: def fetch_file_revisions(filename): eugene@714: ui.write("Fetching revisions of " + filename + " file\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@715: 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 = { victory@1044: b"load-substates": (load_substates_command, [ ], b" [options] OUTPUT_FILE") eugene@706: } eugene@706: dmitry@971: load_substates_command.norepo = False dmitry@971: load_substates_command.optionalrepo = False dmitry@971: load_substates_command.inferrepo = False eugene@706: pasynkov@1007: testedwith = '4.2.1' dmitry@971: buglink = "upsource-support@jetbrains.com" dmitry@971: