##// END OF EJS Templates
Some small cleanups for convert extension:...
Thomas Arendsen Hein -
r4532:c3a78a49 default
parent child Browse files
Show More
@@ -6,7 +6,7
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, repo
9 from mercurial import hg, ui, util, commands
10 10
11 11 commands.norepo += " convert"
12 12
@@ -16,7 +16,7 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\n" % x)
19 raise util.Abort("commit missing field %s" % x)
20 20 self.__dict__.update(parts)
21 21
22 22 def recode(s):
@@ -204,7 +204,8 class convert_cvs(converter_source):
204 204
205 205 if root.startswith(":pserver:"):
206 206 root = root[9:]
207 m = re.match(r'(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?(.*)', root)
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 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, "END AUTH REQUEST", ""]))
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 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\n")
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 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\n" % l)
323 raise util.Abort("unknown CVS response: %s" % l)
322 324 else:
323 raise util.Abort("unknown CVS response: %s\n" % line)
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 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" % (self.path, type, rev))
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 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" % (self.path, version))
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
@@ -522,13 +526,13 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\n" % path)
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\n" % path)
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 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 if p not in self.map]
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
@@ -696,7 +701,7 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\n" % src)
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 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 repo.RepoError:
716 except hg.RepoError:
712 717 raise util.Abort(
713 """destination directory %s is not empty.
714 Please specify an empty directory to be initialized or an already 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\n" % dest)
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\n" % src)
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 mercurial repository
737 742 c.convert()
738 743
739 744 cmdtable = {
740 "convert": (_convert,
745 "convert":
746 (_convert,
741 747 [('', 'datesort', None, 'try to sort changesets by date')],
742 'hg convert [OPTIONS] <src> [dst [map]]'),
748 'hg convert [OPTION]... SOURCE [DEST [MAPFILE]]'),
743 749 }
General Comments 0
You need to be logged in to leave comments. Login now