Mercurial > hg > mercurial
comparison mercurial-common/src/python/load-substates-command.py @ 715:be86907926ae
new approach: remember hg sub-state file hash per commit,
dump hash -> file, and log with refs
author | eugene.petrenko@jetbrains.com |
---|---|
date | Mon, 13 Jan 2014 18:51:13 +0100 |
parents | 78266f6904df |
children | 0607a0504129 |
comparison
equal
deleted
inserted
replaced
714:78266f6904df | 715:be86907926ae |
---|---|
32 def load_substates_command(ui, repo, outputFile, **opts): | 32 def load_substates_command(ui, repo, outputFile, **opts): |
33 """Tons of docs""" | 33 """Tons of docs""" |
34 | 34 |
35 ui.write("Fetching commits...") | 35 ui.write("Fetching commits...") |
36 | 36 |
37 NONE = "=====" | |
38 | |
37 def b64(x): | 39 def b64(x): |
38 if x is None or x == "": | 40 if x is None or x == "": |
39 return "=====" | 41 return NONE |
40 | |
41 return base64.b64encode( x ) | 42 return base64.b64encode( x ) |
42 | 43 |
43 def fetch_commits(): | 44 def fetch_commits(): |
44 ui.write("Iterating over commits...\n") | 45 ui.write("Iterating over commits...\n") |
45 with open(outputFile + ".commits", "w", 5 * 1024 * 1024) as result: | 46 with open(outputFile + ".commits", "w", 5 * 1024 * 1024) as result: |
46 result.write("format: prefix commitID commitHash num_parents parent branch num_tags tag user message date [.hgsub]\n") | 47 result.write("format: prefix commitID commitHash num_parents parent branch num_tags tag user message date [.hgsub] [.hgsubstate]\n") |
47 result.flush() | 48 result.flush() |
48 | 49 |
50 commit_to_substates = {} | |
51 | |
52 def update_sub_states(ctx): | |
53 def filenode(ctx, filename): | |
54 if filename in ctx.files(): | |
55 try: | |
56 return node.hex(ctx.filenode(filename)) | |
57 except: | |
58 # file could have been deleted => so there would be no filenode for it | |
59 return NONE | |
60 else: | |
61 return NONE | |
62 | |
63 def notnull(a, ctx, i): | |
64 if a != NONE: | |
65 return a | |
66 | |
67 for p in ctx.parents(): | |
68 if commit_to_substates.has_key(p): | |
69 v = commit_to_substates[p][i] | |
70 if v != NONE: | |
71 return v | |
72 return NONE | |
73 | |
74 best_sub = notnull(filenode(ctx, ".hgsub"), ctx, 0) | |
75 best_state = notnull(filenode(ctx, ".hgsubstate"), ctx, 1) | |
76 | |
77 commit_to_substates[ctx.node()] = (best_sub, best_state) | |
78 | |
79 return (best_sub, best_state) | |
80 | |
49 for r in list(repo.changelog): | 81 for r in list(repo.changelog): |
50 node = repo[r] | 82 ctx = repo[r] |
51 | 83 |
52 result.write("$$@@@@ ") # magic | 84 result.write("$$@@@@ ") # magic |
53 result.write( str( node.rev() ) ) # commit Num | 85 result.write( str( ctx.rev() ) ) # commit Num |
54 result.write(" ") | 86 result.write(" ") |
55 result.write( node.hex() ) # commit ID | 87 result.write( ctx.hex() ) # commit ID |
56 result.write(" ") | 88 result.write(" ") |
57 result.write( str( len( node.parents()) ) ) # num parents | 89 result.write( str( len( ctx.parents()) ) ) # num parents |
58 | 90 |
59 for p in node.parents(): # parents | 91 for p in ctx.parents(): # parents |
60 result.write(" ") | 92 result.write(" ") |
61 result.write(p.hex()) | 93 result.write(p.hex()) |
62 | 94 |
63 result.write(" ") | 95 result.write(" ") |
64 result.write( b64( node.branch() ) ) # commit branch | 96 result.write( b64( ctx.branch() ) ) # commit branch |
65 | 97 |
66 result.write(" ") | 98 result.write(" ") |
67 result.write( str( len( node.tags() ) ) ) # num tags | 99 result.write( str( len( ctx.tags() ) ) ) # num tags |
68 | 100 |
69 for tag in node.tags(): # tags | 101 for tag in ctx.tags(): # tags |
70 result.write(" ") | 102 result.write(" ") |
71 result.write( b64 ( tag ) ) | 103 result.write( b64 ( tag ) ) |
72 | 104 |
73 result.write(" ") # user | 105 result.write(" ") # user |
74 result.write( b64( node.user() ) ) | 106 result.write( b64( ctx.user() ) ) |
75 | 107 |
76 result.write(" ") # message | 108 result.write(" ") # message |
77 result.write( b64( node.description() ) ) | 109 result.write( b64( ctx.description() ) ) |
78 | 110 |
79 result.write(" ") # date | 111 result.write(" ") # date |
80 result.write( util.datestr( node.date(), "%Y-%m-%dZ%H:%M:%ST%1%2") ) | 112 result.write( util.datestr( ctx.date(), "%Y-%m-%dZ%H:%M:%ST%1%2") ) |
81 | 113 |
82 if ".hgsub" in node.files() or ".hgsubstate" in node.files(): | 114 #resolve sub-repo mounts |
83 result.write(" .hgsub") | 115 (sub_node, state_node) = update_sub_states(ctx) |
84 else: | 116 result.write(" " + sub_node + " " + state_node) |
85 result.write(" =====") | |
86 | |
87 result.write("\n") | 117 result.write("\n") |
88 | 118 |
89 ui.write("Commits iteration completed") | 119 ui.write("Commits iteration completed") |
90 | 120 |
91 def fetch_file_revisions(filename): | 121 def fetch_file_revisions(filename): |
94 result.write("format: prefix commitID base64(" + filename + ")\n") | 124 result.write("format: prefix commitID base64(" + filename + ")\n") |
95 result.flush() | 125 result.flush() |
96 | 126 |
97 log = repo.file(filename) | 127 log = repo.file(filename) |
98 for r in log: | 128 for r in log: |
99 result.write("$$@@@@ " + node.hex(log.node(r)) + " " + b64(log.read(r)) + "\n") | 129 result.write("$$@@@@ " + node.hex(log.node(r)) + " " + b64(log.read(r)) + "\n") |
100 | 130 |
101 ui.write("All revisions of file " + filename + " are fetched\n") | 131 ui.write("All revisions of file " + filename + " are fetched\n") |
102 | 132 |
103 tasks = [ | 133 tasks = [ |
104 Thread(target=fetch_commits, args=[], name="Fetch commits graph"), | 134 Thread(target=fetch_commits, args=[], name="Fetch commits graph"), |