comparison mercurial/localrepo.py @ 11303:a1aad8333864

move working dir/dirstate methods from localrepo to workingctx
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Mon, 07 Jun 2010 20:03:32 +0200
parents 3d0591a66118
children b9eb005c54ad
comparison
equal deleted inserted replaced
11302:e1dde7363601 11303:a1aad8333864
14 import match as matchmod 14 import match as matchmod
15 import merge as mergemod 15 import merge as mergemod
16 import tags as tagsmod 16 import tags as tagsmod
17 import url as urlmod 17 import url as urlmod
18 from lock import release 18 from lock import release
19 import weakref, stat, errno, os, time, inspect 19 import weakref, errno, os, time, inspect
20 propertycache = util.propertycache 20 propertycache = util.propertycache
21 21
22 class localrepository(repo.repository): 22 class localrepository(repo.repository):
23 capabilities = set(('lookup', 'changegroupsubset', 'branchmap')) 23 capabilities = set(('lookup', 'changegroupsubset', 'branchmap'))
24 supported = set('revlogv1 store fncache shared'.split()) 24 supported = set('revlogv1 store fncache shared'.split())
208 208
209 # committed tags are stored in UTF-8 209 # committed tags are stored in UTF-8
210 writetags(fp, names, encoding.fromlocal, prevtags) 210 writetags(fp, names, encoding.fromlocal, prevtags)
211 211
212 if '.hgtags' not in self.dirstate: 212 if '.hgtags' not in self.dirstate:
213 self.add(['.hgtags']) 213 self[None].add(['.hgtags'])
214 214
215 m = matchmod.exact(self.root, '', ['.hgtags']) 215 m = matchmod.exact(self.root, '', ['.hgtags'])
216 tagnode = self.commit(message, user, date, extra=extra, match=m) 216 tagnode = self.commit(message, user, date, extra=extra, match=m)
217 217
218 for name in names: 218 for name in names:
1109 removed = mf1.keys() 1109 removed = mf1.keys()
1110 1110
1111 r = modified, added, removed, deleted, unknown, ignored, clean 1111 r = modified, added, removed, deleted, unknown, ignored, clean
1112 [l.sort() for l in r] 1112 [l.sort() for l in r]
1113 return r 1113 return r
1114
1115 def add(self, list):
1116 wlock = self.wlock()
1117 try:
1118 rejected = []
1119 for f in list:
1120 p = self.wjoin(f)
1121 try:
1122 st = os.lstat(p)
1123 except:
1124 self.ui.warn(_("%s does not exist!\n") % f)
1125 rejected.append(f)
1126 continue
1127 if st.st_size > 10000000:
1128 self.ui.warn(_("%s: up to %d MB of RAM may be required "
1129 "to manage this file\n"
1130 "(use 'hg revert %s' to cancel the "
1131 "pending addition)\n")
1132 % (f, 3 * st.st_size // 1000000, f))
1133 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
1134 self.ui.warn(_("%s not added: only files and symlinks "
1135 "supported currently\n") % f)
1136 rejected.append(p)
1137 elif self.dirstate[f] in 'amn':
1138 self.ui.warn(_("%s already tracked!\n") % f)
1139 elif self.dirstate[f] == 'r':
1140 self.dirstate.normallookup(f)
1141 else:
1142 self.dirstate.add(f)
1143 return rejected
1144 finally:
1145 wlock.release()
1146
1147 def forget(self, list):
1148 wlock = self.wlock()
1149 try:
1150 for f in list:
1151 if self.dirstate[f] != 'a':
1152 self.ui.warn(_("%s not added!\n") % f)
1153 else:
1154 self.dirstate.forget(f)
1155 finally:
1156 wlock.release()
1157
1158 def remove(self, list, unlink=False):
1159 if unlink:
1160 for f in list:
1161 try:
1162 util.unlink(self.wjoin(f))
1163 except OSError, inst:
1164 if inst.errno != errno.ENOENT:
1165 raise
1166 wlock = self.wlock()
1167 try:
1168 for f in list:
1169 if unlink and os.path.exists(self.wjoin(f)):
1170 self.ui.warn(_("%s still exists!\n") % f)
1171 elif self.dirstate[f] == 'a':
1172 self.dirstate.forget(f)
1173 elif f not in self.dirstate:
1174 self.ui.warn(_("%s not tracked!\n") % f)
1175 else:
1176 self.dirstate.remove(f)
1177 finally:
1178 wlock.release()
1179
1180 def undelete(self, list):
1181 manifests = [self.manifest.read(self.changelog.read(p)[0])
1182 for p in self.dirstate.parents() if p != nullid]
1183 wlock = self.wlock()
1184 try:
1185 for f in list:
1186 if self.dirstate[f] != 'r':
1187 self.ui.warn(_("%s not removed!\n") % f)
1188 else:
1189 m = f in manifests[0] and manifests[0] or manifests[1]
1190 t = self.file(f).read(m[f])
1191 self.wwrite(f, t, m.flags(f))
1192 self.dirstate.normal(f)
1193 finally:
1194 wlock.release()
1195
1196 def copy(self, source, dest):
1197 p = self.wjoin(dest)
1198 if not (os.path.exists(p) or os.path.islink(p)):
1199 self.ui.warn(_("%s does not exist!\n") % dest)
1200 elif not (os.path.isfile(p) or os.path.islink(p)):
1201 self.ui.warn(_("copy failed: %s is not a file or a "
1202 "symbolic link\n") % dest)
1203 else:
1204 wlock = self.wlock()
1205 try:
1206 if self.dirstate[dest] in '?r':
1207 self.dirstate.add(dest)
1208 self.dirstate.copy(source, dest)
1209 finally:
1210 wlock.release()
1211 1114
1212 def heads(self, start=None): 1115 def heads(self, start=None):
1213 heads = self.changelog.heads(start) 1116 heads = self.changelog.heads(start)
1214 # sort the output in rev descending order 1117 # sort the output in rev descending order
1215 heads = [(-self.changelog.rev(h), h) for h in heads] 1118 heads = [(-self.changelog.rev(h), h) for h in heads]