##// END OF EJS Templates
convert: don't pass --no-files to "darcs show repo" command...
Yuya Nishihara -
r38484:2c2e8246 @54 default
parent child Browse files
Show More
@@ -1,225 +1,224 b''
1 # darcs.py - darcs support for the convert extension
1 # darcs.py - darcs support for the convert extension
2 #
2 #
3 # Copyright 2007-2009 Matt Mackall <mpm@selenic.com> and others
3 # Copyright 2007-2009 Matt Mackall <mpm@selenic.com> and others
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7 from __future__ import absolute_import
7 from __future__ import absolute_import
8
8
9 import errno
9 import errno
10 import os
10 import os
11 import re
11 import re
12 import shutil
12 import shutil
13
13
14 from mercurial.i18n import _
14 from mercurial.i18n import _
15 from mercurial import (
15 from mercurial import (
16 error,
16 error,
17 pycompat,
17 pycompat,
18 util,
18 util,
19 )
19 )
20 from mercurial.utils import dateutil
20 from mercurial.utils import dateutil
21 from . import common
21 from . import common
22 NoRepo = common.NoRepo
22 NoRepo = common.NoRepo
23
23
24 # The naming drift of ElementTree is fun!
24 # The naming drift of ElementTree is fun!
25
25
26 try:
26 try:
27 import xml.etree.cElementTree.ElementTree as ElementTree
27 import xml.etree.cElementTree.ElementTree as ElementTree
28 import xml.etree.cElementTree.XMLParser as XMLParser
28 import xml.etree.cElementTree.XMLParser as XMLParser
29 except ImportError:
29 except ImportError:
30 try:
30 try:
31 import xml.etree.ElementTree.ElementTree as ElementTree
31 import xml.etree.ElementTree.ElementTree as ElementTree
32 import xml.etree.ElementTree.XMLParser as XMLParser
32 import xml.etree.ElementTree.XMLParser as XMLParser
33 except ImportError:
33 except ImportError:
34 try:
34 try:
35 import elementtree.cElementTree.ElementTree as ElementTree
35 import elementtree.cElementTree.ElementTree as ElementTree
36 import elementtree.cElementTree.XMLParser as XMLParser
36 import elementtree.cElementTree.XMLParser as XMLParser
37 except ImportError:
37 except ImportError:
38 try:
38 try:
39 import elementtree.ElementTree.ElementTree as ElementTree
39 import elementtree.ElementTree.ElementTree as ElementTree
40 import elementtree.ElementTree.XMLParser as XMLParser
40 import elementtree.ElementTree.XMLParser as XMLParser
41 except ImportError:
41 except ImportError:
42 pass
42 pass
43
43
44 class darcs_source(common.converter_source, common.commandline):
44 class darcs_source(common.converter_source, common.commandline):
45 def __init__(self, ui, repotype, path, revs=None):
45 def __init__(self, ui, repotype, path, revs=None):
46 common.converter_source.__init__(self, ui, repotype, path, revs=revs)
46 common.converter_source.__init__(self, ui, repotype, path, revs=revs)
47 common.commandline.__init__(self, ui, 'darcs')
47 common.commandline.__init__(self, ui, 'darcs')
48
48
49 # check for _darcs, ElementTree so that we can easily skip
49 # check for _darcs, ElementTree so that we can easily skip
50 # test-convert-darcs if ElementTree is not around
50 # test-convert-darcs if ElementTree is not around
51 if not os.path.exists(os.path.join(path, '_darcs')):
51 if not os.path.exists(os.path.join(path, '_darcs')):
52 raise NoRepo(_("%s does not look like a darcs repository") % path)
52 raise NoRepo(_("%s does not look like a darcs repository") % path)
53
53
54 common.checktool('darcs')
54 common.checktool('darcs')
55 version = self.run0('--version').splitlines()[0].strip()
55 version = self.run0('--version').splitlines()[0].strip()
56 if version < '2.1':
56 if version < '2.1':
57 raise error.Abort(_('darcs version 2.1 or newer needed (found %r)')
57 raise error.Abort(_('darcs version 2.1 or newer needed (found %r)')
58 % version)
58 % version)
59
59
60 if "ElementTree" not in globals():
60 if "ElementTree" not in globals():
61 raise error.Abort(_("Python ElementTree module is not available"))
61 raise error.Abort(_("Python ElementTree module is not available"))
62
62
63 self.path = os.path.realpath(path)
63 self.path = os.path.realpath(path)
64
64
65 self.lastrev = None
65 self.lastrev = None
66 self.changes = {}
66 self.changes = {}
67 self.parents = {}
67 self.parents = {}
68 self.tags = {}
68 self.tags = {}
69
69
70 # Check darcs repository format
70 # Check darcs repository format
71 format = self.format()
71 format = self.format()
72 if format:
72 if format:
73 if format in ('darcs-1.0', 'hashed'):
73 if format in ('darcs-1.0', 'hashed'):
74 raise NoRepo(_("%s repository format is unsupported, "
74 raise NoRepo(_("%s repository format is unsupported, "
75 "please upgrade") % format)
75 "please upgrade") % format)
76 else:
76 else:
77 self.ui.warn(_('failed to detect repository format!'))
77 self.ui.warn(_('failed to detect repository format!'))
78
78
79 def before(self):
79 def before(self):
80 self.tmppath = pycompat.mkdtemp(
80 self.tmppath = pycompat.mkdtemp(
81 prefix='convert-' + os.path.basename(self.path) + '-')
81 prefix='convert-' + os.path.basename(self.path) + '-')
82 output, status = self.run('init', repodir=self.tmppath)
82 output, status = self.run('init', repodir=self.tmppath)
83 self.checkexit(status)
83 self.checkexit(status)
84
84
85 tree = self.xml('changes', xml_output=True, summary=True,
85 tree = self.xml('changes', xml_output=True, summary=True,
86 repodir=self.path)
86 repodir=self.path)
87 tagname = None
87 tagname = None
88 child = None
88 child = None
89 for elt in tree.findall('patch'):
89 for elt in tree.findall('patch'):
90 node = elt.get('hash')
90 node = elt.get('hash')
91 name = elt.findtext('name', '')
91 name = elt.findtext('name', '')
92 if name.startswith('TAG '):
92 if name.startswith('TAG '):
93 tagname = name[4:].strip()
93 tagname = name[4:].strip()
94 elif tagname is not None:
94 elif tagname is not None:
95 self.tags[tagname] = node
95 self.tags[tagname] = node
96 tagname = None
96 tagname = None
97 self.changes[node] = elt
97 self.changes[node] = elt
98 self.parents[child] = [node]
98 self.parents[child] = [node]
99 child = node
99 child = node
100 self.parents[child] = []
100 self.parents[child] = []
101
101
102 def after(self):
102 def after(self):
103 self.ui.debug('cleaning up %s\n' % self.tmppath)
103 self.ui.debug('cleaning up %s\n' % self.tmppath)
104 shutil.rmtree(self.tmppath, ignore_errors=True)
104 shutil.rmtree(self.tmppath, ignore_errors=True)
105
105
106 def recode(self, s, encoding=None):
106 def recode(self, s, encoding=None):
107 if isinstance(s, pycompat.unicode):
107 if isinstance(s, pycompat.unicode):
108 # XMLParser returns unicode objects for anything it can't
108 # XMLParser returns unicode objects for anything it can't
109 # encode into ASCII. We convert them back to str to get
109 # encode into ASCII. We convert them back to str to get
110 # recode's normal conversion behavior.
110 # recode's normal conversion behavior.
111 s = s.encode('latin-1')
111 s = s.encode('latin-1')
112 return super(darcs_source, self).recode(s, encoding)
112 return super(darcs_source, self).recode(s, encoding)
113
113
114 def xml(self, cmd, **kwargs):
114 def xml(self, cmd, **kwargs):
115 # NOTE: darcs is currently encoding agnostic and will print
115 # NOTE: darcs is currently encoding agnostic and will print
116 # patch metadata byte-for-byte, even in the XML changelog.
116 # patch metadata byte-for-byte, even in the XML changelog.
117 etree = ElementTree()
117 etree = ElementTree()
118 # While we are decoding the XML as latin-1 to be as liberal as
118 # While we are decoding the XML as latin-1 to be as liberal as
119 # possible, etree will still raise an exception if any
119 # possible, etree will still raise an exception if any
120 # non-printable characters are in the XML changelog.
120 # non-printable characters are in the XML changelog.
121 parser = XMLParser(encoding='latin-1')
121 parser = XMLParser(encoding='latin-1')
122 p = self._run(cmd, **kwargs)
122 p = self._run(cmd, **kwargs)
123 etree.parse(p.stdout, parser=parser)
123 etree.parse(p.stdout, parser=parser)
124 p.wait()
124 p.wait()
125 self.checkexit(p.returncode)
125 self.checkexit(p.returncode)
126 return etree.getroot()
126 return etree.getroot()
127
127
128 def format(self):
128 def format(self):
129 output, status = self.run('show', 'repo', no_files=True,
129 output, status = self.run('show', 'repo', repodir=self.path)
130 repodir=self.path)
131 self.checkexit(status)
130 self.checkexit(status)
132 m = re.search(r'^\s*Format:\s*(.*)$', output, re.MULTILINE)
131 m = re.search(r'^\s*Format:\s*(.*)$', output, re.MULTILINE)
133 if not m:
132 if not m:
134 return None
133 return None
135 return ','.join(sorted(f.strip() for f in m.group(1).split(',')))
134 return ','.join(sorted(f.strip() for f in m.group(1).split(',')))
136
135
137 def manifest(self):
136 def manifest(self):
138 man = []
137 man = []
139 output, status = self.run('show', 'files', no_directories=True,
138 output, status = self.run('show', 'files', no_directories=True,
140 repodir=self.tmppath)
139 repodir=self.tmppath)
141 self.checkexit(status)
140 self.checkexit(status)
142 for line in output.split('\n'):
141 for line in output.split('\n'):
143 path = line[2:]
142 path = line[2:]
144 if path:
143 if path:
145 man.append(path)
144 man.append(path)
146 return man
145 return man
147
146
148 def getheads(self):
147 def getheads(self):
149 return self.parents[None]
148 return self.parents[None]
150
149
151 def getcommit(self, rev):
150 def getcommit(self, rev):
152 elt = self.changes[rev]
151 elt = self.changes[rev]
153 dateformat = '%a %b %d %H:%M:%S %Z %Y'
152 dateformat = '%a %b %d %H:%M:%S %Z %Y'
154 date = dateutil.strdate(elt.get('local_date'), dateformat)
153 date = dateutil.strdate(elt.get('local_date'), dateformat)
155 desc = elt.findtext('name') + '\n' + elt.findtext('comment', '')
154 desc = elt.findtext('name') + '\n' + elt.findtext('comment', '')
156 # etree can return unicode objects for name, comment, and author,
155 # etree can return unicode objects for name, comment, and author,
157 # so recode() is used to ensure str objects are emitted.
156 # so recode() is used to ensure str objects are emitted.
158 newdateformat = '%Y-%m-%d %H:%M:%S %1%2'
157 newdateformat = '%Y-%m-%d %H:%M:%S %1%2'
159 return common.commit(author=self.recode(elt.get('author')),
158 return common.commit(author=self.recode(elt.get('author')),
160 date=dateutil.datestr(date, newdateformat),
159 date=dateutil.datestr(date, newdateformat),
161 desc=self.recode(desc).strip(),
160 desc=self.recode(desc).strip(),
162 parents=self.parents[rev])
161 parents=self.parents[rev])
163
162
164 def pull(self, rev):
163 def pull(self, rev):
165 output, status = self.run('pull', self.path, all=True,
164 output, status = self.run('pull', self.path, all=True,
166 match='hash %s' % rev,
165 match='hash %s' % rev,
167 no_test=True, no_posthook=True,
166 no_test=True, no_posthook=True,
168 external_merge='/bin/false',
167 external_merge='/bin/false',
169 repodir=self.tmppath)
168 repodir=self.tmppath)
170 if status:
169 if status:
171 if output.find('We have conflicts in') == -1:
170 if output.find('We have conflicts in') == -1:
172 self.checkexit(status, output)
171 self.checkexit(status, output)
173 output, status = self.run('revert', all=True, repodir=self.tmppath)
172 output, status = self.run('revert', all=True, repodir=self.tmppath)
174 self.checkexit(status, output)
173 self.checkexit(status, output)
175
174
176 def getchanges(self, rev, full):
175 def getchanges(self, rev, full):
177 if full:
176 if full:
178 raise error.Abort(_("convert from darcs does not support --full"))
177 raise error.Abort(_("convert from darcs does not support --full"))
179 copies = {}
178 copies = {}
180 changes = []
179 changes = []
181 man = None
180 man = None
182 for elt in self.changes[rev].find('summary').getchildren():
181 for elt in self.changes[rev].find('summary').getchildren():
183 if elt.tag in ('add_directory', 'remove_directory'):
182 if elt.tag in ('add_directory', 'remove_directory'):
184 continue
183 continue
185 if elt.tag == 'move':
184 if elt.tag == 'move':
186 if man is None:
185 if man is None:
187 man = self.manifest()
186 man = self.manifest()
188 source, dest = elt.get('from'), elt.get('to')
187 source, dest = elt.get('from'), elt.get('to')
189 if source in man:
188 if source in man:
190 # File move
189 # File move
191 changes.append((source, rev))
190 changes.append((source, rev))
192 changes.append((dest, rev))
191 changes.append((dest, rev))
193 copies[dest] = source
192 copies[dest] = source
194 else:
193 else:
195 # Directory move, deduce file moves from manifest
194 # Directory move, deduce file moves from manifest
196 source = source + '/'
195 source = source + '/'
197 for f in man:
196 for f in man:
198 if not f.startswith(source):
197 if not f.startswith(source):
199 continue
198 continue
200 fdest = dest + '/' + f[len(source):]
199 fdest = dest + '/' + f[len(source):]
201 changes.append((f, rev))
200 changes.append((f, rev))
202 changes.append((fdest, rev))
201 changes.append((fdest, rev))
203 copies[fdest] = f
202 copies[fdest] = f
204 else:
203 else:
205 changes.append((elt.text.strip(), rev))
204 changes.append((elt.text.strip(), rev))
206 self.pull(rev)
205 self.pull(rev)
207 self.lastrev = rev
206 self.lastrev = rev
208 return sorted(changes), copies, set()
207 return sorted(changes), copies, set()
209
208
210 def getfile(self, name, rev):
209 def getfile(self, name, rev):
211 if rev != self.lastrev:
210 if rev != self.lastrev:
212 raise error.Abort(_('internal calling inconsistency'))
211 raise error.Abort(_('internal calling inconsistency'))
213 path = os.path.join(self.tmppath, name)
212 path = os.path.join(self.tmppath, name)
214 try:
213 try:
215 data = util.readfile(path)
214 data = util.readfile(path)
216 mode = os.lstat(path).st_mode
215 mode = os.lstat(path).st_mode
217 except IOError as inst:
216 except IOError as inst:
218 if inst.errno == errno.ENOENT:
217 if inst.errno == errno.ENOENT:
219 return None, None
218 return None, None
220 raise
219 raise
221 mode = (mode & 0o111) and 'x' or ''
220 mode = (mode & 0o111) and 'x' or ''
222 return data, mode
221 return data, mode
223
222
224 def gettags(self):
223 def gettags(self):
225 return self.tags
224 return self.tags
General Comments 0
You need to be logged in to leave comments. Login now