##// END OF EJS Templates
issue1251: bail if darcs version is too old
Bryan O'Sullivan -
r9242:6fd3f795 default
parent child Browse files
Show More
@@ -1,131 +1,135 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, incorporated herein by reference.
6 # GNU General Public License version 2, incorporated herein by reference.
7
7
8 from common import NoRepo, checktool, commandline, commit, converter_source
8 from common import NoRepo, checktool, commandline, commit, converter_source
9 from mercurial.i18n import _
9 from mercurial.i18n import _
10 from mercurial import util
10 from mercurial import util
11 import os, shutil, tempfile
11 import os, shutil, tempfile
12
12
13 # The naming drift of ElementTree is fun!
13 # The naming drift of ElementTree is fun!
14
14
15 try: from xml.etree.cElementTree import ElementTree
15 try: from xml.etree.cElementTree import ElementTree
16 except ImportError:
16 except ImportError:
17 try: from xml.etree.ElementTree import ElementTree
17 try: from xml.etree.ElementTree import ElementTree
18 except ImportError:
18 except ImportError:
19 try: from elementtree.cElementTree import ElementTree
19 try: from elementtree.cElementTree import ElementTree
20 except ImportError:
20 except ImportError:
21 try: from elementtree.ElementTree import ElementTree
21 try: from elementtree.ElementTree import ElementTree
22 except ImportError: ElementTree = None
22 except ImportError: ElementTree = None
23
23
24
24
25 class darcs_source(converter_source, commandline):
25 class darcs_source(converter_source, commandline):
26 def __init__(self, ui, path, rev=None):
26 def __init__(self, ui, path, rev=None):
27 converter_source.__init__(self, ui, path, rev=rev)
27 converter_source.__init__(self, ui, path, rev=rev)
28 commandline.__init__(self, ui, 'darcs')
28 commandline.__init__(self, ui, 'darcs')
29
29
30 # check for _darcs, ElementTree, _darcs/inventory so that we can
30 # check for _darcs, ElementTree, _darcs/inventory so that we can
31 # easily skip test-convert-darcs if ElementTree is not around
31 # easily skip test-convert-darcs if ElementTree is not around
32 if not os.path.exists(os.path.join(path, '_darcs', 'inventories')):
32 if not os.path.exists(os.path.join(path, '_darcs', 'inventories')):
33 raise NoRepo("%s does not look like a darcs repo" % path)
33 raise NoRepo("%s does not look like a darcs repo" % path)
34
34
35 if not os.path.exists(os.path.join(path, '_darcs')):
35 if not os.path.exists(os.path.join(path, '_darcs')):
36 raise NoRepo("%s does not look like a darcs repo" % path)
36 raise NoRepo("%s does not look like a darcs repo" % path)
37
37
38 checktool('darcs')
38 checktool('darcs')
39 version = self.run0('--version').splitlines()[0].strip()
40 if version < '2.1':
41 raise util.Abort(_('darcs version 2.1 or newer needed (found %r)') %
42 version)
39
43
40 if ElementTree is None:
44 if ElementTree is None:
41 raise util.Abort(_("Python ElementTree module is not available"))
45 raise util.Abort(_("Python ElementTree module is not available"))
42
46
43 self.path = os.path.realpath(path)
47 self.path = os.path.realpath(path)
44
48
45 self.lastrev = None
49 self.lastrev = None
46 self.changes = {}
50 self.changes = {}
47 self.parents = {}
51 self.parents = {}
48 self.tags = {}
52 self.tags = {}
49
53
50 def before(self):
54 def before(self):
51 self.tmppath = tempfile.mkdtemp(
55 self.tmppath = tempfile.mkdtemp(
52 prefix='convert-' + os.path.basename(self.path) + '-')
56 prefix='convert-' + os.path.basename(self.path) + '-')
53 output, status = self.run('init', repodir=self.tmppath)
57 output, status = self.run('init', repodir=self.tmppath)
54 self.checkexit(status)
58 self.checkexit(status)
55
59
56 tree = self.xml('changes', xml_output=True, summary=True,
60 tree = self.xml('changes', xml_output=True, summary=True,
57 repodir=self.path)
61 repodir=self.path)
58 tagname = None
62 tagname = None
59 child = None
63 child = None
60 for elt in tree.findall('patch'):
64 for elt in tree.findall('patch'):
61 node = elt.get('hash')
65 node = elt.get('hash')
62 name = elt.findtext('name', '')
66 name = elt.findtext('name', '')
63 if name.startswith('TAG '):
67 if name.startswith('TAG '):
64 tagname = name[4:].strip()
68 tagname = name[4:].strip()
65 elif tagname is not None:
69 elif tagname is not None:
66 self.tags[tagname] = node
70 self.tags[tagname] = node
67 tagname = None
71 tagname = None
68 self.changes[node] = elt
72 self.changes[node] = elt
69 self.parents[child] = [node]
73 self.parents[child] = [node]
70 child = node
74 child = node
71 self.parents[child] = []
75 self.parents[child] = []
72
76
73 def after(self):
77 def after(self):
74 self.ui.debug(_('cleaning up %s\n') % self.tmppath)
78 self.ui.debug(_('cleaning up %s\n') % self.tmppath)
75 shutil.rmtree(self.tmppath, ignore_errors=True)
79 shutil.rmtree(self.tmppath, ignore_errors=True)
76
80
77 def xml(self, cmd, **kwargs):
81 def xml(self, cmd, **kwargs):
78 etree = ElementTree()
82 etree = ElementTree()
79 fp = self._run(cmd, **kwargs)
83 fp = self._run(cmd, **kwargs)
80 etree.parse(fp)
84 etree.parse(fp)
81 self.checkexit(fp.close())
85 self.checkexit(fp.close())
82 return etree.getroot()
86 return etree.getroot()
83
87
84 def getheads(self):
88 def getheads(self):
85 return self.parents[None]
89 return self.parents[None]
86
90
87 def getcommit(self, rev):
91 def getcommit(self, rev):
88 elt = self.changes[rev]
92 elt = self.changes[rev]
89 date = util.strdate(elt.get('local_date'), '%a %b %d %H:%M:%S %Z %Y')
93 date = util.strdate(elt.get('local_date'), '%a %b %d %H:%M:%S %Z %Y')
90 desc = elt.findtext('name') + '\n' + elt.findtext('comment', '')
94 desc = elt.findtext('name') + '\n' + elt.findtext('comment', '')
91 return commit(author=elt.get('author'), date=util.datestr(date),
95 return commit(author=elt.get('author'), date=util.datestr(date),
92 desc=desc.strip(), parents=self.parents[rev])
96 desc=desc.strip(), parents=self.parents[rev])
93
97
94 def pull(self, rev):
98 def pull(self, rev):
95 output, status = self.run('pull', self.path, all=True,
99 output, status = self.run('pull', self.path, all=True,
96 match='hash %s' % rev,
100 match='hash %s' % rev,
97 no_test=True, no_posthook=True,
101 no_test=True, no_posthook=True,
98 external_merge='/bin/false',
102 external_merge='/bin/false',
99 repodir=self.tmppath)
103 repodir=self.tmppath)
100 if status:
104 if status:
101 if output.find('We have conflicts in') == -1:
105 if output.find('We have conflicts in') == -1:
102 self.checkexit(status, output)
106 self.checkexit(status, output)
103 output, status = self.run('revert', all=True, repodir=self.tmppath)
107 output, status = self.run('revert', all=True, repodir=self.tmppath)
104 self.checkexit(status, output)
108 self.checkexit(status, output)
105
109
106 def getchanges(self, rev):
110 def getchanges(self, rev):
107 self.pull(rev)
111 self.pull(rev)
108 copies = {}
112 copies = {}
109 changes = []
113 changes = []
110 for elt in self.changes[rev].find('summary').getchildren():
114 for elt in self.changes[rev].find('summary').getchildren():
111 if elt.tag in ('add_directory', 'remove_directory'):
115 if elt.tag in ('add_directory', 'remove_directory'):
112 continue
116 continue
113 if elt.tag == 'move':
117 if elt.tag == 'move':
114 changes.append((elt.get('from'), rev))
118 changes.append((elt.get('from'), rev))
115 copies[elt.get('from')] = elt.get('to')
119 copies[elt.get('from')] = elt.get('to')
116 else:
120 else:
117 changes.append((elt.text.strip(), rev))
121 changes.append((elt.text.strip(), rev))
118 self.lastrev = rev
122 self.lastrev = rev
119 return sorted(changes), copies
123 return sorted(changes), copies
120
124
121 def getfile(self, name, rev):
125 def getfile(self, name, rev):
122 if rev != self.lastrev:
126 if rev != self.lastrev:
123 raise util.Abort(_('internal calling inconsistency'))
127 raise util.Abort(_('internal calling inconsistency'))
124 return open(os.path.join(self.tmppath, name), 'rb').read()
128 return open(os.path.join(self.tmppath, name), 'rb').read()
125
129
126 def getmode(self, name, rev):
130 def getmode(self, name, rev):
127 mode = os.lstat(os.path.join(self.tmppath, name)).st_mode
131 mode = os.lstat(os.path.join(self.tmppath, name)).st_mode
128 return (mode & 0111) and 'x' or ''
132 return (mode & 0111) and 'x' or ''
129
133
130 def gettags(self):
134 def gettags(self):
131 return self.tags
135 return self.tags
General Comments 0
You need to be logged in to leave comments. Login now