common.py
143 lines
| 4.4 KiB
| text/x-python
|
PythonLexer
Brendan Cully
|
r4536 | # common code for the convert extension | ||
Patrick Mezard
|
r5127 | import base64 | ||
import cPickle as pickle | ||||
def encodeargs(args): | ||||
def encodearg(s): | ||||
lines = base64.encodestring(s) | ||||
lines = [l.splitlines()[0] for l in lines] | ||||
return ''.join(lines) | ||||
Thomas Arendsen Hein
|
r5143 | |||
Patrick Mezard
|
r5127 | s = pickle.dumps(args) | ||
return encodearg(s) | ||||
def decodeargs(s): | ||||
s = base64.decodestring(s) | ||||
return pickle.loads(s) | ||||
Brendan Cully
|
r4536 | |||
class NoRepo(Exception): pass | ||||
class commit(object): | ||||
Brendan Cully
|
r5121 | def __init__(self, author, date, desc, parents, branch=None, rev=None): | ||
Bryan O'Sullivan
|
r5012 | self.author = author | ||
self.date = date | ||||
Bryan O'Sullivan
|
r5024 | self.desc = desc | ||
Bryan O'Sullivan
|
r5012 | self.parents = parents | ||
self.branch = branch | ||||
self.rev = rev | ||||
Brendan Cully
|
r4536 | |||
class converter_source(object): | ||||
"""Conversion source interface""" | ||||
Brendan Cully
|
r4760 | def __init__(self, ui, path, rev=None): | ||
Brendan Cully
|
r4536 | """Initialize conversion source (or raise NoRepo("message") | ||
exception if path is not a valid repository)""" | ||||
Brendan Cully
|
r4810 | self.ui = ui | ||
self.path = path | ||||
self.rev = rev | ||||
self.encoding = 'utf-8' | ||||
Brendan Cully
|
r4812 | |||
def setrevmap(self, revmap): | ||||
"""set the map of already-converted revisions""" | ||||
Brendan Cully
|
r4813 | pass | ||
Brendan Cully
|
r4536 | |||
def getheads(self): | ||||
"""Return a list of this repository's heads""" | ||||
raise NotImplementedError() | ||||
def getfile(self, name, rev): | ||||
"""Return file contents as a string""" | ||||
raise NotImplementedError() | ||||
def getmode(self, name, rev): | ||||
"""Return file mode, eg. '', 'x', or 'l'""" | ||||
raise NotImplementedError() | ||||
def getchanges(self, version): | ||||
Brendan Cully
|
r5121 | """Returns a tuple of (files, copies) | ||
Files is a sorted list of (filename, id) tuples for all files changed | ||||
in version, where id is the source revision id of the file. | ||||
Brendan Cully
|
r4536 | |||
Brendan Cully
|
r5121 | copies is a dictionary of dest: source | ||
""" | ||||
Brendan Cully
|
r4536 | raise NotImplementedError() | ||
def getcommit(self, version): | ||||
"""Return the commit object for version""" | ||||
raise NotImplementedError() | ||||
def gettags(self): | ||||
"""Return the tags as a dictionary of name: revision""" | ||||
raise NotImplementedError() | ||||
Brendan Cully
|
r4759 | def recode(self, s, encoding=None): | ||
if not encoding: | ||||
Brendan Cully
|
r4810 | encoding = self.encoding or 'utf-8' | ||
Thomas Arendsen Hein
|
r4957 | |||
Brendan Cully
|
r4759 | try: | ||
return s.decode(encoding).encode("utf-8") | ||||
except: | ||||
try: | ||||
return s.decode("latin-1").encode("utf-8") | ||||
except: | ||||
return s.decode(encoding, "replace").encode("utf-8") | ||||
Brendan Cully
|
r4536 | class converter_sink(object): | ||
"""Conversion sink (target) interface""" | ||||
def __init__(self, ui, path): | ||||
"""Initialize conversion sink (or raise NoRepo("message") | ||||
exception if path is not a valid repository)""" | ||||
raise NotImplementedError() | ||||
def getheads(self): | ||||
"""Return a list of this repository's heads""" | ||||
raise NotImplementedError() | ||||
Bryan O'Sullivan
|
r5011 | def revmapfile(self): | ||
Brendan Cully
|
r4536 | """Path to a file that will contain lines | ||
source_rev_id sink_rev_id | ||||
mapping equivalent revision identifiers for each system.""" | ||||
raise NotImplementedError() | ||||
Edouard Gomez
|
r4589 | def authorfile(self): | ||
"""Path to a file that will contain lines | ||||
srcauthor=dstauthor | ||||
mapping equivalent authors identifiers for each system.""" | ||||
Brendan Cully
|
r4590 | return None | ||
Edouard Gomez
|
r4589 | |||
Brendan Cully
|
r4536 | def putfile(self, f, e, data): | ||
"""Put file for next putcommit(). | ||||
f: path to file | ||||
e: '', 'x', or 'l' (regular file, executable, or symlink) | ||||
data: file contents""" | ||||
raise NotImplementedError() | ||||
def delfile(self, f): | ||||
"""Delete file for next putcommit(). | ||||
f: path to file""" | ||||
raise NotImplementedError() | ||||
def putcommit(self, files, parents, commit): | ||||
"""Create a revision with all changed files listed in 'files' | ||||
and having listed parents. 'commit' is a commit object containing | ||||
at a minimum the author, date, and message for this changeset. | ||||
Called after putfile() and delfile() calls. Note that the sink | ||||
repository is not told to update itself to a particular revision | ||||
(or even what that revision would be) before it receives the | ||||
file data.""" | ||||
raise NotImplementedError() | ||||
def puttags(self, tags): | ||||
"""Put tags into sink. | ||||
tags: {tagname: sink_rev_id, ...}""" | ||||
raise NotImplementedError() | ||||
Patrick Mezard
|
r5127 | |||
Brendan Cully
|
r5173 | def setbranch(self, branch, pbranch, parents): | ||
"""Set the current branch name. Called before the first putfile | ||||
on the branch. | ||||
branch: branch name for subsequent commits | ||||
pbranch: branch name of parent commit | ||||
parents: destination revisions of parent""" | ||||
pass | ||||