comparison hgext/convert/common.py @ 5352:cc34be74eeec

Merge with crew-stable.
author Bryan O'Sullivan <bos@serpentine.com>
date Sat, 29 Sep 2007 21:10:54 -0700
parents c6f932d3e0f6
children f0931c0240b4
comparison
equal deleted inserted replaced
5343:26692d08c2f9 5352:cc34be74eeec
1 # common code for the convert extension 1 # common code for the convert extension
2 import base64
3 import cPickle as pickle
4
5 def encodeargs(args):
6 def encodearg(s):
7 lines = base64.encodestring(s)
8 lines = [l.splitlines()[0] for l in lines]
9 return ''.join(lines)
10
11 s = pickle.dumps(args)
12 return encodearg(s)
13
14 def decodeargs(s):
15 s = base64.decodestring(s)
16 return pickle.loads(s)
2 17
3 class NoRepo(Exception): pass 18 class NoRepo(Exception): pass
4 19
5 class commit(object): 20 class commit(object):
6 def __init__(self, **parts): 21 def __init__(self, author, date, desc, parents, branch=None, rev=None):
7 for x in "author date desc parents".split(): 22 self.author = author
8 if not x in parts: 23 self.date = date
9 raise util.Abort("commit missing field %s" % x) 24 self.desc = desc
10 self.__dict__.update(parts) 25 self.parents = parents
26 self.branch = branch
27 self.rev = rev
11 28
12 class converter_source(object): 29 class converter_source(object):
13 """Conversion source interface""" 30 """Conversion source interface"""
14 31
15 def __init__(self, ui, path): 32 def __init__(self, ui, path, rev=None):
16 """Initialize conversion source (or raise NoRepo("message") 33 """Initialize conversion source (or raise NoRepo("message")
17 exception if path is not a valid repository)""" 34 exception if path is not a valid repository)"""
18 raise NotImplementedError() 35 self.ui = ui
36 self.path = path
37 self.rev = rev
38
39 self.encoding = 'utf-8'
40
41 def setrevmap(self, revmap):
42 """set the map of already-converted revisions"""
43 pass
19 44
20 def getheads(self): 45 def getheads(self):
21 """Return a list of this repository's heads""" 46 """Return a list of this repository's heads"""
22 raise NotImplementedError() 47 raise NotImplementedError()
23 48
28 def getmode(self, name, rev): 53 def getmode(self, name, rev):
29 """Return file mode, eg. '', 'x', or 'l'""" 54 """Return file mode, eg. '', 'x', or 'l'"""
30 raise NotImplementedError() 55 raise NotImplementedError()
31 56
32 def getchanges(self, version): 57 def getchanges(self, version):
33 """Return sorted list of (filename, id) tuples for all files changed in rev. 58 """Returns a tuple of (files, copies)
59 Files is a sorted list of (filename, id) tuples for all files changed
60 in version, where id is the source revision id of the file.
34 61
35 id just tells us which revision to return in getfile(), e.g. in 62 copies is a dictionary of dest: source
36 git it's an object hash.""" 63 """
37 raise NotImplementedError() 64 raise NotImplementedError()
38 65
39 def getcommit(self, version): 66 def getcommit(self, version):
40 """Return the commit object for version""" 67 """Return the commit object for version"""
41 raise NotImplementedError() 68 raise NotImplementedError()
42 69
43 def gettags(self): 70 def gettags(self):
44 """Return the tags as a dictionary of name: revision""" 71 """Return the tags as a dictionary of name: revision"""
45 raise NotImplementedError() 72 raise NotImplementedError()
73
74 def recode(self, s, encoding=None):
75 if not encoding:
76 encoding = self.encoding or 'utf-8'
77
78 if isinstance(s, unicode):
79 return s.encode("utf-8")
80 try:
81 return s.decode(encoding).encode("utf-8")
82 except:
83 try:
84 return s.decode("latin-1").encode("utf-8")
85 except:
86 return s.decode(encoding, "replace").encode("utf-8")
46 87
47 class converter_sink(object): 88 class converter_sink(object):
48 """Conversion sink (target) interface""" 89 """Conversion sink (target) interface"""
49 90
50 def __init__(self, ui, path): 91 def __init__(self, ui, path):
54 95
55 def getheads(self): 96 def getheads(self):
56 """Return a list of this repository's heads""" 97 """Return a list of this repository's heads"""
57 raise NotImplementedError() 98 raise NotImplementedError()
58 99
59 def mapfile(self): 100 def revmapfile(self):
60 """Path to a file that will contain lines 101 """Path to a file that will contain lines
61 source_rev_id sink_rev_id 102 source_rev_id sink_rev_id
62 mapping equivalent revision identifiers for each system.""" 103 mapping equivalent revision identifiers for each system."""
63 raise NotImplementedError() 104 raise NotImplementedError()
64 105
92 133
93 def puttags(self, tags): 134 def puttags(self, tags):
94 """Put tags into sink. 135 """Put tags into sink.
95 tags: {tagname: sink_rev_id, ...}""" 136 tags: {tagname: sink_rev_id, ...}"""
96 raise NotImplementedError() 137 raise NotImplementedError()
138
139 def setbranch(self, branch, pbranch, parents):
140 """Set the current branch name. Called before the first putfile
141 on the branch.
142 branch: branch name for subsequent commits
143 pbranch: branch name of parent commit
144 parents: destination revisions of parent"""
145 pass