##// END OF EJS Templates
Merge with crew.
Bryan O'Sullivan -
r5360:b98c377b merge default
parent child Browse files
Show More
@@ -0,0 +1,137 b''
1 # darcs support for the convert extension
2
3 from common import NoRepo, commit, converter_source
4 from mercurial.i18n import _
5 from mercurial import util
6 import os, shutil, tempfile
7
8 # The naming drift of ElementTree is fun!
9
10 try: from xml.etree.cElementTree import ElementTree
11 except ImportError:
12 try: from xml.etree.ElementTree import ElementTree
13 except ImportError:
14 try: from elementtree.cElementTree import ElementTree
15 except ImportError:
16 try: from elementtree.ElementTree import ElementTree
17 except ImportError: ElementTree = None
18
19
20 class darcs_source(converter_source):
21 def __init__(self, ui, path, rev=None):
22 super(darcs_source, self).__init__(ui, path, rev=rev)
23
24 if not os.path.exists(os.path.join(path, '_darcs', 'inventory')):
25 raise NoRepo("couldn't open darcs repo %s" % path)
26
27 if ElementTree is None:
28 raise util.Abort(_("Python ElementTree module is not available"))
29
30 self.path = os.path.realpath(path)
31
32 self.lastrev = None
33 self.changes = {}
34 self.parents = {}
35 self.tags = {}
36
37 def before(self):
38 self.tmppath = tempfile.mkdtemp(
39 prefix='convert-' + os.path.basename(self.path) + '-')
40 output, status = self.run('init', repodir=self.tmppath)
41 self.checkexit(status)
42
43 tree = self.xml('changes', '--xml-output', '--summary')
44 tagname = None
45 child = None
46 for elt in tree.findall('patch'):
47 node = elt.get('hash')
48 name = elt.findtext('name', '')
49 if name.startswith('TAG '):
50 tagname = name[4:].strip()
51 elif tagname is not None:
52 self.tags[tagname] = node
53 tagname = None
54 self.changes[node] = elt
55 self.parents[child] = [node]
56 child = node
57 self.parents[child] = []
58
59 def after(self):
60 self.ui.debug('cleaning up %s\n' % self.tmppath)
61 #shutil.rmtree(self.tmppath, ignore_errors=True)
62
63 def _run(self, cmd, *args, **kwargs):
64 cmdline = 'darcs %s --repodir=%r %s </dev/null' % (
65 cmd, kwargs.get('repodir', self.path), ' '.join(args))
66 self.ui.debug(cmdline, '\n')
67 return os.popen(cmdline, 'r')
68
69 def run(self, cmd, *args, **kwargs):
70 fp = self._run(cmd, *args, **kwargs)
71 output = fp.read()
72 return output, fp.close()
73
74 def checkexit(self, status, output=''):
75 if status:
76 if output:
77 ui.warn(_('darcs error:\n'))
78 ui.warn(output)
79 msg = util.explain_exit(status)[0]
80 raise util.Abort(_('darcs %s') % msg)
81
82 def xml(self, cmd, *opts):
83 etree = ElementTree()
84 fp = self._run(cmd, *opts)
85 etree.parse(fp)
86 self.checkexit(fp.close())
87 return etree.getroot()
88
89 def getheads(self):
90 return self.parents[None]
91
92 def getcommit(self, rev):
93 elt = self.changes[rev]
94 date = util.strdate(elt.get('local_date'), '%a %b %d %H:%M:%S %Z %Y')
95 desc = elt.findtext('name') + '\n' + elt.findtext('comment', '')
96 return commit(author=elt.get('author'), date=util.datestr(date),
97 desc=desc.strip(), parents=self.parents[rev])
98
99 def pull(self, rev):
100 output, status = self.run('pull %r --all --match="hash %s"' %
101 (self.path, rev),
102 '--no-test', '--no-posthook',
103 '--external-merge=/bin/false',
104 repodir=self.tmppath)
105 if status:
106 if output.find('We have conflicts in') == -1:
107 self.checkexit(status, output)
108 output, status = self.run('revert --all', repodir=self.tmppath)
109 self.checkexit(status, output)
110
111 def getchanges(self, rev):
112 self.pull(rev)
113 copies = {}
114 changes = []
115 for elt in self.changes[rev].find('summary').getchildren():
116 if elt.tag in ('add_directory', 'remove_directory'):
117 continue
118 if elt.tag == 'move':
119 changes.append((elt.get('from'), rev))
120 copies[elt.get('from')] = elt.get('to')
121 else:
122 changes.append((elt.text.strip(), rev))
123 changes.sort()
124 self.lastrev = rev
125 return changes, copies
126
127 def getfile(self, name, rev):
128 if rev != self.lastrev:
129 raise util.Abort(_('internal calling inconsistency'))
130 return open(os.path.join(self.tmppath, name), 'rb').read()
131
132 def getmode(self, name, rev):
133 mode = os.lstat(os.path.join(self.tmppath, name)).st_mode
134 return (mode & 0111) and 'x' or ''
135
136 def gettags(self):
137 return self.tags
@@ -3,12 +3,15 b''
3 3 # vim: tw=80 ts=4 sw=4 noet
4 4 # -----------------------------------------------------------------------------
5 5 # Project : Basic Darcs to Mercurial conversion script
6 #
7 # *** DEPRECATED. Use the convert extension instead. This script will
8 # *** be removed soon.
9 #
6 10 # -----------------------------------------------------------------------------
7 11 # Authors : Sebastien Pierre <sebastien@xprima.com>
8 12 # TK Soh <teekaysoh@gmail.com>
9 13 # -----------------------------------------------------------------------------
10 14 # Creation : 24-May-2006
11 # Last mod : 05-Jun-2006
12 15 # -----------------------------------------------------------------------------
13 16
14 17 import os, sys
@@ -217,6 +220,7 b' if __name__ == "__main__":'
217 220 else:
218 221 print USAGE
219 222 sys.exit(-1)
223 print 'This command is deprecated. Use the convert extension instead.'
220 224 # Initializes the target repo
221 225 if not os.path.isdir(darcs_repo + "/_darcs"):
222 226 print "No darcs directory found at: " + darcs_repo
@@ -7,6 +7,7 b''
7 7
8 8 from common import NoRepo, converter_source, converter_sink
9 9 from cvs import convert_cvs
10 from darcs import darcs_source
10 11 from git import convert_git
11 12 from hg import mercurial_source, mercurial_sink
12 13 from subversion import convert_svn, debugsvnlog
@@ -18,7 +19,7 b' from mercurial.i18n import _'
18 19 commands.norepo += " convert debugsvnlog"
19 20
20 21 converters = [convert_cvs, convert_git, convert_svn, mercurial_source,
21 mercurial_sink]
22 mercurial_sink, darcs_source]
22 23
23 24 def convertsource(ui, path, **opts):
24 25 for c in converters:
@@ -235,6 +236,7 b' class converter(object):'
235 236
236 237 def convert(self):
237 238 try:
239 self.source.before()
238 240 self.dest.before()
239 241 self.source.setrevmap(self.map)
240 242 self.ui.status("scanning source...\n")
@@ -273,7 +275,10 b' class converter(object):'
273 275 self.cleanup()
274 276
275 277 def cleanup(self):
278 try:
276 279 self.dest.after()
280 finally:
281 self.source.after()
277 282 if self.revmapfilefd:
278 283 self.revmapfilefd.close()
279 284
@@ -367,9 +372,10 b' def convert(ui, src, dest=None, revmapfi'
367 372 """Convert a foreign SCM repository to a Mercurial one.
368 373
369 374 Accepted source formats:
370 - GIT
371 375 - CVS
372 - SVN
376 - Darcs
377 - git
378 - Subversion
373 379
374 380 Accepted destination formats:
375 381 - Mercurial
@@ -38,6 +38,12 b' class converter_source(object):'
38 38
39 39 self.encoding = 'utf-8'
40 40
41 def before(self):
42 pass
43
44 def after(self):
45 pass
46
41 47 def setrevmap(self, revmap):
42 48 """set the map of already-converted revisions"""
43 49 pass
@@ -156,7 +156,10 b' class mercurial_sink(converter_sink):'
156 156 class mercurial_source(converter_source):
157 157 def __init__(self, ui, path, rev=None):
158 158 converter_source.__init__(self, ui, path, rev)
159 try:
159 160 self.repo = hg.repository(self.ui, path)
161 except:
162 raise NoRepo("could not open hg repo %s as source" % path)
160 163 self.lastrev = None
161 164 self.lastctx = None
162 165
@@ -1468,7 +1468,7 b" def datestr(date=None, format='%a %b %d "
1468 1468 s += timezone_format % (-tz / 3600, ((-tz % 3600) / 60))
1469 1469 return s
1470 1470
1471 def strdate(string, format, defaults):
1471 def strdate(string, format, defaults=[]):
1472 1472 """parse a localized time string and return a (unixtime, offset) tuple.
1473 1473 if the string cannot be parsed, ValueError is raised."""
1474 1474 def timezone(string):
General Comments 0
You need to be logged in to leave comments. Login now