Mercurial > hg > mercurial
annotate mercurialcommon/src/python/loadsubstatescommand.py @ 712:eea966084204
fix whitespace
author  eugene.petrenko@jetbrains.com 

date  Mon, 13 Jan 2014 15:22:15 +0100 
parents  7d9e79de81e6 
children  41013464149f 
rev  line source 

706  1 #!/usr/bin/env python 
711
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

2 ## 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

3 ## Copyright 20002014 JetBrains 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

4 ## 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

5 ## Licensed under the Apache License, Version 2.0 (the "License"); 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

6 ## you may not use this file except in compliance with the License. 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

7 ## You may obtain a copy of the License at 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

8 ## 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

9 ## http://www.apache.org/licenses/LICENSE2.0 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

10 ## 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

11 ## Unless required by applicable law or agreed to in writing, software 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

12 ## distributed under the License is distributed on an "AS IS" BASIS, 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

13 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

14 ## See the License for the specific language governing permissions and 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

15 ## limitations under the License. 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

16 ## 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

17 ## 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

18 ## http://www.gnu.org/licenses/gplfaq.html#GPLModuleLicense 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

19 ## http://www.gnu.org/licenses/licenselist.html#apache2 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

20 ## http://en.wikipedia.org/wiki/Apache_License#GPL_compatibility 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

21 ## 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

22 ## 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

23 """ 
706  24 loadsubstatescommand 
711
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

25 """ 
706  26 
27 import base64  
711
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

28 from mercurial import util, node 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

29 from threading import Thread 
706  30 
31  
32 def load_substates_command(ui, repo, outputFile, **opts):  
33 """Tons of docs"""  
34  
711
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

35 ui.write("Fetching commits...") 
706  36 
711
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

37 def b64(x): 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

38 if x is None or x == "": 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

39 return "=====" 
706  40 
711
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

41 return base64.b64encode( x ) 
706  42 
711
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

43 def fetch_commits(): 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

44 ui.write("Iterating over commits graph...") 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

45 with open(outputFile + ".commits", "w", 5 * 1024 * 1024) as result: 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

46 result.write("format: prefix commitID base64(.hgsub) base64(.hgsubstate) \n") 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

47 result.flush() 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

48 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

49 for r in list(repo.changelog): 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

50 node = repo[r] 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

51 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

52 result.write("$$@@@@ ") # magic 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

53 result.write( str( node.rev() ) ) # commit Num 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

54 result.write(" ") 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

55 result.write( node.hex() ) # commit ID 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

56 result.write(" ") 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

57 result.write( str( len( node.parents()) ) ) # num parents 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

58 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

59 for p in node.parents(): # parents 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

60 result.write(" ") 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

61 result.write(p.hex()) 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

62 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

63 result.write(" ") 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

64 result.write( b64( node.branch() ) ) # commit branch 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

65 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

66 result.write(" ") 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

67 result.write( str( len( node.tags() ) ) ) # num tags 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

68 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

69 for tag in node.tags(): # tags 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

70 result.write(" ") 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

71 result.write( b64 ( tag ) ) 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

72 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

73 result.write(" ") # user 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

74 result.write( b64( node.user() ) ) 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

75 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

76 result.write(" ") # message 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

77 result.write( b64( node.description() ) ) 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

78 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

79 result.write(" ") # date 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

80 result.write( util.datestr( node.date(), "%Y%m%dZ%H:%M:%ST%1:%2") ) 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

81 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

82 if ".hgsub" in node.files() or ".hgsubstate" in node.files(): 
712  83 result.write(" .hgsub") 
711
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

84 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

85 result.write("\n") 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

86 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

87 ui.write("Commits iteration completed") 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

88 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

89 def fetch_file_revisions(filename): 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

90 ui.write("All revisions of file " + filename + " are fetched\n") 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

91 with open(outputFile + filename, "w", 5 * 1024 * 1024) as result: 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

92 result.write("format: prefix commitID base64(" + filename + ")\n") 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

93 result.flush() 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

94 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

95 log = repo.file(filename) 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

96 for r in log: 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

97 result.write("$$@@@@ " + node.hex(log.node(r)) + " " + b64(log.read(r)) + "\n") 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

98 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

99 ui.write("All revisions of file " + filename + " are fetched\n") 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

100 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

101 tasks = [ 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

102 Thread(target=fetch_commits, args=[], name="Fetch commits graph"), 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

103 Thread(target=fetch_file_revisions, args=[".hgsub"], name="Fetch .hgsub"), 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

104 Thread(target=fetch_file_revisions, args=[".hgsubstate"], name="Fetch .hgsubstate"), 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

105 ] 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

106 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

107 for task in tasks: 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

108 task.start() 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

109 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

110 for task in tasks: 
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

111 task.join() 
706  112 
113 ui.write("\n##Completed##\n")  
114  
115  
116 #so here goes command registration and options  
117 cmdtable = {  
711
7d9e79de81e6
updated logsubstates command that logs:
eugene.petrenko@jetbrains.com
parents:
706
diff
changeset

118 "loadsubstates": (load_substates_command, [ ], " [options] OUTPUT_FILE") 
706  119 } 
120  
121 testedwith = '2.2.2'  
122 buglink = "@jonnyzzz"  
123 