Mercurial > hg
annotate hgext/convert/darcs.py @ 52066:2876d077a796
filelog: drop the CamelCase name for `filelog.filelog`
See 61557734c0ae for the reasoning.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 23 Oct 2024 16:24:18 -0400 |
parents | f4733654f144 |
children |
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 # |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents:
43077
diff
changeset
|
3 # Copyright 2007-2009 Olivia Mackall <olivia@selenic.com> and others |
8250
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. |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
7 |
51863
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
49867
diff
changeset
|
8 from __future__ import annotations |
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
49867
diff
changeset
|
9 |
28368
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 |
49370
1572f790ee5e
convert: remove old ElementTree import cruft from darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49306
diff
changeset
|
13 from xml.etree.ElementTree import ( |
1572f790ee5e
convert: remove old ElementTree import cruft from darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49306
diff
changeset
|
14 ElementTree, |
1572f790ee5e
convert: remove old ElementTree import cruft from darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49306
diff
changeset
|
15 XMLParser, |
1572f790ee5e
convert: remove old ElementTree import cruft from darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49306
diff
changeset
|
16 ) |
38165
2ce60954b1b7
py3: wrap tempfile.mkdtemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents:
36607
diff
changeset
|
17 |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
18 from mercurial.i18n import _ |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
19 from mercurial import ( |
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
20 error, |
38165
2ce60954b1b7
py3: wrap tempfile.mkdtemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents:
36607
diff
changeset
|
21 pycompat, |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
22 util, |
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
23 ) |
36607
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
35176
diff
changeset
|
24 from mercurial.utils import dateutil |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
25 from . import common |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
26 |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
27 NoRepo = common.NoRepo |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
28 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
29 |
28368
b9296b330a54
convert: darcs use absolute_import
timeless <timeless@mozdev.org>
parents:
26779
diff
changeset
|
30 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
|
31 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
|
32 common.converter_source.__init__(self, ui, repotype, path, revs=revs) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
33 common.commandline.__init__(self, ui, b'darcs') |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
34 |
12393
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
35 # 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
|
36 # test-convert-darcs if ElementTree is not around |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
37 if not os.path.exists(os.path.join(path, b'_darcs')): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
38 raise NoRepo(_(b"%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
|
39 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
40 common.checktool(b'darcs') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
41 version = self.run0(b'--version').splitlines()[0].strip() |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
42 if version < b'2.1': |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
43 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
44 _(b'darcs version 2.1 or newer needed (found %r)') % version |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
45 ) |
5497
f0a3918abd42
convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents:
5412
diff
changeset
|
46 |
49371
6833ccc5e74e
py3: fix bytes/unicode issues in convert/darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49370
diff
changeset
|
47 if "ElementTree" not in globals(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
48 raise error.Abort(_(b"Python ElementTree module is not available")) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
49 |
15381
c519cd8f0169
backout dbdb777502dc (issue3077) (issue3071)
Matt Mackall <mpm@selenic.com>
parents:
15355
diff
changeset
|
50 self.path = os.path.realpath(path) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
51 |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
52 self.lastrev = None |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
53 self.changes = {} |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
54 self.parents = {} |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
55 self.tags = {} |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
56 |
12393
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
57 # Check darcs repository format |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
58 format = self.format() |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
59 if format: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
60 if format in (b'darcs-1.0', b'hashed'): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
61 raise NoRepo( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
62 _( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
63 b"%s repository format is unsupported, " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
64 b"please upgrade" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
65 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
66 % format |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
67 ) |
12393
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
68 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
69 self.ui.warn(_(b'failed to detect repository format!')) |
12393
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
70 |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
71 def before(self): |
38165
2ce60954b1b7
py3: wrap tempfile.mkdtemp() to use bytes path
Yuya Nishihara <yuya@tcha.org>
parents:
36607
diff
changeset
|
72 self.tmppath = pycompat.mkdtemp( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
73 prefix=b'convert-' + os.path.basename(self.path) + b'-' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
74 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
75 output, status = self.run(b'init', repodir=self.tmppath) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
76 self.checkexit(status) |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
77 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
78 tree = self.xml( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
79 b'changes', xml_output=True, summary=True, repodir=self.path |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
80 ) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
81 tagname = None |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
82 child = None |
49371
6833ccc5e74e
py3: fix bytes/unicode issues in convert/darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49370
diff
changeset
|
83 for elt in tree.findall('patch'): |
6833ccc5e74e
py3: fix bytes/unicode issues in convert/darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49370
diff
changeset
|
84 node = self.recode(elt.get('hash')) |
6833ccc5e74e
py3: fix bytes/unicode issues in convert/darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49370
diff
changeset
|
85 name = self.recode(elt.findtext('name', '')) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
86 if name.startswith(b'TAG '): |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
87 tagname = name[4:].strip() |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
88 elif tagname is not None: |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
89 self.tags[tagname] = node |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
90 tagname = None |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
91 self.changes[node] = elt |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
92 self.parents[child] = [node] |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
93 child = node |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
94 self.parents[child] = [] |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
95 |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
96 def after(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
97 self.ui.debug(b'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
|
98 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
|
99 |
12717
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
100 def recode(self, s, encoding=None): |
48934
06de08b36c82
py3: use str instead of pycompat.unicode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
101 if isinstance(s, str): |
12717
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
102 # 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
|
103 # 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
|
104 # recode's normal conversion behavior. |
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
105 s = s.encode('latin-1') |
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
106 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
|
107 |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5498
diff
changeset
|
108 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
|
109 # 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
|
110 # 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
|
111 etree = ElementTree() |
12717
89df79b3c011
convert/darcs: support changelogs with bytes 0x7F-0xFF (issue2411)
Brodie Rao <brodie@bitheap.org>
parents:
12393
diff
changeset
|
112 # 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
|
113 # 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
|
114 # non-printable characters are in the XML changelog. |
49371
6833ccc5e74e
py3: fix bytes/unicode issues in convert/darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49370
diff
changeset
|
115 parser = XMLParser(encoding='latin-1') |
17413
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
16514
diff
changeset
|
116 p = self._run(cmd, **kwargs) |
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
16514
diff
changeset
|
117 etree.parse(p.stdout, parser=parser) |
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
16514
diff
changeset
|
118 p.wait() |
97f1f22c2dba
convert: use subprocess for all commandline calls
Patrick Mezard <patrick@mezard.eu>
parents:
16514
diff
changeset
|
119 self.checkexit(p.returncode) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
120 return etree.getroot() |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
121 |
12393
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
122 def format(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
123 output, status = self.run(b'show', b'repo', repodir=self.path) |
12393
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
124 self.checkexit(status) |
49371
6833ccc5e74e
py3: fix bytes/unicode issues in convert/darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49370
diff
changeset
|
125 m = re.search(br'^\s*Format:\s*(.*)$', output, re.MULTILINE) |
12393
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
126 if not m: |
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
127 return None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
128 return b','.join(sorted(f.strip() for f in m.group(1).split(b','))) |
12393
84ceedcfeb6a
convert/darcs: improve unsupported format detection (issue2172)
Patrick Mezard <pmezard@gmail.com>
parents:
12252
diff
changeset
|
129 |
9527
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
130 def manifest(self): |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
131 man = [] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
132 output, status = self.run( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
133 b'show', b'files', no_directories=True, repodir=self.tmppath |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
134 ) |
9527
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
135 self.checkexit(status) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
136 for line in output.split(b'\n'): |
9527
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
137 path = line[2:] |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
138 if path: |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
139 man.append(path) |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
140 return man |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
141 |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
142 def getheads(self): |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
143 return self.parents[None] |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
144 |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
145 def getcommit(self, rev): |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
146 elt = self.changes[rev] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
147 dateformat = b'%a %b %d %H:%M:%S %Z %Y' |
49867
668fb0dcb179
convert: stop passing str to the dateutil API in darcs
Matt Harbison <matt_harbison@yahoo.com>
parents:
49372
diff
changeset
|
148 date = dateutil.strdate(self.recode(elt.get('local_date')), dateformat) |
49371
6833ccc5e74e
py3: fix bytes/unicode issues in convert/darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49370
diff
changeset
|
149 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
|
150 # 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
|
151 # so recode() is used to ensure str objects are emitted. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
152 newdateformat = b'%Y-%m-%d %H:%M:%S %1%2' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
153 return common.commit( |
49371
6833ccc5e74e
py3: fix bytes/unicode issues in convert/darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49370
diff
changeset
|
154 author=self.recode(elt.get('author')), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
155 date=dateutil.datestr(date, newdateformat), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
156 desc=self.recode(desc).strip(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
157 parents=self.parents[rev], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
158 ) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
159 |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
160 def pull(self, rev): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
161 output, status = self.run( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
162 b'pull', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
163 self.path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
164 all=True, |
49371
6833ccc5e74e
py3: fix bytes/unicode issues in convert/darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49370
diff
changeset
|
165 match=b'hash %s' % self.recode(rev), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
166 no_test=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
167 no_posthook=True, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
168 external_merge=b'/bin/false', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
169 repodir=self.tmppath, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
38466
diff
changeset
|
170 ) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
171 if status: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
172 if output.find(b'We have conflicts in') == -1: |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
173 self.checkexit(status, output) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
174 output, status = self.run(b'revert', all=True, repodir=self.tmppath) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
175 self.checkexit(status, output) |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
176 |
22300
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
177 def getchanges(self, rev, full): |
35ab037de989
convert: introduce --full for converting all files
Mads Kiilerich <madski@unity3d.com>
parents:
22296
diff
changeset
|
178 if full: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
179 raise error.Abort(_(b"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
|
180 copies = {} |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
181 changes = [] |
9527
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
182 man = None |
49372
270f8e89ff32
py3: stop using deprecated Element.getchildren() method in convert/darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49371
diff
changeset
|
183 for elt in self.changes[rev].find('summary'): |
49371
6833ccc5e74e
py3: fix bytes/unicode issues in convert/darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49370
diff
changeset
|
184 if elt.tag in ('add_directory', 'remove_directory'): |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
185 continue |
49371
6833ccc5e74e
py3: fix bytes/unicode issues in convert/darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49370
diff
changeset
|
186 if elt.tag == 'move': |
9527
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
187 if man is None: |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
188 man = self.manifest() |
49371
6833ccc5e74e
py3: fix bytes/unicode issues in convert/darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49370
diff
changeset
|
189 source = self.recode(elt.get('from')) |
6833ccc5e74e
py3: fix bytes/unicode issues in convert/darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49370
diff
changeset
|
190 dest = self.recode(elt.get('to')) |
9527
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
191 if source in man: |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
192 # File move |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
193 changes.append((source, rev)) |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
194 changes.append((dest, rev)) |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
195 copies[dest] = source |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
196 else: |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
197 # Directory move, deduce file moves from manifest |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
198 source = source + b'/' |
9527
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
199 for f in man: |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
200 if not f.startswith(source): |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
201 continue |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
202 fdest = dest + b'/' + f[len(source) :] |
9527
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
203 changes.append((f, rev)) |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
204 changes.append((fdest, rev)) |
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
205 copies[fdest] = f |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
206 else: |
49371
6833ccc5e74e
py3: fix bytes/unicode issues in convert/darcs
Ian Moody <moz-ian@perix.co.uk>
parents:
49370
diff
changeset
|
207 changes.append((self.recode(elt.text.strip()), rev)) |
9527
b3c13e721593
convert/darcs: handle directory renaming
Patrick Mezard <pmezard@gmail.com>
parents:
9526
diff
changeset
|
208 self.pull(rev) |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
209 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
|
210 return sorted(changes), copies, set() |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
211 |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
212 def getfile(self, name, rev): |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
213 if rev != self.lastrev: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
214 raise error.Abort(_(b'internal calling inconsistency')) |
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10939
diff
changeset
|
215 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
|
216 try: |
650b5b6e75ed
convert: use None value for missing files instead of overloading IOError
Mads Kiilerich <madski@unity3d.com>
parents:
17413
diff
changeset
|
217 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
|
218 mode = os.lstat(path).st_mode |
49306
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
48934
diff
changeset
|
219 except FileNotFoundError: |
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
48934
diff
changeset
|
220 return None, None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
221 mode = (mode & 0o111) and b'x' or b'' |
11134
33010ff1fd6f
convert: merge sources getmode() into getfile()
Patrick Mezard <pmezard@gmail.com>
parents:
10939
diff
changeset
|
222 return data, mode |
5359
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
223 |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
224 def gettags(self): |
6b6104430964
convert: support darcs as a source repo
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff
changeset
|
225 return self.tags |