annotate mercurial-common/src/python/load-substates-command-46.py @ 1103:ee62597cacc3 release/2022.10 tip

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