annotate hgext/convert/common.py @ 5012:be25decfdb13

convert: make commit constructor clearer and less magical
author Bryan O'Sullivan <bos@serpentine.com>
date Thu, 26 Jul 2007 13:34:36 -0700
parents 89fbb0a5e8e3
children 7963438881f5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4536
cc9b79216a76 Split convert extension into common and repository type modules
Brendan Cully <brendan@kublai.com>
parents: 4532
diff changeset
1 # common code for the convert extension
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
2
3953
fad134931327 convert-repo: add basic CVS import support
Matt Mackall <mpm@selenic.com>
parents: 3939
diff changeset
3 class NoRepo(Exception): pass
3938
0fab73b3f453 convert-repo: add some smarts
Matt Mackall <mpm@selenic.com>
parents: 3917
diff changeset
4
4448
af013ae3ca10 use documented convert-repo interface
Daniel Holth <dholth@fastmail.fm>
parents: 4447
diff changeset
5 class commit(object):
5012
be25decfdb13 convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
6 def __init__(self, author, date, desc, parents, branch=None, rev=None,
be25decfdb13 convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
7 copies={}):
4873
28b23b9073a8 convert: record the source revision in the changelog
Brendan Cully <brendan@kublai.com>
parents: 4813
diff changeset
8 self.rev = None
28b23b9073a8 convert: record the source revision in the changelog
Brendan Cully <brendan@kublai.com>
parents: 4813
diff changeset
9 self.branch = None
5012
be25decfdb13 convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
10 self.author = author
be25decfdb13 convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
11 self.date = date
be25decfdb13 convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
12 if desc and not desc.isspace():
be25decfdb13 convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
13 self.desc = desc
be25decfdb13 convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
14 else:
4762
47091c8d028e convert: move *** empty log message *** into commit class
Brendan Cully <brendan@kublai.com>
parents: 4760
diff changeset
15 self.desc = '*** empty log message ***'
5012
be25decfdb13 convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
16 self.parents = parents
be25decfdb13 convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
17 self.branch = branch
be25decfdb13 convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
18 self.rev = rev
be25decfdb13 convert: make commit constructor clearer and less magical
Bryan O'Sullivan <bos@serpentine.com>
parents: 5011
diff changeset
19 self.copies = copies
3954
9af4b853ed4d convert-repo: add CVS branch support
Matt Mackall <mpm@selenic.com>
parents: 3953
diff changeset
20
4448
af013ae3ca10 use documented convert-repo interface
Daniel Holth <dholth@fastmail.fm>
parents: 4447
diff changeset
21 class converter_source(object):
4447
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
22 """Conversion source interface"""
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
23
4760
07efcce17d28 convert: add -r argument specifying latest revision to convert
Brendan Cully <brendan@kublai.com>
parents: 4759
diff changeset
24 def __init__(self, ui, path, rev=None):
4447
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
25 """Initialize conversion source (or raise NoRepo("message")
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
26 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
27 self.ui = ui
c2d529f288a1 convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents: 4807
diff changeset
28 self.path = path
c2d529f288a1 convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents: 4807
diff changeset
29 self.rev = rev
c2d529f288a1 convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents: 4807
diff changeset
30
c2d529f288a1 convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents: 4807
diff changeset
31 self.encoding = 'utf-8'
4812
a5209b0487e0 convert: export revmap to source.
Brendan Cully <brendan@kublai.com>
parents: 4810
diff changeset
32
a5209b0487e0 convert: export revmap to source.
Brendan Cully <brendan@kublai.com>
parents: 4810
diff changeset
33 def setrevmap(self, revmap):
a5209b0487e0 convert: export revmap to source.
Brendan Cully <brendan@kublai.com>
parents: 4810
diff changeset
34 """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
35 pass
4447
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
36
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
37 def getheads(self):
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
38 """Return a list of this repository's heads"""
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
39 raise NotImplementedError()
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
40
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
41 def getfile(self, name, rev):
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
42 """Return file contents as a string"""
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
43 raise NotImplementedError()
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
44
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
45 def getmode(self, name, rev):
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
46 """Return file mode, eg. '', 'x', or 'l'"""
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
47 raise NotImplementedError()
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
48
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
49 def getchanges(self, version):
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
50 """Return sorted list of (filename, id) tuples for all files changed in rev.
4516
96d8a56d4ef9 Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4515
diff changeset
51
4447
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
52 id just tells us which revision to return in getfile(), e.g. in
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
53 git it's an object hash."""
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
54 raise NotImplementedError()
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
55
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
56 def getcommit(self, version):
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
57 """Return the commit object for version"""
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
58 raise NotImplementedError()
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
59
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
60 def gettags(self):
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
61 """Return the tags as a dictionary of name: revision"""
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
62 raise NotImplementedError()
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
63
4759
20ec5cc02f18 convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents: 4590
diff changeset
64 def recode(self, s, encoding=None):
20ec5cc02f18 convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents: 4590
diff changeset
65 if not encoding:
4810
c2d529f288a1 convert: move some code into common init function
Brendan Cully <brendan@kublai.com>
parents: 4807
diff changeset
66 encoding = self.encoding or 'utf-8'
4957
cdd33a048289 removed trailing whitespace
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4873
diff changeset
67
4759
20ec5cc02f18 convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents: 4590
diff changeset
68 try:
20ec5cc02f18 convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents: 4590
diff changeset
69 return s.decode(encoding).encode("utf-8")
20ec5cc02f18 convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents: 4590
diff changeset
70 except:
20ec5cc02f18 convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents: 4590
diff changeset
71 try:
20ec5cc02f18 convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents: 4590
diff changeset
72 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
73 except:
20ec5cc02f18 convert: ove recode method into converter_source
Brendan Cully <brendan@kublai.com>
parents: 4590
diff changeset
74 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
75
4448
af013ae3ca10 use documented convert-repo interface
Daniel Holth <dholth@fastmail.fm>
parents: 4447
diff changeset
76 class converter_sink(object):
4447
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
77 """Conversion sink (target) interface"""
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
78
4513
ac2fe196ac9b Turns convert.py into a real extension
Edouard Gomez <ed.gomez@free.fr>
parents: 4512
diff changeset
79 def __init__(self, ui, path):
4447
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
80 """Initialize conversion sink (or raise NoRepo("message")
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
81 exception if path is not a valid repository)"""
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
82 raise NotImplementedError()
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
83
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
84 def getheads(self):
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
85 """Return a list of this repository's heads"""
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
86 raise NotImplementedError()
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
87
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
88 def revmapfile(self):
4447
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
89 """Path to a file that will contain lines
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
90 source_rev_id sink_rev_id
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
91 mapping equivalent revision identifiers for each system."""
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
92 raise NotImplementedError()
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
93
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
94 def authorfile(self):
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
95 """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
96 srcauthor=dstauthor
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
97 mapping equivalent authors identifiers for each system."""
4590
80fb4ec512b5 convert: fix various authormap handling bugs
Brendan Cully <brendan@kublai.com>
parents: 4589
diff changeset
98 return None
4589
451e91ed535e convert extension: Add support for username mapping
Edouard Gomez <ed.gomez@free.fr>
parents: 4536
diff changeset
99
4447
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
100 def putfile(self, f, e, data):
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
101 """Put file for next putcommit().
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
102 f: path to file
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
103 e: '', 'x', or 'l' (regular file, executable, or symlink)
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
104 data: file contents"""
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
105 raise NotImplementedError()
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
106
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
107 def delfile(self, f):
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
108 """Delete file for next putcommit().
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
109 f: path to file"""
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
110 raise NotImplementedError()
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
111
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
112 def putcommit(self, files, parents, commit):
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
113 """Create a revision with all changed files listed in 'files'
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
114 and having listed parents. 'commit' is a commit object containing
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
115 at a minimum the author, date, and message for this changeset.
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
116 Called after putfile() and delfile() calls. Note that the sink
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
117 repository is not told to update itself to a particular revision
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
118 (or even what that revision would be) before it receives the
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
119 file data."""
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
120 raise NotImplementedError()
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
121
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
122 def puttags(self, tags):
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
123 """Put tags into sink.
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
124 tags: {tagname: sink_rev_id, ...}"""
1b75e0eff532 document conversion interface
Daniel Holth <dholth@fastmail.fm>
parents: 4114
diff changeset
125 raise NotImplementedError()