Show More
@@ -6,7 +6,7 b'' | |||
|
6 | 6 | # of the GNU General Public License, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 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 | 11 | commands.norepo += " convert" |
|
12 | 12 | |
@@ -16,7 +16,7 b' class commit(object):' | |||
|
16 | 16 | def __init__(self, **parts): |
|
17 | 17 | for x in "author date desc parents".split(): |
|
18 | 18 | if not x in parts: |
|
19 |
raise util.Abort("commit missing field %s |
|
|
19 | raise util.Abort("commit missing field %s" % x) | |
|
20 | 20 | self.__dict__.update(parts) |
|
21 | 21 | |
|
22 | 22 | def recode(s): |
@@ -148,7 +148,7 b' class convert_cvs(converter_source):' | |||
|
148 | 148 | date = util.datestr(date) |
|
149 | 149 | elif l.startswith("Branch"): |
|
150 | 150 | branch = l[8:-1] |
|
151 | self.parent[id] = self.lastbranch.get(branch,'bad') | |
|
151 | self.parent[id] = self.lastbranch.get(branch, 'bad') | |
|
152 | 152 | self.lastbranch[branch] = id |
|
153 | 153 | elif l.startswith("Ancestor branch"): |
|
154 | 154 | ancestor = l[17:-1] |
@@ -204,7 +204,8 b' class convert_cvs(converter_source):' | |||
|
204 | 204 | |
|
205 | 205 | if root.startswith(":pserver:"): |
|
206 | 206 | root = root[9:] |
|
207 |
m = re.match(r'(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?(.*)', |
|
|
207 | m = re.match(r'(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?(.*)', | |
|
208 | root) | |
|
208 | 209 | if m: |
|
209 | 210 | conntype = "pserver" |
|
210 | 211 | user, passw, serv, port, root = m.groups() |
@@ -232,7 +233,8 b' class convert_cvs(converter_source):' | |||
|
232 | 233 | |
|
233 | 234 | sck = socket.socket() |
|
234 | 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 | 238 | if sck.recv(128) != "I LOVE YOU\n": |
|
237 | 239 | raise NoRepo("CVS pserver authentication failed") |
|
238 | 240 | |
@@ -273,7 +275,7 b' class convert_cvs(converter_source):' | |||
|
273 | 275 | self.writep.flush() |
|
274 | 276 | r = self.readp.readline() |
|
275 | 277 | if not r.startswith("Valid-requests"): |
|
276 |
raise util.Abort("server sucks |
|
|
278 | raise util.Abort("server sucks") | |
|
277 | 279 | if "UseUnchanged" in r: |
|
278 | 280 | self.writep.write("UseUnchanged\n") |
|
279 | 281 | self.writep.flush() |
@@ -318,9 +320,9 b' class convert_cvs(converter_source):' | |||
|
318 | 320 | l = self.readp.readline() |
|
319 | 321 | l = self.readp.readline() |
|
320 | 322 | if l != "ok\n": |
|
321 |
raise util.Abort("unknown CVS response: %s |
|
|
323 | raise util.Abort("unknown CVS response: %s" % l) | |
|
322 | 324 | else: |
|
323 |
raise util.Abort("unknown CVS response: %s |
|
|
325 | raise util.Abort("unknown CVS response: %s" % line) | |
|
324 | 326 | |
|
325 | 327 | def getfile(self, file, rev): |
|
326 | 328 | data, mode = self._getfile(file, rev) |
@@ -361,7 +363,8 b' class convert_git(converter_source):' | |||
|
361 | 363 | |
|
362 | 364 | def catfile(self, rev, type): |
|
363 | 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 | 368 | return fh.read() |
|
366 | 369 | |
|
367 | 370 | def getfile(self, name, rev): |
@@ -372,7 +375,8 b' class convert_git(converter_source):' | |||
|
372 | 375 | |
|
373 | 376 | def getchanges(self, version): |
|
374 | 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 | 380 | changes = [] |
|
377 | 381 | for l in fh: |
|
378 | 382 | if "\t" not in l: continue |
@@ -394,7 +398,7 b' class convert_git(converter_source):' | |||
|
394 | 398 | manifest = l[0].split()[1] |
|
395 | 399 | parents = [] |
|
396 | 400 | for e in l[1:]: |
|
397 | n,v = e.split(" ", 1) | |
|
401 | n, v = e.split(" ", 1) | |
|
398 | 402 | if n == "author": |
|
399 | 403 | p = v.split() |
|
400 | 404 | tm, tz = p[-2:] |
@@ -522,13 +526,13 b' converters = [convert_cvs, convert_git, ' | |||
|
522 | 526 | |
|
523 | 527 | def converter(ui, path): |
|
524 | 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 | 530 | for c in converters: |
|
527 | 531 | try: |
|
528 | 532 | return c(ui, path) |
|
529 | 533 | except NoRepo: |
|
530 | 534 | pass |
|
531 |
raise util.Abort("%s: unknown repository type |
|
|
535 | raise util.Abort("%s: unknown repository type" % path) | |
|
532 | 536 | |
|
533 | 537 | class convert(object): |
|
534 | 538 | def __init__(self, ui, source, dest, mapfile, opts): |
@@ -610,7 +614,8 b' class convert(object):' | |||
|
610 | 614 | depth = {} |
|
611 | 615 | for n in s: |
|
612 | 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 | 619 | if pl: |
|
615 | 620 | depth[n] = max([depth[p] for p in pl]) + 1 |
|
616 | 621 | |
@@ -624,7 +629,7 b' class convert(object):' | |||
|
624 | 629 | c = self.commitcache[rev] |
|
625 | 630 | files = self.source.getchanges(rev) |
|
626 | 631 | |
|
627 | for f,v in files: | |
|
632 | for f, v in files: | |
|
628 | 633 | try: |
|
629 | 634 | data = self.source.getfile(f, v) |
|
630 | 635 | except IOError, inst: |
@@ -634,7 +639,7 b' class convert(object):' | |||
|
634 | 639 | self.dest.putfile(f, e, data) |
|
635 | 640 | |
|
636 | 641 | r = [self.map[v] for v in c.parents] |
|
637 | f = [f for f,v in files] | |
|
642 | f = [f for f, v in files] | |
|
638 | 643 | self.map[rev] = self.dest.putcommit(f, r, c) |
|
639 | 644 | file(self.mapfile, "a").write("%s %s\n" % (rev, self.map[rev])) |
|
640 | 645 | |
@@ -696,7 +701,7 b' def _convert(ui, src, dest=None, mapfile' | |||
|
696 | 701 | |
|
697 | 702 | srcc = converter(ui, src) |
|
698 | 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 | 706 | if not dest: |
|
702 | 707 | dest = src + "-hg" |
@@ -708,24 +713,24 b' def _convert(ui, src, dest=None, mapfile' | |||
|
708 | 713 | try: |
|
709 | 714 | hg.repository(ui, dest) |
|
710 | 715 | ui.status("destination %s is a Mercurial repository\n" % dest) |
|
711 |
except |
|
|
716 | except hg.RepoError: | |
|
712 | 717 | raise util.Abort( |
|
713 |
|
|
|
714 |
Please specify an empty directory to be initialized |
|
|
715 | mercurial repository | |
|
716 | """ % dest) | |
|
718 | "destination directory %s is not empty.\n" | |
|
719 | "Please specify an empty directory to be initialized\n" | |
|
720 | "or an already initialized mercurial repository" | |
|
721 | % dest) | |
|
717 | 722 | else: |
|
718 | 723 | ui.status("initializing destination %s repository\n" % dest) |
|
719 | 724 | hg.repository(ui, dest, create=True) |
|
720 | 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 | 727 | else: |
|
723 | 728 | ui.status("initializing destination %s repository\n" % dest) |
|
724 | 729 | hg.repository(ui, dest, create=True) |
|
725 | ||
|
730 | ||
|
726 | 731 | destc = converter(ui, dest) |
|
727 | 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 | 735 | if not mapfile: |
|
731 | 736 | try: |
@@ -737,7 +742,8 b' mercurial repository' | |||
|
737 | 742 | c.convert() |
|
738 | 743 | |
|
739 | 744 | cmdtable = { |
|
740 |
"convert": |
|
|
741 | [('', 'datesort', None, 'try to sort changesets by date')], | |
|
742 | 'hg convert [OPTIONS] <src> [dst [map]]'), | |
|
745 | "convert": | |
|
746 | (_convert, | |
|
747 | [('', 'datesort', None, 'try to sort changesets by date')], | |
|
748 | 'hg convert [OPTION]... SOURCE [DEST [MAPFILE]]'), | |
|
743 | 749 | } |
General Comments 0
You need to be logged in to leave comments.
Login now