annotate hgext/convert/darcs.py @ 12252:4481f8a93c7a stable

convert/darcs: handle non-ASCII metadata in darcs changelog (issue2354) Given a commit author or message with non-ASCII characters in a darcs repo, convert would raise a UnicodeEncodeError when adding changesets to the hg changelog. This happened because etree returns back unicode objects for any text it can't encode into ASCII. convert was passing these objects to changelog.add(), which would then attempt encoding.fromlocal() on them. This patch ensures converter_source.recode() is called on each piece of commit data returned by etree. (Also note that darcs is currently encoding agnostic and will print out whatever is in a patch's metadata byte-for-byte, even in the XML changelog.)
author Brodie Rao <brodie@bitheap.org>
date Fri, 10 Sep 2010 09:30:50 -0500
parents 33010ff1fd6f
children 84ceedcfeb6a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8250
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
1 # darcs.py - darcs support for the convert extension
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
2 #
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
3 # Copyright 2007-2009 Matt Mackall <mpm@selenic.com> and others
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
4 #
1b60efdb8bc5 convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents: 8209
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9712
diff changeset
6 # GNU General Public License version 2 or any later version.
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
7
5512
8cd26ccc68f8 convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents: 5498
diff changeset
8 from common import NoRepo, checktool, commandline, commit, converter_source
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
9 from mercurial.i18n import _
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
10 from mercurial import util
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
11 import os, shutil, tempfile
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
12
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
13 # The naming drift of ElementTree is fun!
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
14
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
15 try:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
16 from xml.etree.cElementTree import ElementTree
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
17 except ImportError:
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
18 try:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
19 from xml.etree.ElementTree import ElementTree
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
20 except ImportError:
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
21 try:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
22 from elementtree.cElementTree import ElementTree
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
23 except ImportError:
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
24 try:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
25 from elementtree.ElementTree import ElementTree
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
26 except ImportError:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
27 ElementTree = None
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
28
5512
8cd26ccc68f8 convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents: 5498
diff changeset
29 class darcs_source(converter_source, commandline):
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
30 def __init__(self, ui, path, rev=None):
5512
8cd26ccc68f8 convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents: 5498
diff changeset
31 converter_source.__init__(self, ui, path, rev=rev)
8cd26ccc68f8 convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents: 5498
diff changeset
32 commandline.__init__(self, ui, 'darcs')
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
33
5520
cc3af86ab6fe test-convert-darcs: skip if we can't find the elementtree module
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5481
diff changeset
34 # check for _darcs, ElementTree, _darcs/inventory so that we can
cc3af86ab6fe test-convert-darcs: skip if we can't find the elementtree module
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5481
diff changeset
35 # easily skip test-convert-darcs if ElementTree is not around
7973
db3a68fd9387 convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents: 7609
diff changeset
36 if not os.path.exists(os.path.join(path, '_darcs', 'inventories')):
10939
9f6731b03906 convert: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents: 10938
diff changeset
37 raise NoRepo(_("%s does not look like a darcs repository") % path)
7973
db3a68fd9387 convert: attempt to check repo type before checking for tool
Matt Mackall <mpm@selenic.com>
parents: 7609
diff changeset
38
5520
cc3af86ab6fe test-convert-darcs: skip if we can't find the elementtree module
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5481
diff changeset
39 if not os.path.exists(os.path.join(path, '_darcs')):
10939
9f6731b03906 convert: mark strings for translation
Martin Geisler <mg@lazybytes.net>
parents: 10938
diff changeset
40 raise NoRepo(_("%s does not look like a darcs repository") % path)
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
41
5497
f0a3918abd42 convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents: 5412
diff changeset
42 checktool('darcs')
9242
6fd3f795e908 issue1251: bail if darcs version is too old
Bryan O'Sullivan <bos@serpentine.com>
parents: 8250
diff changeset
43 version = self.run0('--version').splitlines()[0].strip()
6fd3f795e908 issue1251: bail if darcs version is too old
Bryan O'Sullivan <bos@serpentine.com>
parents: 8250
diff changeset
44 if version < '2.1':
6fd3f795e908 issue1251: bail if darcs version is too old
Bryan O'Sullivan <bos@serpentine.com>
parents: 8250
diff changeset
45 raise util.Abort(_('darcs version 2.1 or newer needed (found %r)') %
6fd3f795e908 issue1251: bail if darcs version is too old
Bryan O'Sullivan <bos@serpentine.com>
parents: 8250
diff changeset
46 version)
5497
f0a3918abd42 convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents: 5412
diff changeset
47
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
48 if ElementTree is None:
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
49 raise util.Abort(_("Python ElementTree module is not available"))
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
50
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
51 self.path = os.path.realpath(path)
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
52
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
53 self.lastrev = None
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
54 self.changes = {}
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
55 self.parents = {}
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
56 self.tags = {}
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
57
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
58 def before(self):
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
59 self.tmppath = tempfile.mkdtemp(
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
60 prefix='convert-' + os.path.basename(self.path) + '-')
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
61 output, status = self.run('init', repodir=self.tmppath)
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
62 self.checkexit(status)
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
63
5512
8cd26ccc68f8 convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents: 5498
diff changeset
64 tree = self.xml('changes', xml_output=True, summary=True,
8cd26ccc68f8 convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents: 5498
diff changeset
65 repodir=self.path)
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
66 tagname = None
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
67 child = None
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
68 for elt in tree.findall('patch'):
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
69 node = elt.get('hash')
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
70 name = elt.findtext('name', '')
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
71 if name.startswith('TAG '):
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
72 tagname = name[4:].strip()
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
73 elif tagname is not None:
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
74 self.tags[tagname] = node
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
75 tagname = None
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
76 self.changes[node] = elt
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
77 self.parents[child] = [node]
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
78 child = node
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
79 self.parents[child] = []
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
80
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
81 def after(self):
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 9242
diff changeset
82 self.ui.debug('cleaning up %s\n' % self.tmppath)
5362
4ad2a18aff42 convert: fix a few residual bugs in darcs importer
Bryan O'Sullivan <bos@serpentine.com>
parents: 5359
diff changeset
83 shutil.rmtree(self.tmppath, ignore_errors=True)
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
84
5512
8cd26ccc68f8 convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents: 5498
diff changeset
85 def xml(self, cmd, **kwargs):
12252
4481f8a93c7a convert/darcs: handle non-ASCII metadata in darcs changelog (issue2354)
Brodie Rao <brodie@bitheap.org>
parents: 11134
diff changeset
86 # NOTE: darcs is currently encoding agnostic and will print
4481f8a93c7a convert/darcs: handle non-ASCII metadata in darcs changelog (issue2354)
Brodie Rao <brodie@bitheap.org>
parents: 11134
diff changeset
87 # patch metadata byte-for-byte, even in the XML changelog.
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
88 etree = ElementTree()
5512
8cd26ccc68f8 convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents: 5498
diff changeset
89 fp = self._run(cmd, **kwargs)
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
90 etree.parse(fp)
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
91 self.checkexit(fp.close())
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
92 return etree.getroot()
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
93
9527
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
94 def manifest(self):
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
95 man = []
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
96 output, status = self.run('show', 'files', no_directories=True,
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
97 repodir=self.tmppath)
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
98 self.checkexit(status)
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
99 for line in output.split('\n'):
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
100 path = line[2:]
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
101 if path:
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
102 man.append(path)
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
103 return man
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
104
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
105 def getheads(self):
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
106 return self.parents[None]
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
107
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
108 def getcommit(self, rev):
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
109 elt = self.changes[rev]
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
110 date = util.strdate(elt.get('local_date'), '%a %b %d %H:%M:%S %Z %Y')
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
111 desc = elt.findtext('name') + '\n' + elt.findtext('comment', '')
12252
4481f8a93c7a convert/darcs: handle non-ASCII metadata in darcs changelog (issue2354)
Brodie Rao <brodie@bitheap.org>
parents: 11134
diff changeset
112 # etree can return unicode objects for name, comment, and author,
4481f8a93c7a convert/darcs: handle non-ASCII metadata in darcs changelog (issue2354)
Brodie Rao <brodie@bitheap.org>
parents: 11134
diff changeset
113 # so recode() is used to ensure str objects are emitted.
4481f8a93c7a convert/darcs: handle non-ASCII metadata in darcs changelog (issue2354)
Brodie Rao <brodie@bitheap.org>
parents: 11134
diff changeset
114 return commit(author=self.recode(elt.get('author')),
4481f8a93c7a convert/darcs: handle non-ASCII metadata in darcs changelog (issue2354)
Brodie Rao <brodie@bitheap.org>
parents: 11134
diff changeset
115 date=util.datestr(date),
4481f8a93c7a convert/darcs: handle non-ASCII metadata in darcs changelog (issue2354)
Brodie Rao <brodie@bitheap.org>
parents: 11134
diff changeset
116 desc=self.recode(desc).strip(),
4481f8a93c7a convert/darcs: handle non-ASCII metadata in darcs changelog (issue2354)
Brodie Rao <brodie@bitheap.org>
parents: 11134
diff changeset
117 parents=self.parents[rev])
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
118
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
119 def pull(self, rev):
5512
8cd26ccc68f8 convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents: 5498
diff changeset
120 output, status = self.run('pull', self.path, all=True,
8cd26ccc68f8 convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents: 5498
diff changeset
121 match='hash %s' % rev,
8cd26ccc68f8 convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents: 5498
diff changeset
122 no_test=True, no_posthook=True,
8cd26ccc68f8 convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents: 5498
diff changeset
123 external_merge='/bin/false',
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
124 repodir=self.tmppath)
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
125 if status:
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
126 if output.find('We have conflicts in') == -1:
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
127 self.checkexit(status, output)
5512
8cd26ccc68f8 convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents: 5498
diff changeset
128 output, status = self.run('revert', all=True, repodir=self.tmppath)
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
129 self.checkexit(status, output)
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
130
9712
18b134ef294c kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9541
diff changeset
131 def getchanges(self, rev):
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
132 copies = {}
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
133 changes = []
9527
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
134 man = None
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
135 for elt in self.changes[rev].find('summary').getchildren():
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
136 if elt.tag in ('add_directory', 'remove_directory'):
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
137 continue
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
138 if elt.tag == 'move':
9527
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
139 if man is None:
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
140 man = self.manifest()
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
141 source, dest = elt.get('from'), elt.get('to')
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
142 if source in man:
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
143 # File move
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
144 changes.append((source, rev))
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
145 changes.append((dest, rev))
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
146 copies[dest] = source
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
147 else:
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
148 # Directory move, deduce file moves from manifest
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
149 source = source + '/'
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
150 for f in man:
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
151 if not f.startswith(source):
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
152 continue
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
153 fdest = dest + '/' + f[len(source):]
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
154 changes.append((f, rev))
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
155 changes.append((fdest, rev))
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
156 copies[fdest] = f
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
157 else:
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
158 changes.append((elt.text.strip(), rev))
9527
b3c13e721593 convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents: 9526
diff changeset
159 self.pull(rev)
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
160 self.lastrev = rev
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 7973
diff changeset
161 return sorted(changes), copies
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
162
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
163 def getfile(self, name, rev):
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
164 if rev != self.lastrev:
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
165 raise util.Abort(_('internal calling inconsistency'))
11134
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10939
diff changeset
166 path = os.path.join(self.tmppath, name)
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10939
diff changeset
167 data = open(path, 'rb').read()
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10939
diff changeset
168 mode = os.lstat(path).st_mode
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10939
diff changeset
169 mode = (mode & 0111) and 'x' or ''
33010ff1fd6f convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents: 10939
diff changeset
170 return data, mode
5359
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
171
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
172 def gettags(self):
6b6104430964 convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
173 return self.tags