Mercurial > public > mercurial-scm > hg
comparison mercurial/localrepo.py @ 4906:30847b8af7ca
dirstate: add __contains__ and make __getitem__ more useful
dirstate.state(f) == '?' -> f not in dirstate
dirstate.state(f) -> dirstate[f]
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sat, 21 Jul 2007 16:02:09 -0500 |
parents | 6fd953d5faea |
children | fd96bc61a18b |
comparison
equal
deleted
inserted
replaced
4905:fc61495ea9cf | 4906:30847b8af7ca |
---|---|
123 if prevtags and prevtags[-1] != '\n': | 123 if prevtags and prevtags[-1] != '\n': |
124 fp.write('\n') | 124 fp.write('\n') |
125 fp.write('%s %s\n' % (hex(node), munge and munge(name) or name)) | 125 fp.write('%s %s\n' % (hex(node), munge and munge(name) or name)) |
126 fp.close() | 126 fp.close() |
127 self.hook('tag', node=hex(node), tag=name, local=local) | 127 self.hook('tag', node=hex(node), tag=name, local=local) |
128 | 128 |
129 prevtags = '' | 129 prevtags = '' |
130 if local: | 130 if local: |
131 try: | 131 try: |
132 fp = self.opener('localtags', 'r+') | 132 fp = self.opener('localtags', 'r+') |
133 except IOError, err: | 133 except IOError, err: |
154 fp = self.wfile('.hgtags', 'wb') | 154 fp = self.wfile('.hgtags', 'wb') |
155 | 155 |
156 # committed tags are stored in UTF-8 | 156 # committed tags are stored in UTF-8 |
157 writetag(fp, name, util.fromlocal, prevtags) | 157 writetag(fp, name, util.fromlocal, prevtags) |
158 | 158 |
159 if use_dirstate and self.dirstate.state('.hgtags') == '?': | 159 if use_dirstate and '.hgtags' not in self.dirstate: |
160 self.add(['.hgtags']) | 160 self.add(['.hgtags']) |
161 | 161 |
162 tagnode = self.commit(['.hgtags'], message, user, date, p1=parent, | 162 tagnode = self.commit(['.hgtags'], message, user, date, p1=parent, |
163 extra=extra) | 163 extra=extra) |
164 | 164 |
649 extra = extra.copy() | 649 extra = extra.copy() |
650 | 650 |
651 if use_dirstate: | 651 if use_dirstate: |
652 if files: | 652 if files: |
653 for f in files: | 653 for f in files: |
654 s = self.dirstate.state(f) | 654 s = self.dirstate[f] |
655 if s in 'nmai': | 655 if s in 'nma': |
656 commit.append(f) | 656 commit.append(f) |
657 elif s == 'r': | 657 elif s == 'r': |
658 remove.append(f) | 658 remove.append(f) |
659 else: | 659 else: |
660 self.ui.warn(_("%s not tracked!\n") % f) | 660 self.ui.warn(_("%s not tracked!\n") % f) |
968 "(use 'hg revert %s' to unadd the file)\n") | 968 "(use 'hg revert %s' to unadd the file)\n") |
969 % (f, f)) | 969 % (f, f)) |
970 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): | 970 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
971 self.ui.warn(_("%s not added: only files and symlinks " | 971 self.ui.warn(_("%s not added: only files and symlinks " |
972 "supported currently\n") % f) | 972 "supported currently\n") % f) |
973 elif self.dirstate.state(f) in 'an': | 973 elif self.dirstate[f] in 'an': |
974 self.ui.warn(_("%s already tracked!\n") % f) | 974 self.ui.warn(_("%s already tracked!\n") % f) |
975 else: | 975 else: |
976 self.dirstate.add(f) | 976 self.dirstate.add(f) |
977 | 977 |
978 def forget(self, list, wlock=None): | 978 def forget(self, list, wlock=None): |
979 if not wlock: | 979 if not wlock: |
980 wlock = self.wlock() | 980 wlock = self.wlock() |
981 for f in list: | 981 for f in list: |
982 if self.dirstate.state(f) not in 'ai': | 982 if self.dirstate[f] != 'a': |
983 self.ui.warn(_("%s not added!\n") % f) | 983 self.ui.warn(_("%s not added!\n") % f) |
984 else: | 984 else: |
985 self.dirstate.forget(f) | 985 self.dirstate.forget(f) |
986 | 986 |
987 def remove(self, list, unlink=False, wlock=None): | 987 def remove(self, list, unlink=False, wlock=None): |
995 if not wlock: | 995 if not wlock: |
996 wlock = self.wlock() | 996 wlock = self.wlock() |
997 for f in list: | 997 for f in list: |
998 if unlink and os.path.exists(self.wjoin(f)): | 998 if unlink and os.path.exists(self.wjoin(f)): |
999 self.ui.warn(_("%s still exists!\n") % f) | 999 self.ui.warn(_("%s still exists!\n") % f) |
1000 elif self.dirstate.state(f) == 'a': | 1000 elif self.dirstate[f] == 'a': |
1001 self.dirstate.forget(f) | 1001 self.dirstate.forget(f) |
1002 elif f not in self.dirstate: | 1002 elif f not in self.dirstate: |
1003 self.ui.warn(_("%s not tracked!\n") % f) | 1003 self.ui.warn(_("%s not tracked!\n") % f) |
1004 else: | 1004 else: |
1005 self.dirstate.remove(f) | 1005 self.dirstate.remove(f) |
1009 mn = self.changelog.read(p)[0] | 1009 mn = self.changelog.read(p)[0] |
1010 m = self.manifest.read(mn) | 1010 m = self.manifest.read(mn) |
1011 if not wlock: | 1011 if not wlock: |
1012 wlock = self.wlock() | 1012 wlock = self.wlock() |
1013 for f in list: | 1013 for f in list: |
1014 if self.dirstate.state(f) not in "r": | 1014 if self.dirstate[f] != 'r': |
1015 self.ui.warn("%s not removed!\n" % f) | 1015 self.ui.warn("%s not removed!\n" % f) |
1016 else: | 1016 else: |
1017 t = self.file(f).read(m[f]) | 1017 t = self.file(f).read(m[f]) |
1018 self.wwrite(f, t, m.flags(f)) | 1018 self.wwrite(f, t, m.flags(f)) |
1019 self.dirstate.normal(f) | 1019 self.dirstate.normal(f) |
1026 self.ui.warn(_("copy failed: %s is not a file or a " | 1026 self.ui.warn(_("copy failed: %s is not a file or a " |
1027 "symbolic link\n") % dest) | 1027 "symbolic link\n") % dest) |
1028 else: | 1028 else: |
1029 if not wlock: | 1029 if not wlock: |
1030 wlock = self.wlock() | 1030 wlock = self.wlock() |
1031 if self.dirstate.state(dest) == '?': | 1031 if dest not in self.dirstate: |
1032 self.dirstate.add(dest) | 1032 self.dirstate.add(dest) |
1033 self.dirstate.copy(source, dest) | 1033 self.dirstate.copy(source, dest) |
1034 | 1034 |
1035 def heads(self, start=None): | 1035 def heads(self, start=None): |
1036 heads = self.changelog.heads(start) | 1036 heads = self.changelog.heads(start) |