Mercurial > hg > mercurial-crew-with-dirclash
comparison contrib/convert-repo @ 4484:c927c568a5ad
Automated merge with http://hg.intevation.org/mercurial/crew
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Sun, 27 May 2007 14:43:29 -0700 |
parents | af013ae3ca10 |
children |
comparison
equal
deleted
inserted
replaced
4483:a11e13d50645 | 4484:c927c568a5ad |
---|---|
28 from mercurial import hg, ui, util, fancyopts | 28 from mercurial import hg, ui, util, fancyopts |
29 | 29 |
30 class Abort(Exception): pass | 30 class Abort(Exception): pass |
31 class NoRepo(Exception): pass | 31 class NoRepo(Exception): pass |
32 | 32 |
33 class commit: | 33 class commit(object): |
34 def __init__(self, **parts): | 34 def __init__(self, **parts): |
35 for x in "author date desc parents".split(): | 35 for x in "author date desc parents".split(): |
36 if not x in parts: | 36 if not x in parts: |
37 abort("commit missing field %s\n" % x) | 37 abort("commit missing field %s\n" % x) |
38 self.__dict__.update(parts) | 38 self.__dict__.update(parts) |
54 try: | 54 try: |
55 return s.decode("latin-1").encode("utf-8") | 55 return s.decode("latin-1").encode("utf-8") |
56 except: | 56 except: |
57 return s.decode("utf-8", "replace").encode("utf-8") | 57 return s.decode("utf-8", "replace").encode("utf-8") |
58 | 58 |
59 class converter_source(object): | |
60 """Conversion source interface""" | |
61 | |
62 def __init__(self, path): | |
63 """Initialize conversion source (or raise NoRepo("message") | |
64 exception if path is not a valid repository)""" | |
65 raise NotImplementedError() | |
66 | |
67 def getheads(self): | |
68 """Return a list of this repository's heads""" | |
69 raise NotImplementedError() | |
70 | |
71 def getfile(self, name, rev): | |
72 """Return file contents as a string""" | |
73 raise NotImplementedError() | |
74 | |
75 def getmode(self, name, rev): | |
76 """Return file mode, eg. '', 'x', or 'l'""" | |
77 raise NotImplementedError() | |
78 | |
79 def getchanges(self, version): | |
80 """Return sorted list of (filename, id) tuples for all files changed in rev. | |
81 | |
82 id just tells us which revision to return in getfile(), e.g. in | |
83 git it's an object hash.""" | |
84 raise NotImplementedError() | |
85 | |
86 def getcommit(self, version): | |
87 """Return the commit object for version""" | |
88 raise NotImplementedError() | |
89 | |
90 def gettags(self): | |
91 """Return the tags as a dictionary of name: revision""" | |
92 raise NotImplementedError() | |
93 | |
94 class converter_sink(object): | |
95 """Conversion sink (target) interface""" | |
96 | |
97 def __init__(self, path): | |
98 """Initialize conversion sink (or raise NoRepo("message") | |
99 exception if path is not a valid repository)""" | |
100 raise NotImplementedError() | |
101 | |
102 def getheads(self): | |
103 """Return a list of this repository's heads""" | |
104 raise NotImplementedError() | |
105 | |
106 def mapfile(self): | |
107 """Path to a file that will contain lines | |
108 source_rev_id sink_rev_id | |
109 mapping equivalent revision identifiers for each system.""" | |
110 raise NotImplementedError() | |
111 | |
112 def putfile(self, f, e, data): | |
113 """Put file for next putcommit(). | |
114 f: path to file | |
115 e: '', 'x', or 'l' (regular file, executable, or symlink) | |
116 data: file contents""" | |
117 raise NotImplementedError() | |
118 | |
119 def delfile(self, f): | |
120 """Delete file for next putcommit(). | |
121 f: path to file""" | |
122 raise NotImplementedError() | |
123 | |
124 def putcommit(self, files, parents, commit): | |
125 """Create a revision with all changed files listed in 'files' | |
126 and having listed parents. 'commit' is a commit object containing | |
127 at a minimum the author, date, and message for this changeset. | |
128 Called after putfile() and delfile() calls. Note that the sink | |
129 repository is not told to update itself to a particular revision | |
130 (or even what that revision would be) before it receives the | |
131 file data.""" | |
132 raise NotImplementedError() | |
133 | |
134 def puttags(self, tags): | |
135 """Put tags into sink. | |
136 tags: {tagname: sink_rev_id, ...}""" | |
137 raise NotImplementedError() | |
138 | |
139 | |
59 # CVS conversion code inspired by hg-cvs-import and git-cvsimport | 140 # CVS conversion code inspired by hg-cvs-import and git-cvsimport |
60 class convert_cvs: | 141 class convert_cvs(converter_source): |
61 def __init__(self, path): | 142 def __init__(self, path): |
62 self.path = path | 143 self.path = path |
63 cvs = os.path.join(path, "CVS") | 144 cvs = os.path.join(path, "CVS") |
64 if not os.path.exists(cvs): | 145 if not os.path.exists(cvs): |
65 raise NoRepo("couldn't open CVS repo %s" % path) | 146 raise NoRepo("couldn't open CVS repo %s" % path) |
286 return self.changeset[rev] | 367 return self.changeset[rev] |
287 | 368 |
288 def gettags(self): | 369 def gettags(self): |
289 return self.tags | 370 return self.tags |
290 | 371 |
291 class convert_git: | 372 class convert_git(converter_source): |
292 def __init__(self, path): | 373 def __init__(self, path): |
293 if os.path.isdir(path + "/.git"): | 374 if os.path.isdir(path + "/.git"): |
294 path += "/.git" | 375 path += "/.git" |
295 self.path = path | 376 self.path = path |
296 if not os.path.exists(path + "/objects"): | 377 if not os.path.exists(path + "/objects"): |
372 tag = tag[len(prefix):-3] | 453 tag = tag[len(prefix):-3] |
373 tags[tag] = node | 454 tags[tag] = node |
374 | 455 |
375 return tags | 456 return tags |
376 | 457 |
377 class convert_mercurial: | 458 class convert_mercurial(converter_sink): |
378 def __init__(self, path): | 459 def __init__(self, path): |
379 self.path = path | 460 self.path = path |
380 u = ui.ui() | 461 u = ui.ui() |
381 try: | 462 try: |
382 self.repo = hg.repository(u, path) | 463 self.repo = hg.repository(u, path) |
469 return c(path) | 550 return c(path) |
470 except NoRepo: | 551 except NoRepo: |
471 pass | 552 pass |
472 abort("%s: unknown repository type\n" % path) | 553 abort("%s: unknown repository type\n" % path) |
473 | 554 |
474 class convert: | 555 class convert(object): |
475 def __init__(self, source, dest, mapfile, opts): | 556 def __init__(self, source, dest, mapfile, opts): |
476 | 557 |
477 self.source = source | 558 self.source = source |
478 self.dest = dest | 559 self.dest = dest |
479 self.mapfile = mapfile | 560 self.mapfile = mapfile |