Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/scmutil.py @ 24635:21e1ece30f8c
util: move dirs() and finddirs() from scmutil to util
An upcoming commit requires that match.py be able to call scmutil.dirs(), but
when match.py imports scmutil, a dependency cycle is created. This commit
avoids the cycle by moving dirs() and its related finddirs() function from
scmutil to util, which match.py already depends on.
author | Drew Gottlieb <drgott@google.com> |
---|---|
date | Mon, 06 Apr 2015 14:36:08 -0700 |
parents | a0b47885a1c5 |
children | ca3a90096c95 |
comparison
equal
deleted
inserted
replaced
24634:4ece2847cf4c | 24635:21e1ece30f8c |
---|---|
5 # This software may be used and distributed according to the terms of the | 5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 from i18n import _ | 8 from i18n import _ |
9 from mercurial.node import nullrev | 9 from mercurial.node import nullrev |
10 import util, error, osutil, revset, similar, encoding, phases, parsers | 10 import util, error, osutil, revset, similar, encoding, phases |
11 import pathutil | 11 import pathutil |
12 import match as matchmod | 12 import match as matchmod |
13 import os, errno, re, glob, tempfile | 13 import os, errno, re, glob, tempfile |
14 | 14 |
15 if os.name == 'nt': | 15 if os.name == 'nt': |
1081 def __delete__(self, obj): | 1081 def __delete__(self, obj): |
1082 try: | 1082 try: |
1083 del obj.__dict__[self.name] | 1083 del obj.__dict__[self.name] |
1084 except KeyError: | 1084 except KeyError: |
1085 raise AttributeError(self.name) | 1085 raise AttributeError(self.name) |
1086 | |
1087 class dirs(object): | |
1088 '''a multiset of directory names from a dirstate or manifest''' | |
1089 | |
1090 def __init__(self, map, skip=None): | |
1091 self._dirs = {} | |
1092 addpath = self.addpath | |
1093 if util.safehasattr(map, 'iteritems') and skip is not None: | |
1094 for f, s in map.iteritems(): | |
1095 if s[0] != skip: | |
1096 addpath(f) | |
1097 else: | |
1098 for f in map: | |
1099 addpath(f) | |
1100 | |
1101 def addpath(self, path): | |
1102 dirs = self._dirs | |
1103 for base in finddirs(path): | |
1104 if base in dirs: | |
1105 dirs[base] += 1 | |
1106 return | |
1107 dirs[base] = 1 | |
1108 | |
1109 def delpath(self, path): | |
1110 dirs = self._dirs | |
1111 for base in finddirs(path): | |
1112 if dirs[base] > 1: | |
1113 dirs[base] -= 1 | |
1114 return | |
1115 del dirs[base] | |
1116 | |
1117 def __iter__(self): | |
1118 return self._dirs.iterkeys() | |
1119 | |
1120 def __contains__(self, d): | |
1121 return d in self._dirs | |
1122 | |
1123 if util.safehasattr(parsers, 'dirs'): | |
1124 dirs = parsers.dirs | |
1125 | |
1126 def finddirs(path): | |
1127 pos = path.rfind('/') | |
1128 while pos != -1: | |
1129 yield path[:pos] | |
1130 pos = path.rfind('/', 0, pos) |