Mercurial > public > mercurial-scm > hg
comparison mercurial/context.py @ 42292:491855ea9d62
context: move flags overrides from committablectx to workingctx
These read from the dirstate, so they shouldn't be used in other
subclasses.
Differential Revision: https://phab.mercurial-scm.org/D6362
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 10 May 2019 21:35:30 -0700 |
parents | a13b30555ffb |
children | 4fbfc893e6b9 |
comparison
equal
deleted
inserted
replaced
42291:a13b30555ffb | 42292:491855ea9d62 |
---|---|
1134 def __nonzero__(self): | 1134 def __nonzero__(self): |
1135 return True | 1135 return True |
1136 | 1136 |
1137 __bool__ = __nonzero__ | 1137 __bool__ = __nonzero__ |
1138 | 1138 |
1139 def _buildflagfunc(self): | |
1140 # Create a fallback function for getting file flags when the | |
1141 # filesystem doesn't support them | |
1142 | |
1143 copiesget = self._repo.dirstate.copies().get | |
1144 parents = self.parents() | |
1145 if len(parents) < 2: | |
1146 # when we have one parent, it's easy: copy from parent | |
1147 man = parents[0].manifest() | |
1148 def func(f): | |
1149 f = copiesget(f, f) | |
1150 return man.flags(f) | |
1151 else: | |
1152 # merges are tricky: we try to reconstruct the unstored | |
1153 # result from the merge (issue1802) | |
1154 p1, p2 = parents | |
1155 pa = p1.ancestor(p2) | |
1156 m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest() | |
1157 | |
1158 def func(f): | |
1159 f = copiesget(f, f) # may be wrong for merges with copies | |
1160 fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f) | |
1161 if fl1 == fl2: | |
1162 return fl1 | |
1163 if fl1 == fla: | |
1164 return fl2 | |
1165 if fl2 == fla: | |
1166 return fl1 | |
1167 return '' # punt for conflicts | |
1168 | |
1169 return func | |
1170 | |
1171 @propertycache | |
1172 def _flagfunc(self): | |
1173 return self._repo.dirstate.flagfunc(self._buildflagfunc) | |
1174 | |
1175 @propertycache | 1139 @propertycache |
1176 def _status(self): | 1140 def _status(self): |
1177 return self._repo.status() | 1141 return self._repo.status() |
1178 | 1142 |
1179 @propertycache | 1143 @propertycache |
1239 return False | 1203 return False |
1240 | 1204 |
1241 def children(self): | 1205 def children(self): |
1242 return [] | 1206 return [] |
1243 | 1207 |
1244 def flags(self, path): | |
1245 if r'_manifest' in self.__dict__: | |
1246 try: | |
1247 return self._manifest.flags(path) | |
1248 except KeyError: | |
1249 return '' | |
1250 | |
1251 try: | |
1252 return self._flagfunc(path) | |
1253 except OSError: | |
1254 return '' | |
1255 | |
1256 def ancestor(self, c2): | 1208 def ancestor(self, c2): |
1257 """return the "best" ancestor context of self and c2""" | 1209 """return the "best" ancestor context of self and c2""" |
1258 return self._parents[0].ancestor(c2) # punt on two parents for now | 1210 return self._parents[0].ancestor(c2) # punt on two parents for now |
1259 | 1211 |
1260 def walk(self, match): | 1212 def walk(self, match): |
1336 | 1288 |
1337 def _fileinfo(self, path): | 1289 def _fileinfo(self, path): |
1338 # populate __dict__['_manifest'] as workingctx has no _manifestdelta | 1290 # populate __dict__['_manifest'] as workingctx has no _manifestdelta |
1339 self._manifest | 1291 self._manifest |
1340 return super(workingctx, self)._fileinfo(path) | 1292 return super(workingctx, self)._fileinfo(path) |
1293 | |
1294 def _buildflagfunc(self): | |
1295 # Create a fallback function for getting file flags when the | |
1296 # filesystem doesn't support them | |
1297 | |
1298 copiesget = self._repo.dirstate.copies().get | |
1299 parents = self.parents() | |
1300 if len(parents) < 2: | |
1301 # when we have one parent, it's easy: copy from parent | |
1302 man = parents[0].manifest() | |
1303 def func(f): | |
1304 f = copiesget(f, f) | |
1305 return man.flags(f) | |
1306 else: | |
1307 # merges are tricky: we try to reconstruct the unstored | |
1308 # result from the merge (issue1802) | |
1309 p1, p2 = parents | |
1310 pa = p1.ancestor(p2) | |
1311 m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest() | |
1312 | |
1313 def func(f): | |
1314 f = copiesget(f, f) # may be wrong for merges with copies | |
1315 fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f) | |
1316 if fl1 == fl2: | |
1317 return fl1 | |
1318 if fl1 == fla: | |
1319 return fl2 | |
1320 if fl2 == fla: | |
1321 return fl1 | |
1322 return '' # punt for conflicts | |
1323 | |
1324 return func | |
1325 | |
1326 @propertycache | |
1327 def _flagfunc(self): | |
1328 return self._repo.dirstate.flagfunc(self._buildflagfunc) | |
1329 | |
1330 def flags(self, path): | |
1331 if r'_manifest' in self.__dict__: | |
1332 try: | |
1333 return self._manifest.flags(path) | |
1334 except KeyError: | |
1335 return '' | |
1336 | |
1337 try: | |
1338 return self._flagfunc(path) | |
1339 except OSError: | |
1340 return '' | |
1341 | 1341 |
1342 def filectx(self, path, filelog=None): | 1342 def filectx(self, path, filelog=None): |
1343 """get a file context from the working directory""" | 1343 """get a file context from the working directory""" |
1344 return workingfilectx(self._repo, path, workingctx=self, | 1344 return workingfilectx(self._repo, path, workingctx=self, |
1345 filelog=filelog) | 1345 filelog=filelog) |