Mercurial > hg
annotate hgext/convert/common.py @ 8682:cc7da5aae4cd
match: remove match.never
Only one user, can be translated to match.exact()
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 31 May 2009 17:54:18 -0500 |
parents | 284fda4cd093 |
children | c5b4f662109f |
rev | line source |
---|---|
8250
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8155
diff
changeset
|
1 # common.py - common code for the convert extension |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8155
diff
changeset
|
2 # |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8155
diff
changeset
|
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8155
diff
changeset
|
4 # |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8155
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8155
diff
changeset
|
6 # GNU General Public License version 2, incorporated herein by reference. |
1b60efdb8bc5
convert: add copyright and license headers to back-ends
Martin Geisler <mg@lazybytes.net>
parents:
8155
diff
changeset
|
7 |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
8 import base64, errno |
5832
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
9 import os |
5127
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
10 import cPickle as pickle |
8656 | 11 from mercurial import util |
5513
f0c58fd4b798
convert: add support for Subversion as a sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5512
diff
changeset
|
12 from mercurial.i18n import _ |
5127
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
13 |
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
14 def encodeargs(args): |
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
15 def encodearg(s): |
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
16 lines = base64.encodestring(s) |
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
17 lines = [l.splitlines()[0] for l in lines] |
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
18 return ''.join(lines) |
5143
d4fa6bafc43a
Remove trailing spaces, fix indentation
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5127
diff
changeset
|
19 |
5127
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
20 s = pickle.dumps(args) |
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
21 return encodearg(s) |
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
22 |
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
23 def decodeargs(s): |
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
24 s = base64.decodestring(s) |
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
25 return pickle.loads(s) |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
26 |
6332
950e72fc7cf3
convert: allow missing tools not to stop source type detection
Patrick Mezard <pmezard@gmail.com>
parents:
6049
diff
changeset
|
27 class MissingTool(Exception): pass |
950e72fc7cf3
convert: allow missing tools not to stop source type detection
Patrick Mezard <pmezard@gmail.com>
parents:
6049
diff
changeset
|
28 |
950e72fc7cf3
convert: allow missing tools not to stop source type detection
Patrick Mezard <pmezard@gmail.com>
parents:
6049
diff
changeset
|
29 def checktool(exe, name=None, abort=True): |
5497
f0a3918abd42
convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents:
5441
diff
changeset
|
30 name = name or exe |
f0a3918abd42
convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents:
5441
diff
changeset
|
31 if not util.find_exe(exe): |
6332
950e72fc7cf3
convert: allow missing tools not to stop source type detection
Patrick Mezard <pmezard@gmail.com>
parents:
6049
diff
changeset
|
32 exc = abort and util.Abort or MissingTool |
950e72fc7cf3
convert: allow missing tools not to stop source type detection
Patrick Mezard <pmezard@gmail.com>
parents:
6049
diff
changeset
|
33 raise exc(_('cannot find required "%s" tool') % name) |
5497
f0a3918abd42
convert: fail if an external required tool is not found
Patrick Mezard <pmezard@gmail.com>
parents:
5441
diff
changeset
|
34 |
3953
fad134931327
convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents:
3939
diff
changeset
|
35 class NoRepo(Exception): pass |
3938
0fab73b3f453
convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents:
3917
diff
changeset
|
36 |
5400
d9057f00d343
convert: change SKIPREV to 'SKIP'
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5378
diff
changeset
|
37 SKIPREV = 'SKIP' |
5374
e710874247d1
convert: allow the converter_source to say "skip this revision"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5373
diff
changeset
|
38 |
4448
af013ae3ca10
use documented convert-repo interface
Daniel Holth <dholth@fastmail.fm>
parents:
4447
diff
changeset
|
39 class commit(object): |
5439
d0c67b52ac01
convert: make contents of "extra" dict available from sources, for sinks.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5400
diff
changeset
|
40 def __init__(self, author, date, desc, parents, branch=None, rev=None, |
d0c67b52ac01
convert: make contents of "extra" dict available from sources, for sinks.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5400
diff
changeset
|
41 extra={}): |
5984
9451a941c536
convert: use 'unknown' and '0 0' if commit author or date weren't specified
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5934
diff
changeset
|
42 self.author = author or 'unknown' |
9451a941c536
convert: use 'unknown' and '0 0' if commit author or date weren't specified
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5934
diff
changeset
|
43 self.date = date or '0 0' |
5024
7963438881f5
convert: empty log messages are OK as of 7f5c3fb0a37d
Bryan O'Sullivan <bos@serpentine.com>
parents:
5012
diff
changeset
|
44 self.desc = desc |
5012
be25decfdb13
convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
45 self.parents = parents |
be25decfdb13
convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
46 self.branch = branch |
be25decfdb13
convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents:
5011
diff
changeset
|
47 self.rev = rev |
5439
d0c67b52ac01
convert: make contents of "extra" dict available from sources, for sinks.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5400
diff
changeset
|
48 self.extra = extra |
3954
9af4b853ed4d
convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents:
3953
diff
changeset
|
49 |
4448
af013ae3ca10
use documented convert-repo interface
Daniel Holth <dholth@fastmail.fm>
parents:
4447
diff
changeset
|
50 class converter_source(object): |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
51 """Conversion source interface""" |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
52 |
5556
61fdf2558c0a
convert: some tidyups, doc improvements, and test fixes
Bryan O'Sullivan <bos@serpentine.com>
parents:
5554
diff
changeset
|
53 def __init__(self, ui, path=None, rev=None): |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
54 """Initialize conversion source (or raise NoRepo("message") |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
55 exception if path is not a valid repository)""" |
4810
c2d529f288a1
convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents:
4807
diff
changeset
|
56 self.ui = ui |
c2d529f288a1
convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents:
4807
diff
changeset
|
57 self.path = path |
c2d529f288a1
convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents:
4807
diff
changeset
|
58 self.rev = rev |
c2d529f288a1
convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents:
4807
diff
changeset
|
59 |
c2d529f288a1
convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents:
4807
diff
changeset
|
60 self.encoding = 'utf-8' |
4812
a5209b0487e0
convert: export revmap to source.
Brendan Cully <brendan@kublai.com>
parents:
4810
diff
changeset
|
61 |
5356
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5287
diff
changeset
|
62 def before(self): |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5287
diff
changeset
|
63 pass |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5287
diff
changeset
|
64 |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5287
diff
changeset
|
65 def after(self): |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5287
diff
changeset
|
66 pass |
f0931c0240b4
convert: add before/after hooks for converter sources
Bryan O'Sullivan <bos@serpentine.com>
parents:
5287
diff
changeset
|
67 |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
68 def setrevmap(self, revmap): |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
69 """set the map of already-converted revisions""" |
4813
1fcdf2fe3d7c
convert: svn: use revmap to parse only new revisions in incremental conversions
Brendan Cully <brendan@kublai.com>
parents:
4812
diff
changeset
|
70 pass |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
71 |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
72 def getheads(self): |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
73 """Return a list of this repository's heads""" |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
74 raise NotImplementedError() |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
75 |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
76 def getfile(self, name, rev): |
7055
0f4564b4cc2c
convert: improve convert_source documentation
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
77 """Return file contents as a string. rev is the identifier returned |
8444
057e96fe2955
convert: improve docstrings, comments.
Greg Ward <greg-hg@gerg.ca>
parents:
8250
diff
changeset
|
78 by a previous call to getchanges(). Raise IOError to indicate that |
057e96fe2955
convert: improve docstrings, comments.
Greg Ward <greg-hg@gerg.ca>
parents:
8250
diff
changeset
|
79 name was deleted in rev. |
7055
0f4564b4cc2c
convert: improve convert_source documentation
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
80 """ |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
81 raise NotImplementedError() |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
82 |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
83 def getmode(self, name, rev): |
7055
0f4564b4cc2c
convert: improve convert_source documentation
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
84 """Return file mode, eg. '', 'x', or 'l'. rev is the identifier |
0f4564b4cc2c
convert: improve convert_source documentation
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
85 returned by a previous call to getchanges(). |
0f4564b4cc2c
convert: improve convert_source documentation
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
86 """ |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
87 raise NotImplementedError() |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
88 |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
89 def getchanges(self, version): |
7186
f77c8d8331ca
clean up trailing spaces, leading spaces in C
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7075
diff
changeset
|
90 """Returns a tuple of (files, copies). |
7055
0f4564b4cc2c
convert: improve convert_source documentation
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
91 |
0f4564b4cc2c
convert: improve convert_source documentation
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
92 files is a sorted list of (filename, id) tuples for all files |
8444
057e96fe2955
convert: improve docstrings, comments.
Greg Ward <greg-hg@gerg.ca>
parents:
8250
diff
changeset
|
93 changed between version and its first parent returned by |
7055
0f4564b4cc2c
convert: improve convert_source documentation
Patrick Mezard <pmezard@gmail.com>
parents:
6956
diff
changeset
|
94 getcommit(). id is the source revision id of the file. |
4516
96d8a56d4ef9
Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4515
diff
changeset
|
95 |
5121
ef338e34a906
convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents:
5112
diff
changeset
|
96 copies is a dictionary of dest: source |
ef338e34a906
convert: look up copies in getchanges instead of getcommit
Brendan Cully <brendan@kublai.com>
parents:
5112
diff
changeset
|
97 """ |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
98 raise NotImplementedError() |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
99 |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
100 def getcommit(self, version): |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
101 """Return the commit object for version""" |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
102 raise NotImplementedError() |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
103 |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
104 def gettags(self): |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
105 """Return the tags as a dictionary of name: revision""" |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
106 raise NotImplementedError() |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
107 |
4759
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4590
diff
changeset
|
108 def recode(self, s, encoding=None): |
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4590
diff
changeset
|
109 if not encoding: |
4810
c2d529f288a1
convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents:
4807
diff
changeset
|
110 encoding = self.encoding or 'utf-8' |
4957
cdd33a048289
removed trailing whitespace
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4873
diff
changeset
|
111 |
5287
c6f932d3e0f6
Don't decode unicode strings.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5173
diff
changeset
|
112 if isinstance(s, unicode): |
c6f932d3e0f6
Don't decode unicode strings.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5173
diff
changeset
|
113 return s.encode("utf-8") |
4759
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4590
diff
changeset
|
114 try: |
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4590
diff
changeset
|
115 return s.decode(encoding).encode("utf-8") |
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4590
diff
changeset
|
116 except: |
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4590
diff
changeset
|
117 try: |
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4590
diff
changeset
|
118 return s.decode("latin-1").encode("utf-8") |
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4590
diff
changeset
|
119 except: |
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4590
diff
changeset
|
120 return s.decode(encoding, "replace").encode("utf-8") |
20ec5cc02f18
convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents:
4590
diff
changeset
|
121 |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
122 def getchangedfiles(self, rev, i): |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
123 """Return the files changed by rev compared to parent[i]. |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5556
diff
changeset
|
124 |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
125 i is an index selecting one of the parents of rev. The return |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
126 value should be the list of files that are different in rev and |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
127 this parent. |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
128 |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
129 If rev has no parents, i is None. |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5556
diff
changeset
|
130 |
5377
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
131 This function is only needed to support --filemap |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
132 """ |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
133 raise NotImplementedError() |
756a43a30e34
convert: readd --filemap
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5374
diff
changeset
|
134 |
5554
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5529
diff
changeset
|
135 def converted(self, rev, sinkrev): |
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5529
diff
changeset
|
136 '''Notify the source that a revision has been converted.''' |
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5529
diff
changeset
|
137 pass |
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5529
diff
changeset
|
138 |
2147a734dcf9
convert: tell the source repository when a rev has been converted
Bryan O'Sullivan <bos@serpentine.com>
parents:
5529
diff
changeset
|
139 |
4448
af013ae3ca10
use documented convert-repo interface
Daniel Holth <dholth@fastmail.fm>
parents:
4447
diff
changeset
|
140 class converter_sink(object): |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
141 """Conversion sink (target) interface""" |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
142 |
4513
ac2fe196ac9b
Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents:
4512
diff
changeset
|
143 def __init__(self, ui, path): |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
144 """Initialize conversion sink (or raise NoRepo("message") |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
145 exception if path is not a valid repository) |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
146 |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
147 created is a list of paths to remove if a fatal error occurs |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
148 later""" |
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
149 self.ui = ui |
5440
b4ae8535f834
convert: add default constructor for converter_sink
Bryan O'Sullivan <bos@serpentine.com>
parents:
5439
diff
changeset
|
150 self.path = path |
5441
71e7c86adcb7
convert: refactor sink initialisation, to remove hardcoding of hg
Bryan O'Sullivan <bos@serpentine.com>
parents:
5440
diff
changeset
|
151 self.created = [] |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
152 |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
153 def getheads(self): |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
154 """Return a list of this repository's heads""" |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
155 raise NotImplementedError() |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
156 |
5011
89fbb0a5e8e3
convert: rename mapfile to revmapfile, so we can map more than just revs
Bryan O'Sullivan <bos@serpentine.com>
parents:
4957
diff
changeset
|
157 def revmapfile(self): |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
158 """Path to a file that will contain lines |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
159 source_rev_id sink_rev_id |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
160 mapping equivalent revision identifiers for each system.""" |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
161 raise NotImplementedError() |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
162 |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
163 def authorfile(self): |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
164 """Path to a file that will contain lines |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
165 srcauthor=dstauthor |
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
166 mapping equivalent authors identifiers for each system.""" |
4590
80fb4ec512b5
convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents:
4589
diff
changeset
|
167 return None |
4589
451e91ed535e
convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents:
4536
diff
changeset
|
168 |
6716
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
169 def putcommit(self, files, copies, parents, commit, source): |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
170 """Create a revision with all changed files listed in 'files' |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
171 and having listed parents. 'commit' is a commit object containing |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
172 at a minimum the author, date, and message for this changeset. |
6716
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
173 'files' is a list of (path, version) tuples, 'copies'is a dictionary |
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
174 mapping destinations to sources, and 'source' is the source repository. |
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
175 Only getfile() and getmode() should be called on 'source'. |
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
176 |
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
177 Note that the sink repository is not told to update itself to |
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
178 a particular revision (or even what that revision would be) |
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
179 before it receives the file data. |
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
180 """ |
4447
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
181 raise NotImplementedError() |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
182 |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
183 def puttags(self, tags): |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
184 """Put tags into sink. |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
185 tags: {tagname: sink_rev_id, ...}""" |
1b75e0eff532
document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents:
4114
diff
changeset
|
186 raise NotImplementedError() |
5127
39b6eaee6fd7
convert: replace fork with subprocess call.
Patrick Mezard <pmezard@gmail.com>
parents:
5121
diff
changeset
|
187 |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5441
diff
changeset
|
188 def setbranch(self, branch, pbranches): |
6716
c9b8d2565b92
convert: reintegrate file retrieval code in sinks
Patrick Mezard <pmezard@gmail.com>
parents:
6332
diff
changeset
|
189 """Set the current branch name. Called before the first putcommit |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
190 on the branch. |
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
191 branch: branch name for subsequent commits |
5934
e495f3f35b2d
convert: hg.clonebranches must pull missing parents (issue941)
Patrick Mezard <pmezard@gmail.com>
parents:
5441
diff
changeset
|
192 pbranches: (converted parent revision, parent branch) tuples""" |
5173
6b4c332f241b
convert: hg: optionally create branches as clones
Brendan Cully <brendan@kublai.com>
parents:
5143
diff
changeset
|
193 pass |
5378
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
194 |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
195 def setfilemapmode(self, active): |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
196 """Tell the destination that we're using a filemap |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
197 |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
198 Some converter_sources (svn in particular) can claim that a file |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
199 was changed in a revision, even if there was no change. This method |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
200 tells the destination that we're using a filemap and that it should |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
201 filter empty revisions. |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
202 """ |
8a2915f57dfc
convert: add a mode where mercurial_sink skips empty revisions.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
5377
diff
changeset
|
203 pass |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
204 |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
205 def before(self): |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
206 pass |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
207 |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
208 def after(self): |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
209 pass |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
210 |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
211 |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
212 class commandline(object): |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
213 def __init__(self, ui, command): |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
214 self.ui = ui |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
215 self.command = command |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
216 |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
217 def prerun(self): |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
218 pass |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
219 |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
220 def postrun(self): |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
221 pass |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
222 |
5832
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
223 def _cmdline(self, cmd, *args, **kwargs): |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
224 cmdline = [self.command, cmd] + list(args) |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
225 for k, v in kwargs.iteritems(): |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
226 if len(k) == 1: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
227 cmdline.append('-' + k) |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
228 else: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
229 cmdline.append('--' + k.replace('_', '-')) |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
230 try: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
231 if len(k) == 1: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
232 cmdline.append('' + v) |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
233 else: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
234 cmdline[-1] += '=' + v |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
235 except TypeError: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
236 pass |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
237 cmdline = [util.shellquote(arg) for arg in cmdline] |
7611
dafcc96c1285
convert: display child command output if --debug (fix 878466138b57)
Patrick Mezard <pmezard@gmail.com>
parents:
7610
diff
changeset
|
238 if not self.ui.debugflag: |
7610
878466138b57
convert: print darcs error messages iff --debug
Bryan O'Sullivan <bos@serpentine.com>
parents:
7186
diff
changeset
|
239 cmdline += ['2>', util.nulldev] |
878466138b57
convert: print darcs error messages iff --debug
Bryan O'Sullivan <bos@serpentine.com>
parents:
7186
diff
changeset
|
240 cmdline += ['<', util.nulldev] |
5529
5499dbb445de
convert: fix util.popen regression in darcs converter
Patrick Mezard <pmezard@gmail.com>
parents:
5513
diff
changeset
|
241 cmdline = ' '.join(cmdline) |
5832
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
242 return cmdline |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
243 |
5832
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
244 def _run(self, cmd, *args, **kwargs): |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
245 cmdline = self._cmdline(cmd, *args, **kwargs) |
6956
12472a240398
i18n: mark strings for translation in convert extension
Martin Geisler <mg@daimi.au.dk>
parents:
6870
diff
changeset
|
246 self.ui.debug(_('running: %s\n') % (cmdline,)) |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
247 self.prerun() |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
248 try: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
249 return util.popen(cmdline) |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
250 finally: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
251 self.postrun() |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
252 |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
253 def run(self, cmd, *args, **kwargs): |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
254 fp = self._run(cmd, *args, **kwargs) |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
255 output = fp.read() |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
256 self.ui.debug(output) |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
257 return output, fp.close() |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
258 |
6035
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
6001
diff
changeset
|
259 def runlines(self, cmd, *args, **kwargs): |
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
6001
diff
changeset
|
260 fp = self._run(cmd, *args, **kwargs) |
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
6001
diff
changeset
|
261 output = fp.readlines() |
6049
348132c112cf
convert: improve gnu arch source performance and other fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
6035
diff
changeset
|
262 self.ui.debug(''.join(output)) |
6035
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
6001
diff
changeset
|
263 return output, fp.close() |
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
6001
diff
changeset
|
264 |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
265 def checkexit(self, status, output=''): |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
266 if status: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
267 if output: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
268 self.ui.warn(_('%s error:\n') % self.command) |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
269 self.ui.warn(output) |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
270 msg = util.explain_exit(status)[0] |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
271 raise util.Abort(_('%s %s') % (self.command, msg)) |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
272 |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
273 def run0(self, cmd, *args, **kwargs): |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
274 output, status = self.run(cmd, *args, **kwargs) |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
275 self.checkexit(status, output) |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
276 return output |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
277 |
6035
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
6001
diff
changeset
|
278 def runlines0(self, cmd, *args, **kwargs): |
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
6001
diff
changeset
|
279 output, status = self.runlines(cmd, *args, **kwargs) |
6049
348132c112cf
convert: improve gnu arch source performance and other fixes
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
6035
diff
changeset
|
280 self.checkexit(status, ''.join(output)) |
6035
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
6001
diff
changeset
|
281 return output |
df659eb23360
convert: added GNU Arch source converter
Aleix Conchillo Flaque <aleix@member.fsf.org>
parents:
6001
diff
changeset
|
282 |
5832
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
283 def getargmax(self): |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
284 if '_argmax' in self.__dict__: |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
285 return self._argmax |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
286 |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
287 # POSIX requires at least 4096 bytes for ARG_MAX |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
288 self._argmax = 4096 |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
289 try: |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
290 self._argmax = os.sysconf("SC_ARG_MAX") |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
291 except: |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
292 pass |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
293 |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
294 # Windows shells impose their own limits on command line length, |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
295 # down to 2047 bytes for cmd.exe under Windows NT/2k and 2500 bytes |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
296 # for older 4nt.exe. See http://support.microsoft.com/kb/830473 for |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
297 # details about cmd.exe limitations. |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
298 |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
299 # Since ARG_MAX is for command line _and_ environment, lower our limit |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
300 # (and make happy Windows shells while doing this). |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
301 |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
302 self._argmax = self._argmax/2 - 1 |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
303 return self._argmax |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
304 |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
305 def limit_arglist(self, arglist, cmd, *args, **kwargs): |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
306 limit = self.getargmax() - len(self._cmdline(cmd, *args, **kwargs)) |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
307 bytes = 0 |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
308 fl = [] |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
309 for fn in arglist: |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
310 b = len(fn) + 3 |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
311 if bytes + b < limit or len(fl) == 0: |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
312 fl.append(fn) |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
313 bytes += b |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
314 else: |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
315 yield fl |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
316 fl = [fn] |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
317 bytes = b |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
318 if fl: |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
319 yield fl |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
320 |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
321 def xargs(self, arglist, cmd, *args, **kwargs): |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
322 for l in self.limit_arglist(arglist, cmd, *args, **kwargs): |
2192ed187319
convert: add commandline.xargs(), use it in svn_sink class
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
323 self.run0(cmd, *(list(args) + l), **kwargs) |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
324 |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
325 class mapfile(dict): |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
326 def __init__(self, ui, path): |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
327 super(mapfile, self).__init__() |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
328 self.ui = ui |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
329 self.path = path |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
330 self.fp = None |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
331 self.order = [] |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
332 self._read() |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
333 |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
334 def _read(self): |
7774
3b8f2750efcf
Handle when the slicemap option is an empty string
Stefan Rusek <stefan@rusek.org>
parents:
7611
diff
changeset
|
335 if not self.path: |
5996
3f9ce63da18c
convert: allow synthetic history to be spliced in.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5959
diff
changeset
|
336 return |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
337 try: |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
338 fp = open(self.path, 'r') |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
339 except IOError, err: |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
340 if err.errno != errno.ENOENT: |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
341 raise |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
342 return |
8047
04c62275cbc7
convert: better mapfile parsing errors (issue1581/1)
Patrick Mezard <pmezard@gmail.com>
parents:
7774
diff
changeset
|
343 for i, line in enumerate(fp): |
04c62275cbc7
convert: better mapfile parsing errors (issue1581/1)
Patrick Mezard <pmezard@gmail.com>
parents:
7774
diff
changeset
|
344 try: |
8155 | 345 key, value = line[:-1].rsplit(' ', 1) |
8047
04c62275cbc7
convert: better mapfile parsing errors (issue1581/1)
Patrick Mezard <pmezard@gmail.com>
parents:
7774
diff
changeset
|
346 except ValueError: |
04c62275cbc7
convert: better mapfile parsing errors (issue1581/1)
Patrick Mezard <pmezard@gmail.com>
parents:
7774
diff
changeset
|
347 raise util.Abort(_('syntax error in %s(%d): key/value pair expected') |
04c62275cbc7
convert: better mapfile parsing errors (issue1581/1)
Patrick Mezard <pmezard@gmail.com>
parents:
7774
diff
changeset
|
348 % (self.path, i+1)) |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
349 if key not in self: |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
350 self.order.append(key) |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
351 super(mapfile, self).__setitem__(key, value) |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
352 fp.close() |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5556
diff
changeset
|
353 |
5510
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
354 def __setitem__(self, key, value): |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
355 if self.fp is None: |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
356 try: |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
357 self.fp = open(self.path, 'a') |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
358 except IOError, err: |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
359 raise util.Abort(_('could not open map file %r: %s') % |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
360 (self.path, err.strerror)) |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
361 self.fp.write('%s %s\n' % (key, value)) |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
362 self.fp.flush() |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
363 super(mapfile, self).__setitem__(key, value) |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
364 |
11d7908a3ea8
convert: abstract map files into a class
Bryan O'Sullivan <bos@serpentine.com>
parents:
5497
diff
changeset
|
365 def close(self): |
5512
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
366 if self.fp: |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
367 self.fp.close() |
8cd26ccc68f8
convert: abstract darcs's commandline handling
Bryan O'Sullivan <bos@serpentine.com>
parents:
5510
diff
changeset
|
368 self.fp = None |