comparison mercurial-common/src/python/load-substates-command-46.py @ 1007:b29a61718d05

UP-10121 fix extension compatibility break in 4.6
author pasynkov
date Thu, 18 Oct 2018 16:30:49 +0200
parents
children e7df2ef5064b 5bec80ce92ae
comparison
equal deleted inserted replaced
1005:3da1f4168906 1007:b29a61718d05
1 #!/usr/bin/env python
2 ##
3 ## Copyright 2000-2014 JetBrains
4 ##
5 ## Licensed under the Apache License, Version 2.0 (the "License");
6 ## you may not use this file except in compliance with the License.
7 ## You may obtain a copy of the License at
8 ##
9 ## http://www.apache.org/licenses/LICENSE-2.0
10 ##
11 ## Unless required by applicable law or agreed to in writing, software
12 ## distributed under the License is distributed on an "AS IS" BASIS,
13 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ## See the License for the specific language governing permissions and
15 ## limitations under the License.
16 ##
17 ##
18 ## http://www.gnu.org/licenses/gpl-faq.html#GPLModuleLicense
19 ## http://www.gnu.org/licenses/license-list.html#apache2
20 ## http://en.wikipedia.org/wiki/Apache_License#GPL_compatibility
21 ##
22 ##
23 """
24 load-substates-command
25 """
26
27 import base64
28 from mercurial import util, node
29 from mercurial.utils import dateutil
30 from threading import Thread
31
32
33 def load_substates_command(ui, repo, outputFile, **opts):
34 """Tons of docs"""
35
36 ui.write("Fetching commits...")
37
38 NONE = "====="
39
40 def b64(x):
41 if x is None or x == "":
42 return NONE
43 return base64.b64encode( x )
44
45 def fetch_commits():
46 ui.write("Iterating over commits...\n")
47 with open(outputFile + ".commits", "w", 5 * 1024 * 1024) as result:
48 result.write("format: prefix commitID commitHash num_parents parent branch num_tags tag user message date [.hgsub] [.hgsubstate]\n")
49 result.flush()
50
51 commit_to_substates = {}
52
53 def update_sub_states(ctx):
54 def filenode(ctx, filename, i):
55 if filename in ctx.files():
56 try:
57 return node.hex(ctx.filenode(filename))
58 except:
59 # file could have been deleted => so there would be no filenode for it
60 # this also means we should avoid parents as file source
61 return NONE
62 else:
63 for p in ctx.parents():
64 if commit_to_substates.has_key(p.hex()):
65 v = commit_to_substates[p.hex()][i]
66 if v != NONE:
67 return v
68 return NONE
69
70 best_sub = filenode(ctx, ".hgsub", 0)
71 best_state = filenode(ctx, ".hgsubstate", 1)
72 commit_to_substates[ctx.hex()] = (best_sub, best_state)
73 return best_sub, best_state
74
75 for r in list(repo.changelog):
76 ctx = repo[r]
77
78 result.write("$$@@@@ ") # magic
79 result.write( str( ctx.rev() ) ) # commit Num
80 result.write(" ")
81 result.write( ctx.hex() ) # commit ID
82 result.write(" ")
83 result.write( str( len( ctx.parents()) ) ) # num parents
84
85 for p in ctx.parents(): # parents
86 result.write(" ")
87 result.write(p.hex())
88
89 result.write(" ")
90 result.write( b64( ctx.branch() ) ) # commit branch
91
92 result.write(" ")
93 result.write( str( len( ctx.tags() ) ) ) # num tags
94
95 for tag in ctx.tags(): # tags
96 result.write(" ")
97 result.write( b64 ( tag ) )
98
99 result.write(" ") # user
100 result.write( b64( ctx.user() ) )
101
102 result.write(" ") # message
103 result.write( b64( ctx.description() ) )
104
105 result.write(" ") # date
106 result.write( dateutil.datestr( ctx.date(), "%Y-%m-%dZ%H:%M:%ST%1%2") )
107
108 #resolve sub-repo mounts
109 (sub_node, state_node) = update_sub_states(ctx)
110 result.write(" " + sub_node + " " + state_node)
111 result.write("\n")
112
113 ui.write("Commits iteration completed")
114
115 def fetch_file_revisions(filename):
116 ui.write("Fetching revisions of " + filename + " file\n")
117 with open(outputFile + filename, "w", 5 * 1024 * 1024) as result:
118 result.write("format: prefix commitID base64(" + filename + ")\n")
119 result.flush()
120
121 log = repo.file(filename)
122 for r in log:
123 result.write("$$@@@@ " + node.hex(log.node(r)) + " " + b64(log.read(r)) + "\n")
124
125 ui.write("All revisions of file " + filename + " are fetched\n")
126
127 tasks = [
128 Thread(target=fetch_commits, args=[], name="Fetch commits graph"),
129 Thread(target=fetch_file_revisions, args=[".hgsub"], name="Fetch .hgsub"),
130 Thread(target=fetch_file_revisions, args=[".hgsubstate"], name="Fetch .hgsubstate"),
131 ]
132
133 for task in tasks:
134 task.start()
135
136 for task in tasks:
137 task.join()
138
139 ui.write("\n##Completed##\n")
140
141
142 #so here goes command registration and options
143 cmdtable = {
144 "load-substates": (load_substates_command, [ ], " [options] OUTPUT_FILE")
145 }
146
147 load_substates_command.norepo = False
148 load_substates_command.optionalrepo = False
149 load_substates_command.inferrepo = False
150 load_substates_command.intents = None
151
152 testedwith = '4.7.2'
153 buglink = "upsource-support@jetbrains.com"
154