Show More
@@ -6,7 +6,7 | |||||
6 | # of the GNU General Public License, incorporated herein by reference. |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
7 |
|
7 | |||
8 | import sys, os, zlib, sha, time, re, locale, socket |
|
8 | import sys, os, zlib, sha, time, re, locale, socket | |
9 |
from mercurial import hg, ui, util, commands |
|
9 | from mercurial import hg, ui, util, commands | |
10 |
|
10 | |||
11 | commands.norepo += " convert" |
|
11 | commands.norepo += " convert" | |
12 |
|
12 | |||
@@ -16,7 +16,7 class commit(object): | |||||
16 | def __init__(self, **parts): |
|
16 | def __init__(self, **parts): | |
17 | for x in "author date desc parents".split(): |
|
17 | for x in "author date desc parents".split(): | |
18 | if not x in parts: |
|
18 | if not x in parts: | |
19 |
raise util.Abort("commit missing field %s |
|
19 | raise util.Abort("commit missing field %s" % x) | |
20 | self.__dict__.update(parts) |
|
20 | self.__dict__.update(parts) | |
21 |
|
21 | |||
22 | def recode(s): |
|
22 | def recode(s): | |
@@ -204,7 +204,8 class convert_cvs(converter_source): | |||||
204 |
|
204 | |||
205 | if root.startswith(":pserver:"): |
|
205 | if root.startswith(":pserver:"): | |
206 | root = root[9:] |
|
206 | root = root[9:] | |
207 |
m = re.match(r'(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?(.*)', |
|
207 | m = re.match(r'(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?(.*)', | |
|
208 | root) | |||
208 | if m: |
|
209 | if m: | |
209 | conntype = "pserver" |
|
210 | conntype = "pserver" | |
210 | user, passw, serv, port, root = m.groups() |
|
211 | user, passw, serv, port, root = m.groups() | |
@@ -232,7 +233,8 class convert_cvs(converter_source): | |||||
232 |
|
233 | |||
233 | sck = socket.socket() |
|
234 | sck = socket.socket() | |
234 | sck.connect((serv, port)) |
|
235 | sck.connect((serv, port)) | |
235 |
sck.send("\n".join(["BEGIN AUTH REQUEST", root, user, passw, |
|
236 | sck.send("\n".join(["BEGIN AUTH REQUEST", root, user, passw, | |
|
237 | "END AUTH REQUEST", ""])) | |||
236 | if sck.recv(128) != "I LOVE YOU\n": |
|
238 | if sck.recv(128) != "I LOVE YOU\n": | |
237 | raise NoRepo("CVS pserver authentication failed") |
|
239 | raise NoRepo("CVS pserver authentication failed") | |
238 |
|
240 | |||
@@ -273,7 +275,7 class convert_cvs(converter_source): | |||||
273 | self.writep.flush() |
|
275 | self.writep.flush() | |
274 | r = self.readp.readline() |
|
276 | r = self.readp.readline() | |
275 | if not r.startswith("Valid-requests"): |
|
277 | if not r.startswith("Valid-requests"): | |
276 |
raise util.Abort("server sucks |
|
278 | raise util.Abort("server sucks") | |
277 | if "UseUnchanged" in r: |
|
279 | if "UseUnchanged" in r: | |
278 | self.writep.write("UseUnchanged\n") |
|
280 | self.writep.write("UseUnchanged\n") | |
279 | self.writep.flush() |
|
281 | self.writep.flush() | |
@@ -318,9 +320,9 class convert_cvs(converter_source): | |||||
318 | l = self.readp.readline() |
|
320 | l = self.readp.readline() | |
319 | l = self.readp.readline() |
|
321 | l = self.readp.readline() | |
320 | if l != "ok\n": |
|
322 | if l != "ok\n": | |
321 |
raise util.Abort("unknown CVS response: %s |
|
323 | raise util.Abort("unknown CVS response: %s" % l) | |
322 | else: |
|
324 | else: | |
323 |
raise util.Abort("unknown CVS response: %s |
|
325 | raise util.Abort("unknown CVS response: %s" % line) | |
324 |
|
326 | |||
325 | def getfile(self, file, rev): |
|
327 | def getfile(self, file, rev): | |
326 | data, mode = self._getfile(file, rev) |
|
328 | data, mode = self._getfile(file, rev) | |
@@ -361,7 +363,8 class convert_git(converter_source): | |||||
361 |
|
363 | |||
362 | def catfile(self, rev, type): |
|
364 | def catfile(self, rev, type): | |
363 | if rev == "0" * 40: raise IOError() |
|
365 | if rev == "0" * 40: raise IOError() | |
364 |
fh = os.popen("GIT_DIR=%s git-cat-file %s %s 2>/dev/null" |
|
366 | fh = os.popen("GIT_DIR=%s git-cat-file %s %s 2>/dev/null" | |
|
367 | % (self.path, type, rev)) | |||
365 | return fh.read() |
|
368 | return fh.read() | |
366 |
|
369 | |||
367 | def getfile(self, name, rev): |
|
370 | def getfile(self, name, rev): | |
@@ -372,7 +375,8 class convert_git(converter_source): | |||||
372 |
|
375 | |||
373 | def getchanges(self, version): |
|
376 | def getchanges(self, version): | |
374 | self.modecache = {} |
|
377 | self.modecache = {} | |
375 |
fh = os.popen("GIT_DIR=%s git-diff-tree --root -m -r %s" |
|
378 | fh = os.popen("GIT_DIR=%s git-diff-tree --root -m -r %s" | |
|
379 | % (self.path, version)) | |||
376 | changes = [] |
|
380 | changes = [] | |
377 | for l in fh: |
|
381 | for l in fh: | |
378 | if "\t" not in l: continue |
|
382 | if "\t" not in l: continue | |
@@ -522,13 +526,13 converters = [convert_cvs, convert_git, | |||||
522 |
|
526 | |||
523 | def converter(ui, path): |
|
527 | def converter(ui, path): | |
524 | if not os.path.isdir(path): |
|
528 | if not os.path.isdir(path): | |
525 |
raise util.Abort("%s: not a directory |
|
529 | raise util.Abort("%s: not a directory" % path) | |
526 | for c in converters: |
|
530 | for c in converters: | |
527 | try: |
|
531 | try: | |
528 | return c(ui, path) |
|
532 | return c(ui, path) | |
529 | except NoRepo: |
|
533 | except NoRepo: | |
530 | pass |
|
534 | pass | |
531 |
raise util.Abort("%s: unknown repository type |
|
535 | raise util.Abort("%s: unknown repository type" % path) | |
532 |
|
536 | |||
533 | class convert(object): |
|
537 | class convert(object): | |
534 | def __init__(self, ui, source, dest, mapfile, opts): |
|
538 | def __init__(self, ui, source, dest, mapfile, opts): | |
@@ -610,7 +614,8 class convert(object): | |||||
610 | depth = {} |
|
614 | depth = {} | |
611 | for n in s: |
|
615 | for n in s: | |
612 | depth[n] = 0 |
|
616 | depth[n] = 0 | |
613 |
pl = [p for p in self.commitcache[n].parents |
|
617 | pl = [p for p in self.commitcache[n].parents | |
|
618 | if p not in self.map] | |||
614 | if pl: |
|
619 | if pl: | |
615 | depth[n] = max([depth[p] for p in pl]) + 1 |
|
620 | depth[n] = max([depth[p] for p in pl]) + 1 | |
616 |
|
621 | |||
@@ -696,7 +701,7 def _convert(ui, src, dest=None, mapfile | |||||
696 |
|
701 | |||
697 | srcc = converter(ui, src) |
|
702 | srcc = converter(ui, src) | |
698 | if not hasattr(srcc, "getcommit"): |
|
703 | if not hasattr(srcc, "getcommit"): | |
699 |
raise util.Abort("%s: can't read from this repo type |
|
704 | raise util.Abort("%s: can't read from this repo type" % src) | |
700 |
|
705 | |||
701 | if not dest: |
|
706 | if not dest: | |
702 | dest = src + "-hg" |
|
707 | dest = src + "-hg" | |
@@ -708,24 +713,24 def _convert(ui, src, dest=None, mapfile | |||||
708 | try: |
|
713 | try: | |
709 | hg.repository(ui, dest) |
|
714 | hg.repository(ui, dest) | |
710 | ui.status("destination %s is a Mercurial repository\n" % dest) |
|
715 | ui.status("destination %s is a Mercurial repository\n" % dest) | |
711 |
except |
|
716 | except hg.RepoError: | |
712 | raise util.Abort( |
|
717 | raise util.Abort( | |
713 |
|
|
718 | "destination directory %s is not empty.\n" | |
714 |
Please specify an empty directory to be initialized |
|
719 | "Please specify an empty directory to be initialized\n" | |
715 | mercurial repository |
|
720 | "or an already initialized mercurial repository" | |
716 | """ % dest) |
|
721 | % dest) | |
717 | else: |
|
722 | else: | |
718 | ui.status("initializing destination %s repository\n" % dest) |
|
723 | ui.status("initializing destination %s repository\n" % dest) | |
719 | hg.repository(ui, dest, create=True) |
|
724 | hg.repository(ui, dest, create=True) | |
720 | elif os.path.exists(dest): |
|
725 | elif os.path.exists(dest): | |
721 |
raise util.Abort("destination %s exists and is not a directory |
|
726 | raise util.Abort("destination %s exists and is not a directory" % dest) | |
722 | else: |
|
727 | else: | |
723 | ui.status("initializing destination %s repository\n" % dest) |
|
728 | ui.status("initializing destination %s repository\n" % dest) | |
724 | hg.repository(ui, dest, create=True) |
|
729 | hg.repository(ui, dest, create=True) | |
725 |
|
730 | |||
726 | destc = converter(ui, dest) |
|
731 | destc = converter(ui, dest) | |
727 | if not hasattr(destc, "putcommit"): |
|
732 | if not hasattr(destc, "putcommit"): | |
728 |
raise util.Abort("%s: can't write to this repo type |
|
733 | raise util.Abort("%s: can't write to this repo type" % src) | |
729 |
|
734 | |||
730 | if not mapfile: |
|
735 | if not mapfile: | |
731 | try: |
|
736 | try: | |
@@ -737,7 +742,8 mercurial repository | |||||
737 | c.convert() |
|
742 | c.convert() | |
738 |
|
743 | |||
739 | cmdtable = { |
|
744 | cmdtable = { | |
740 |
"convert": |
|
745 | "convert": | |
|
746 | (_convert, | |||
741 |
|
|
747 | [('', 'datesort', None, 'try to sort changesets by date')], | |
742 |
|
|
748 | 'hg convert [OPTION]... SOURCE [DEST [MAPFILE]]'), | |
743 | } |
|
749 | } |
General Comments 0
You need to be logged in to leave comments.
Login now