equal
deleted
inserted
replaced
889 try: |
889 try: |
890 del obj.__dict__[self.name] |
890 del obj.__dict__[self.name] |
891 except KeyError: |
891 except KeyError: |
892 raise AttributeError(self.name) |
892 raise AttributeError(self.name) |
893 |
893 |
|
894 class dirs(object): |
|
895 '''a multiset of directory names from a dirstate or manifest''' |
|
896 |
|
897 def __init__(self, map, skip=None): |
|
898 self._dirs = {} |
|
899 addpath = self.addpath |
|
900 if util.safehasattr(map, 'iteritems') and skip is not None: |
|
901 for f, s in map.iteritems(): |
|
902 if s[0] != skip: |
|
903 addpath(f) |
|
904 else: |
|
905 for f in map: |
|
906 addpath(f) |
|
907 |
|
908 def addpath(self, path): |
|
909 dirs = self._dirs |
|
910 for base in finddirs(path): |
|
911 if base in dirs: |
|
912 dirs[base] += 1 |
|
913 return |
|
914 dirs[base] = 1 |
|
915 |
|
916 def delpath(self, path): |
|
917 dirs = self._dirs |
|
918 for base in finddirs(path): |
|
919 if dirs[base] > 1: |
|
920 dirs[base] -= 1 |
|
921 return |
|
922 del dirs[base] |
|
923 |
|
924 def __iter__(self): |
|
925 return self._dirs.iterkeys() |
|
926 |
|
927 def __contains__(self, d): |
|
928 return d in self._dirs |
|
929 |
894 def finddirs(path): |
930 def finddirs(path): |
895 pos = path.rfind('/') |
931 pos = path.rfind('/') |
896 while pos != -1: |
932 while pos != -1: |
897 yield path[:pos] |
933 yield path[:pos] |
898 pos = path.rfind('/', 0, pos) |
934 pos = path.rfind('/', 0, pos) |