Mercurial > hg
annotate hgext/convert/darcs.py @ 41640:e06d91bc504b
test: use `printenv.py --line` in `test-http-bundle1.t`
This makes the output easier to update and read.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Sat, 09 Feb 2019 01:20:35 +0100 |
parents | 2c2e82469b89 |
children | 2372284d9457 |
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 | 6 # GNU General Public License version 2 or any later version. |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
7 from __future__ import absolute_import |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
8 |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
9 import errno |
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
10 import os |
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
11 import re |
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
12 import shutil |
38165
2ce60954b1b7
py3: wrap tempfile.mkdtemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents:
36607
diff
changeset
|
13 |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
14 from mercurial.i18n import _ |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
15 from mercurial import ( |
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
16 error, |
38165
2ce60954b1b7
py3: wrap tempfile.mkdtemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents:
36607
diff
changeset
|
17 pycompat, |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
18 util, |
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
19 ) |
36607
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
35176
diff
changeset
|
20 from mercurial.utils import dateutil |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
21 from . import common |
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
22 NoRepo = common.NoRepo |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
23 |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
24 # The naming drift of ElementTree is fun! |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
25 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
26 try: |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
27 import xml.etree.cElementTree.ElementTree as ElementTree |
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
28 import xml.etree.cElementTree.XMLParser as XMLParser |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
29 except ImportError: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
30 try: |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
31 import xml.etree.ElementTree.ElementTree as ElementTree |
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
32 import xml.etree.ElementTree.XMLParser as XMLParser |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
33 except ImportError: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
34 try: |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
35 import elementtree.cElementTree.ElementTree as ElementTree |
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
36 import elementtree.cElementTree.XMLParser as XMLParser |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
37 except ImportError: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
38 try: |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
39 import elementtree.ElementTree.ElementTree as ElementTree |
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
40 import elementtree.ElementTree.XMLParser as XMLParser |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
41 except ImportError: |
15457
1470f8b00694
check-code: enable camelcase check, fix up problems
Matt Mackall <mpm@selenic.com>
parents:
15381
diff
changeset
|
42 pass |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
43 |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
44 class darcs_source(common.converter_source, common.commandline): |
35176
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
28368
diff
changeset
|
45 def __init__(self, ui, repotype, path, revs=None): |
671aba341d90
convert: save an indicator of the repo type for sources and sinks
Matt Harbison <matt_harbison@yahoo.com>
parents:
28368
diff
changeset
|
46 common.converter_source.__init__(self, ui, repotype, path, revs=revs) |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
47 common.commandline.__init__(self, ui, 'darcs') |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
48 |
12393
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
49 # check for _darcs, ElementTree so that we can easily skip |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
50 # test-convert-darcs if ElementTree is not around |
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
|
51 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
|
52 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
|
53 |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
54 common.checktool('darcs') |
9242
6fd3f795e908
issue1251: bail if darcs version is too old
Bryan O'Sullivan <bos@serpentine.com>
parents:
8250
diff
changeset
|
55 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
|
56 if version < '2.1': |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25748
diff
changeset
|
57 raise error.Abort(_('darcs version 2.1 or newer needed (found %r)') |
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25748
diff
changeset
|
58 % version) |
5497
f0a3918abd42
convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents:
5412
diff
changeset
|
59 |
15457
1470f8b00694
check-code: enable camelcase check, fix up problems
Matt Mackall <mpm@selenic.com>
parents:
15381
diff
changeset
|
60 if "ElementTree" not in globals(): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25748
diff
changeset
|
61 raise error.Abort(_("Python ElementTree module is not available")) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
62 |
15381
c519cd8f0169
backout dbdb777502dc (issue3077) (issue3071)
Matt Mackall <mpm@selenic.com>
parents:
15355
diff
changeset
|
63 self.path = os.path.realpath(path) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
64 |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
65 self.lastrev = None |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
66 self.changes = {} |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
67 self.parents = {} |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
68 self.tags = {} |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
69 |
12393
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
70 # Check darcs repository format |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
71 format = self.format() |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
72 if format: |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
73 if format in ('darcs-1.0', 'hashed'): |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
74 raise NoRepo(_("%s repository format is unsupported, " |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
75 "please upgrade") % format) |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
76 else: |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
77 self.ui.warn(_('failed to detect repository format!')) |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
78 |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
79 def before(self): |
38165
2ce60954b1b7
py3: wrap tempfile.mkdtemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents:
36607
diff
changeset
|
80 self.tmppath = pycompat.mkdtemp( |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
81 prefix='convert-' + os.path.basename(self.path) + '-') |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
82 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
|
83 self.checkexit(status) |
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 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
|
86 repodir=self.path) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
87 tagname = None |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
88 child = None |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
89 for elt in tree.findall('patch'): |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
90 node = elt.get('hash') |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
91 name = elt.findtext('name', '') |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
92 if name.startswith('TAG '): |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
93 tagname = name[4:].strip() |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
94 elif tagname is not None: |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
95 self.tags[tagname] = node |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
96 tagname = None |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
97 self.changes[node] = elt |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
98 self.parents[child] = [node] |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
99 child = node |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
100 self.parents[child] = [] |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
101 |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
102 def after(self): |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9242
diff
changeset
|
103 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
|
104 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
|
105 |
12717
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
106 def recode(self, s, encoding=None): |
38312
79dd61a4554f
py3: replace `unicode` with pycompat.unicode
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38165
diff
changeset
|
107 if isinstance(s, pycompat.unicode): |
12717
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
108 # XMLParser returns unicode objects for anything it can't |
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
109 # encode into ASCII. We convert them back to str to get |
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
110 # recode's normal conversion behavior. |
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
111 s = s.encode('latin-1') |
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
112 return super(darcs_source, self).recode(s, encoding) |
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
113 |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5498
diff
changeset
|
114 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
|
115 # 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
|
116 # 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
|
117 etree = ElementTree() |
12717
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
118 # While we are decoding the XML as latin-1 to be as liberal as |
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
119 # possible, etree will still raise an exception if any |
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
120 # non-printable characters are in the XML changelog. |
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
121 parser = XMLParser(encoding='latin-1') |
17413
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
16514
diff
changeset
|
122 p = self._run(cmd, **kwargs) |
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
16514
diff
changeset
|
123 etree.parse(p.stdout, parser=parser) |
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
16514
diff
changeset
|
124 p.wait() |
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
16514
diff
changeset
|
125 self.checkexit(p.returncode) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
126 return etree.getroot() |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
127 |
12393
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
128 def format(self): |
38466
2c2e82469b89
convert: don't pass --no-files to "darcs show repo" command
Yuya Nishihara <yuya@tcha.org>
parents:
38312
diff
changeset
|
129 output, status = self.run('show', 'repo', repodir=self.path) |
12393
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
130 self.checkexit(status) |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
131 m = re.search(r'^\s*Format:\s*(.*)$', output, re.MULTILINE) |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
132 if not m: |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
133 return None |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
134 return ','.join(sorted(f.strip() for f in m.group(1).split(','))) |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
135 |
9527
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
136 def manifest(self): |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
137 man = [] |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
138 output, status = self.run('show', 'files', no_directories=True, |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
139 repodir=self.tmppath) |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
140 self.checkexit(status) |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
141 for line in output.split('\n'): |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
142 path = line[2:] |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
143 if path: |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
144 man.append(path) |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
145 return man |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
146 |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
147 def getheads(self): |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
148 return self.parents[None] |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
149 |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
150 def getcommit(self, rev): |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
151 elt = self.changes[rev] |
36607
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
35176
diff
changeset
|
152 dateformat = '%a %b %d %H:%M:%S %Z %Y' |
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
35176
diff
changeset
|
153 date = dateutil.strdate(elt.get('local_date'), dateformat) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
154 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
|
155 # 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
|
156 # so recode() is used to ensure str objects are emitted. |
36607
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
35176
diff
changeset
|
157 newdateformat = '%Y-%m-%d %H:%M:%S %1%2' |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
158 return common.commit(author=self.recode(elt.get('author')), |
36607
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
35176
diff
changeset
|
159 date=dateutil.datestr(date, newdateformat), |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
160 desc=self.recode(desc).strip(), |
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
161 parents=self.parents[rev]) |
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 pull(self, rev): |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5498
diff
changeset
|
164 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
|
165 match='hash %s' % rev, |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5498
diff
changeset
|
166 no_test=True, no_posthook=True, |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5498
diff
changeset
|
167 external_merge='/bin/false', |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
168 repodir=self.tmppath) |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
169 if status: |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
170 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
|
171 self.checkexit(status, output) |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5498
diff
changeset
|
172 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
|
173 self.checkexit(status, output) |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
174 |
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
175 def getchanges(self, rev, full): |
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
176 if full: |
26779
aaa33ec3c951
grammar: use does instead of do where appropriate
timeless@mozdev.org
parents:
26587
diff
changeset
|
177 raise error.Abort(_("convert from darcs does not support --full")) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
178 copies = {} |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
179 changes = [] |
9527
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
180 man = None |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
181 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
|
182 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
|
183 continue |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
184 if elt.tag == 'move': |
9527
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
185 if man is None: |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
186 man = self.manifest() |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
187 source, dest = elt.get('from'), elt.get('to') |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
188 if source in man: |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
189 # File move |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
190 changes.append((source, rev)) |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
191 changes.append((dest, rev)) |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
192 copies[dest] = source |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
193 else: |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
194 # Directory move, deduce file moves from manifest |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
195 source = source + '/' |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
196 for f in man: |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
197 if not f.startswith(source): |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
198 continue |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
199 fdest = dest + '/' + f[len(source):] |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
200 changes.append((f, rev)) |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
201 changes.append((fdest, rev)) |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
202 copies[fdest] = f |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
203 else: |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
204 changes.append((elt.text.strip(), rev)) |
9527
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
205 self.pull(rev) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
206 self.lastrev = rev |
24395
216fa1ba9993
convert: optimize convert of files that are unmodified from p2 in merges
Mads Kiilerich <madski@unity3d.com>
parents:
22300
diff
changeset
|
207 return sorted(changes), copies, set() |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
208 |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
209 def getfile(self, name, rev): |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
210 if rev != self.lastrev: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25748
diff
changeset
|
211 raise error.Abort(_('internal calling inconsistency')) |
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10939
diff
changeset
|
212 path = os.path.join(self.tmppath, name) |
22296
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
17413
diff
changeset
|
213 try: |
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
17413
diff
changeset
|
214 data = util.readfile(path) |
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
17413
diff
changeset
|
215 mode = os.lstat(path).st_mode |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25658
diff
changeset
|
216 except IOError as inst: |
22296
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
17413
diff
changeset
|
217 if inst.errno == errno.ENOENT: |
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
17413
diff
changeset
|
218 return None, None |
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
17413
diff
changeset
|
219 raise |
25658
e93036747902
global: mass rewrite to use modern octal syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24395
diff
changeset
|
220 mode = (mode & 0o111) and 'x' or '' |
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10939
diff
changeset
|
221 return data, mode |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
222 |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
223 def gettags(self): |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
224 return self.tags |