comparison hgext/convert/subversion.py @ 5050:2bd996d0aaf8

convert: (svn) simplify _find_children
author Brendan Cully <brendan@kublai.com>
date Wed, 01 Aug 2007 15:16:42 -0700
parents 780051cca03c
children 35f67dd712d0
comparison
equal deleted inserted replaced
5049:41284ad94852 5050:2bd996d0aaf8
43 except SubversionException: 43 except SubversionException:
44 pass 44 pass
45 if os.path.isdir(path): 45 if os.path.isdir(path):
46 return 'file://%s' % os.path.normpath(os.path.abspath(path)) 46 return 'file://%s' % os.path.normpath(os.path.abspath(path))
47 return path 47 return path
48
49 class CompatibilityException(Exception): pass
50 48
51 class changedpath(object): 49 class changedpath(object):
52 def __init__(self, p): 50 def __init__(self, p):
53 self.copyfrom_path = p.copyfrom_path 51 self.copyfrom_path = p.copyfrom_path
54 self.copyfrom_rev = p.copyfrom_rev 52 self.copyfrom_rev = p.copyfrom_rev
624 if data.startswith(link_prefix): 622 if data.startswith(link_prefix):
625 data = data[len(link_prefix):] 623 data = data[len(link_prefix):]
626 return data, mode 624 return data, mode
627 625
628 def _find_children(self, path, revnum): 626 def _find_children(self, path, revnum):
629 path = path.strip("/")
630
631 def _find_children_fallback(path, revnum):
632 # SWIG python bindings for getdir are broken up to at least 1.4.3
633 pool = Pool()
634 optrev = svn.core.svn_opt_revision_t()
635 optrev.kind = svn.core.svn_opt_revision_number
636 optrev.value.number = revnum
637 rpath = '/'.join([self.base, path]).strip('/')
638 return ['%s/%s' % (path, x) for x in svn.client.ls(rpath, optrev, True, self.ctx, pool).keys()]
639
640 if hasattr(self, '_find_children_fallback'):
641 return _find_children_fallback(path, revnum)
642
643 self.reparent("/" + path)
644 pool = Pool() 627 pool = Pool()
645 628 optrev = svn.core.svn_opt_revision_t()
646 children = [] 629 optrev.kind = svn.core.svn_opt_revision_number
647 def find_children_inner(children, path, revnum = revnum): 630 optrev.value.number = revnum
648 if hasattr(svn.ra, 'get_dir2'): # Since SVN 1.4 631 rpath = '/'.join([self.base, path.strip('/')]).strip('/')
649 fields = 0xffffffff # Binding does not provide SVN_DIRENT_ALL 632 return ['%s/%s' % (path, x) for x in svn.client.ls(rpath, optrev, True, self.ctx, pool).keys()]
650 getdir = svn.ra.get_dir2(self.ra, path, revnum, fields, pool)
651 else:
652 getdir = svn.ra.get_dir(self.ra, path, revnum, pool)
653 if type(getdir) == dict:
654 # python binding for getdir is broken up to at least 1.4.3
655 raise CompatibilityException()
656 dirents = getdir[0]
657 if type(dirents) == int:
658 # got here once due to infinite recursion bug
659 return
660 c = dirents.keys()
661 c.sort()
662 for child in c:
663 dirent = dirents[child]
664 if dirent.kind == svn.core.svn_node_dir:
665 find_children_inner(children, (path + "/" + child).strip("/"))
666 else:
667 children.append((path + "/" + child).strip("/"))
668
669 try:
670 find_children_inner(children, "")
671 except CompatibilityException:
672 self._find_children_fallback = True
673 self.reparent(self.module)
674 return _find_children_fallback(path, revnum)
675
676 self.reparent(self.module)
677 return [path + "/" + c for c in children]