Show More
@@ -1,125 +1,122 b'' | |||||
1 | # common code for the convert extension |
|
1 | # common code for the convert extension | |
2 |
|
2 | |||
3 | class NoRepo(Exception): pass |
|
3 | class NoRepo(Exception): pass | |
4 |
|
4 | |||
5 | class commit(object): |
|
5 | class commit(object): | |
6 | def __init__(self, author, date, desc, parents, branch=None, rev=None, |
|
6 | def __init__(self, author, date, desc, parents, branch=None, rev=None, | |
7 | copies={}): |
|
7 | copies={}): | |
8 | self.rev = None |
|
8 | self.rev = None | |
9 | self.branch = None |
|
9 | self.branch = None | |
10 | self.author = author |
|
10 | self.author = author | |
11 | self.date = date |
|
11 | self.date = date | |
12 | if desc and not desc.isspace(): |
|
|||
13 |
|
|
12 | self.desc = desc | |
14 | else: |
|
|||
15 | self.desc = '*** empty log message ***' |
|
|||
16 | self.parents = parents |
|
13 | self.parents = parents | |
17 | self.branch = branch |
|
14 | self.branch = branch | |
18 | self.rev = rev |
|
15 | self.rev = rev | |
19 | self.copies = copies |
|
16 | self.copies = copies | |
20 |
|
17 | |||
21 | class converter_source(object): |
|
18 | class converter_source(object): | |
22 | """Conversion source interface""" |
|
19 | """Conversion source interface""" | |
23 |
|
20 | |||
24 | def __init__(self, ui, path, rev=None): |
|
21 | def __init__(self, ui, path, rev=None): | |
25 | """Initialize conversion source (or raise NoRepo("message") |
|
22 | """Initialize conversion source (or raise NoRepo("message") | |
26 | exception if path is not a valid repository)""" |
|
23 | exception if path is not a valid repository)""" | |
27 | self.ui = ui |
|
24 | self.ui = ui | |
28 | self.path = path |
|
25 | self.path = path | |
29 | self.rev = rev |
|
26 | self.rev = rev | |
30 |
|
27 | |||
31 | self.encoding = 'utf-8' |
|
28 | self.encoding = 'utf-8' | |
32 |
|
29 | |||
33 | def setrevmap(self, revmap): |
|
30 | def setrevmap(self, revmap): | |
34 | """set the map of already-converted revisions""" |
|
31 | """set the map of already-converted revisions""" | |
35 | pass |
|
32 | pass | |
36 |
|
33 | |||
37 | def getheads(self): |
|
34 | def getheads(self): | |
38 | """Return a list of this repository's heads""" |
|
35 | """Return a list of this repository's heads""" | |
39 | raise NotImplementedError() |
|
36 | raise NotImplementedError() | |
40 |
|
37 | |||
41 | def getfile(self, name, rev): |
|
38 | def getfile(self, name, rev): | |
42 | """Return file contents as a string""" |
|
39 | """Return file contents as a string""" | |
43 | raise NotImplementedError() |
|
40 | raise NotImplementedError() | |
44 |
|
41 | |||
45 | def getmode(self, name, rev): |
|
42 | def getmode(self, name, rev): | |
46 | """Return file mode, eg. '', 'x', or 'l'""" |
|
43 | """Return file mode, eg. '', 'x', or 'l'""" | |
47 | raise NotImplementedError() |
|
44 | raise NotImplementedError() | |
48 |
|
45 | |||
49 | def getchanges(self, version): |
|
46 | def getchanges(self, version): | |
50 | """Return sorted list of (filename, id) tuples for all files changed in rev. |
|
47 | """Return sorted list of (filename, id) tuples for all files changed in rev. | |
51 |
|
48 | |||
52 | id just tells us which revision to return in getfile(), e.g. in |
|
49 | id just tells us which revision to return in getfile(), e.g. in | |
53 | git it's an object hash.""" |
|
50 | git it's an object hash.""" | |
54 | raise NotImplementedError() |
|
51 | raise NotImplementedError() | |
55 |
|
52 | |||
56 | def getcommit(self, version): |
|
53 | def getcommit(self, version): | |
57 | """Return the commit object for version""" |
|
54 | """Return the commit object for version""" | |
58 | raise NotImplementedError() |
|
55 | raise NotImplementedError() | |
59 |
|
56 | |||
60 | def gettags(self): |
|
57 | def gettags(self): | |
61 | """Return the tags as a dictionary of name: revision""" |
|
58 | """Return the tags as a dictionary of name: revision""" | |
62 | raise NotImplementedError() |
|
59 | raise NotImplementedError() | |
63 |
|
60 | |||
64 | def recode(self, s, encoding=None): |
|
61 | def recode(self, s, encoding=None): | |
65 | if not encoding: |
|
62 | if not encoding: | |
66 | encoding = self.encoding or 'utf-8' |
|
63 | encoding = self.encoding or 'utf-8' | |
67 |
|
64 | |||
68 | try: |
|
65 | try: | |
69 | return s.decode(encoding).encode("utf-8") |
|
66 | return s.decode(encoding).encode("utf-8") | |
70 | except: |
|
67 | except: | |
71 | try: |
|
68 | try: | |
72 | return s.decode("latin-1").encode("utf-8") |
|
69 | return s.decode("latin-1").encode("utf-8") | |
73 | except: |
|
70 | except: | |
74 | return s.decode(encoding, "replace").encode("utf-8") |
|
71 | return s.decode(encoding, "replace").encode("utf-8") | |
75 |
|
72 | |||
76 | class converter_sink(object): |
|
73 | class converter_sink(object): | |
77 | """Conversion sink (target) interface""" |
|
74 | """Conversion sink (target) interface""" | |
78 |
|
75 | |||
79 | def __init__(self, ui, path): |
|
76 | def __init__(self, ui, path): | |
80 | """Initialize conversion sink (or raise NoRepo("message") |
|
77 | """Initialize conversion sink (or raise NoRepo("message") | |
81 | exception if path is not a valid repository)""" |
|
78 | exception if path is not a valid repository)""" | |
82 | raise NotImplementedError() |
|
79 | raise NotImplementedError() | |
83 |
|
80 | |||
84 | def getheads(self): |
|
81 | def getheads(self): | |
85 | """Return a list of this repository's heads""" |
|
82 | """Return a list of this repository's heads""" | |
86 | raise NotImplementedError() |
|
83 | raise NotImplementedError() | |
87 |
|
84 | |||
88 | def revmapfile(self): |
|
85 | def revmapfile(self): | |
89 | """Path to a file that will contain lines |
|
86 | """Path to a file that will contain lines | |
90 | source_rev_id sink_rev_id |
|
87 | source_rev_id sink_rev_id | |
91 | mapping equivalent revision identifiers for each system.""" |
|
88 | mapping equivalent revision identifiers for each system.""" | |
92 | raise NotImplementedError() |
|
89 | raise NotImplementedError() | |
93 |
|
90 | |||
94 | def authorfile(self): |
|
91 | def authorfile(self): | |
95 | """Path to a file that will contain lines |
|
92 | """Path to a file that will contain lines | |
96 | srcauthor=dstauthor |
|
93 | srcauthor=dstauthor | |
97 | mapping equivalent authors identifiers for each system.""" |
|
94 | mapping equivalent authors identifiers for each system.""" | |
98 | return None |
|
95 | return None | |
99 |
|
96 | |||
100 | def putfile(self, f, e, data): |
|
97 | def putfile(self, f, e, data): | |
101 | """Put file for next putcommit(). |
|
98 | """Put file for next putcommit(). | |
102 | f: path to file |
|
99 | f: path to file | |
103 | e: '', 'x', or 'l' (regular file, executable, or symlink) |
|
100 | e: '', 'x', or 'l' (regular file, executable, or symlink) | |
104 | data: file contents""" |
|
101 | data: file contents""" | |
105 | raise NotImplementedError() |
|
102 | raise NotImplementedError() | |
106 |
|
103 | |||
107 | def delfile(self, f): |
|
104 | def delfile(self, f): | |
108 | """Delete file for next putcommit(). |
|
105 | """Delete file for next putcommit(). | |
109 | f: path to file""" |
|
106 | f: path to file""" | |
110 | raise NotImplementedError() |
|
107 | raise NotImplementedError() | |
111 |
|
108 | |||
112 | def putcommit(self, files, parents, commit): |
|
109 | def putcommit(self, files, parents, commit): | |
113 | """Create a revision with all changed files listed in 'files' |
|
110 | """Create a revision with all changed files listed in 'files' | |
114 | and having listed parents. 'commit' is a commit object containing |
|
111 | and having listed parents. 'commit' is a commit object containing | |
115 | at a minimum the author, date, and message for this changeset. |
|
112 | at a minimum the author, date, and message for this changeset. | |
116 | Called after putfile() and delfile() calls. Note that the sink |
|
113 | Called after putfile() and delfile() calls. Note that the sink | |
117 | repository is not told to update itself to a particular revision |
|
114 | repository is not told to update itself to a particular revision | |
118 | (or even what that revision would be) before it receives the |
|
115 | (or even what that revision would be) before it receives the | |
119 | file data.""" |
|
116 | file data.""" | |
120 | raise NotImplementedError() |
|
117 | raise NotImplementedError() | |
121 |
|
118 | |||
122 | def puttags(self, tags): |
|
119 | def puttags(self, tags): | |
123 | """Put tags into sink. |
|
120 | """Put tags into sink. | |
124 | tags: {tagname: sink_rev_id, ...}""" |
|
121 | tags: {tagname: sink_rev_id, ...}""" | |
125 | raise NotImplementedError() |
|
122 | raise NotImplementedError() |
General Comments 0
You need to be logged in to leave comments.
Login now