Show More
@@ -1,22 +1,19 b'' | |||
|
1 | 1 | # monotone support for the convert extension |
|
2 | 2 | |
|
3 | import os | |
|
4 | import re | |
|
5 | import time | |
|
3 | import os, re, time | |
|
6 | 4 | from mercurial import util |
|
5 | from common import NoRepo, commit, converter_source, checktool, commandline | |
|
6 | from mercurial.i18n import _ | |
|
7 | 7 | |
|
8 | from common import NoRepo, commit, converter_source, checktool | |
|
9 | ||
|
10 | class monotone_source(converter_source): | |
|
8 | class monotone_source(converter_source, commandline): | |
|
11 | 9 | def __init__(self, ui, path=None, rev=None): |
|
12 | 10 | converter_source.__init__(self, ui, path, rev) |
|
11 | commandline.__init__(self, ui, 'mtn') | |
|
13 | 12 | |
|
14 | 13 | self.ui = ui |
|
15 | 14 | self.path = path |
|
16 | 15 | |
|
17 | ||
|
18 | 16 | # regular expressions for parsing monotone output |
|
19 | ||
|
20 | 17 | space = r'\s*' |
|
21 | 18 | name = r'\s+"((?:[^"]|\\")*)"\s*' |
|
22 | 19 | value = name |
@@ -35,48 +32,38 b' class monotone_source(converter_source):' | |||
|
35 | 32 | self.attr_execute_re = re.compile(attr + '"mtn:execute"' + space + '"true"') |
|
36 | 33 | |
|
37 | 34 | # cached data |
|
38 | ||
|
39 | 35 | self.manifest_rev = None |
|
40 | 36 | self.manifest = None |
|
41 | 37 |
self.files = None |
|
42 | 38 |
self.dirs = None |
|
43 | 39 | |
|
44 | norepo = NoRepo("%s does not look like a monotone repo" % path) | |
|
40 | norepo = NoRepo (_("%s does not look like a monotone repo") % path) | |
|
45 | 41 | if not os.path.exists(path): |
|
46 | 42 | raise norepo |
|
47 | 43 | |
|
48 | 44 | checktool('mtn') |
|
49 | 45 | |
|
50 |
# test if there are a |
|
|
46 | # test if there are any revisions | |
|
51 | 47 | self.rev = None |
|
52 | 48 |
try |
|
53 | 49 | self.getheads() |
|
54 | 50 |
except |
|
55 | 51 |
raise norepo |
|
56 | ||
|
57 | 52 | self.rev = rev |
|
58 | 53 | |
|
59 | ||
|
60 | def mtncmd(self, arg): | |
|
61 | cmdline = "mtn -d %s automate %s" % (util.shellquote(self.path), arg) | |
|
62 | self.ui.debug(cmdline, '\n') | |
|
63 | p = util.popen(cmdline) | |
|
64 | result = p.read() | |
|
65 | if p.close(): | |
|
66 | raise IOError() | |
|
67 | return result | |
|
54 | def mtnrun(self, *args, **kwargs): | |
|
55 | kwargs['d'] = self.path | |
|
56 | return self.run0('automate', *args, **kwargs) | |
|
68 | 57 | |
|
69 | 58 | def mtnloadmanifest(self, rev): |
|
70 | 59 | if self.manifest_rev == rev: |
|
71 | 60 | return |
|
61 | self.manifest = self.mtnrun("get_manifest_of", rev).split("\n\n") | |
|
72 | 62 | self.manifest_rev = rev |
|
73 | self.manifest = self.mtncmd("get_manifest_of %s" % rev).split("\n\n") | |
|
63 | self.files = {} | |
|
64 | self.dirs = {} | |
|
74 | 65 | |
|
75 |
|
|
|
76 | files = {} | |
|
77 | dirs = {} | |
|
78 | ||
|
79 | for e in manifest: | |
|
66 | for e in self.manifest: | |
|
80 | 67 | m = self.file_re.match(e) |
|
81 | 68 |
if m: |
|
82 | 69 | attr = "" |
@@ -84,13 +71,10 b' class monotone_source(converter_source):' | |||
|
84 | 71 | node = m.group(2) |
|
85 | 72 | if self.attr_execute_re.match(e): |
|
86 | 73 | attr += "x" |
|
87 | files[name] = (node, attr) | |
|
74 | self.files[name] = (node, attr) | |
|
88 | 75 | m = self.dir_re.match(e) |
|
89 | 76 | if m: |
|
90 | dirs[m.group(1)] = True | |
|
91 | ||
|
92 | self.files = files | |
|
93 | self.dirs = dirs | |
|
77 | self.dirs[m.group(1)] = True | |
|
94 | 78 | |
|
95 | 79 | def mtnisfile(self, name, rev): |
|
96 | 80 | # a non-file could be a directory or a deleted or renamed file |
@@ -112,21 +96,13 b' class monotone_source(converter_source):' | |||
|
112 | 96 | def mtngetcerts(self, rev): |
|
113 | 97 | certs = {"author":"<missing>", "date":"<missing>", |
|
114 | 98 | "changelog":"<missing>", "branch":"<missing>"} |
|
115 |
cert_list = self.mtn |
|
|
99 | cert_list = self.mtnrun("certs", rev).split("\n\n") | |
|
116 | 100 | for e in cert_list: |
|
117 | 101 | m = self.cert_re.match(e) |
|
118 | 102 | if m: |
|
119 | 103 | certs[m.group(1)] = m.group(2) |
|
120 | 104 | return certs |
|
121 | 105 | |
|
122 | def mtngetparents(self, rev): | |
|
123 | parents = self.mtncmd("parents %s" % rev).strip("\n").split("\n") | |
|
124 | p = [] | |
|
125 | for x in parents: | |
|
126 | if len(x) >= 40: # blank revs have been seen otherwise | |
|
127 | p.append(x) | |
|
128 | return p | |
|
129 | ||
|
130 | 106 | def mtnrenamefiles(self, files, fromdir, todir): |
|
131 | 107 | renamed = {} |
|
132 | 108 | for tofile in files: |
@@ -139,13 +115,14 b' class monotone_source(converter_source):' | |||
|
139 | 115 | # implement the converter_source interface: |
|
140 | 116 | |
|
141 | 117 | def getheads(self): |
|
142 |
if not self.rev |
|
|
143 |
return self.mtn |
|
|
118 | if not self.rev: | |
|
119 | return self.mtnrun("leaves").splitlines() | |
|
144 | 120 | else: |
|
145 | 121 | return [self.rev] |
|
146 | 122 | |
|
147 | 123 | def getchanges(self, rev): |
|
148 | revision = self.mtncmd("get_revision %s" % rev).split("\n\n") | |
|
124 | #revision = self.mtncmd("get_revision %s" % rev).split("\n\n") | |
|
125 | revision = self.mtnrun("get_revision", rev).split("\n\n") | |
|
149 | 126 | files = {} |
|
150 | 127 | copies = {} |
|
151 | 128 | for e in revision: |
@@ -170,11 +147,10 b' class monotone_source(converter_source):' | |||
|
170 | 147 | if self.mtnisdir(toname, rev): |
|
171 | 148 | renamed = self.mtnrenamefiles(self.files, fromname, toname) |
|
172 | 149 | for tofile, fromfile in renamed.items(): |
|
173 |
self.ui.debug (("copying file in renamed dir from '%s' to '%s'" % (fromfile, tofile) |
|
|
150 | self.ui.debug (_("copying file in renamed dir from '%s' to '%s'") % (fromfile, tofile), '\n') | |
|
174 | 151 | files[tofile] = rev |
|
175 | 152 | for fromfile in renamed.values(): |
|
176 | 153 | files[fromfile] = rev |
|
177 | ||
|
178 | 154 | return (files.items(), copies) |
|
179 | 155 | |
|
180 | 156 | def getmode(self, name, rev): |
@@ -188,7 +164,10 b' class monotone_source(converter_source):' | |||
|
188 | 164 | def getfile(self, name, rev): |
|
189 | 165 | if not self.mtnisfile(name, rev): |
|
190 | 166 | raise IOError() # file was deleted or renamed |
|
191 | return self.mtncmd("get_file_of %s -r %s" % (util.shellquote(name), rev)) | |
|
167 | try: | |
|
168 | return self.mtnrun("get_file_of", name, r=rev) | |
|
169 | except: | |
|
170 | raise IOError() # file was deleted or renamed | |
|
192 | 171 | |
|
193 | 172 |
def getcommit(self, rev): |
|
194 | 173 | certs = self.mtngetcerts(rev) |
@@ -197,12 +176,12 b' class monotone_source(converter_source):' | |||
|
197 | 176 | date=util.datestr(util.strdate(certs["date"], "%Y-%m-%dT%H:%M:%S")), |
|
198 | 177 | desc=certs["changelog"], |
|
199 | 178 | rev=rev, |
|
200 |
parents=self.mtn |
|
|
179 | parents=self.mtnrun("parents", rev).splitlines(), | |
|
201 | 180 | branch=certs["branch"]) |
|
202 | 181 | |
|
203 | 182 | def gettags(self): |
|
204 | 183 | tags = {} |
|
205 |
for e in self.mtn |
|
|
184 | for e in self.mtnrun("tags").split("\n\n"): | |
|
206 | 185 | m = self.tag_re.match(e) |
|
207 | 186 | if m: |
|
208 | 187 | tags[m.group(1)] = m.group(2) |
General Comments 0
You need to be logged in to leave comments.
Login now