Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.py @ 6284:c93b6c0e6e84
Allow hgwebdir collections to follow symlinks.
author | Eric Hopper <hopper@omnifarious.org> |
---|---|
date | Sat, 15 Mar 2008 12:42:34 -0700 |
parents | d036ea711140 |
children | b0d937869417 |
comparison
equal
deleted
inserted
replaced
6283:5a45c82fc7da | 6284:c93b6c0e6e84 |
---|---|
1700 if len(text) <= maxlength: | 1700 if len(text) <= maxlength: |
1701 return text | 1701 return text |
1702 else: | 1702 else: |
1703 return "%s..." % (text[:maxlength-3]) | 1703 return "%s..." % (text[:maxlength-3]) |
1704 | 1704 |
1705 def walkrepos(path): | 1705 def walkrepos(path, followsym=False, seen_dirs=None): |
1706 '''yield every hg repository under path, recursively.''' | 1706 '''yield every hg repository under path, recursively.''' |
1707 def errhandler(err): | 1707 def errhandler(err): |
1708 if err.filename == path: | 1708 if err.filename == path: |
1709 raise err | 1709 raise err |
1710 | 1710 if followsym and hasattr(os.path, 'samestat'): |
1711 for root, dirs, files in os.walk(path, onerror=errhandler): | 1711 def _add_dir_if_not_there(dirlst, dirname): |
1712 match = False | |
1713 samestat = os.path.samestat | |
1714 dirstat = os.stat(dirname) | |
1715 for lstdirstat in dirlst: | |
1716 if samestat(dirstat, lstdirstat): | |
1717 match = True | |
1718 break | |
1719 if not match: | |
1720 dirlst.append(dirstat) | |
1721 return not match | |
1722 else: | |
1723 followsym = false | |
1724 | |
1725 if (seen_dirs is None) and followsym: | |
1726 seen_dirs = [] | |
1727 _add_dir_if_not_there(seen_dirs, path) | |
1728 for root, dirs, files in os.walk(path, topdown=True, onerror=errhandler): | |
1712 if '.hg' in dirs: | 1729 if '.hg' in dirs: |
1713 dirs[:] = [] # don't descend further | 1730 dirs[:] = [] # don't descend further |
1714 yield root # found a repository | 1731 yield root # found a repository |
1715 qroot = os.path.join(root, '.hg', 'patches') | 1732 qroot = os.path.join(root, '.hg', 'patches') |
1716 if os.path.isdir(os.path.join(qroot, '.hg')): | 1733 if os.path.isdir(os.path.join(qroot, '.hg')): |
1717 yield qroot # we have a patch queue repo here | 1734 yield qroot # we have a patch queue repo here |
1735 elif followsym: | |
1736 newdirs = [] | |
1737 for d in dirs: | |
1738 fname = os.path.join(root, d) | |
1739 if _add_dir_if_not_there(seen_dirs, fname): | |
1740 if os.path.islink(fname): | |
1741 for hgname in walkrepos(fname, True, seen_dirs): | |
1742 yield hgname | |
1743 else: | |
1744 newdirs.append(d) | |
1745 dirs[:] = newdirs | |
1718 | 1746 |
1719 _rcpath = None | 1747 _rcpath = None |
1720 | 1748 |
1721 def os_rcpath(): | 1749 def os_rcpath(): |
1722 '''return default os-specific hgrc search path''' | 1750 '''return default os-specific hgrc search path''' |