##// END OF EJS Templates
dirstate: move opendirstatefile to dirstatemap...
Durham Goode -
r34338:c36c3fa7 default
parent child Browse files
Show More
@@ -82,9 +82,6 b' class dirstate(object):'
82 self._origpl = None
82 self._origpl = None
83 self._updatedfiles = set()
83 self._updatedfiles = set()
84
84
85 # for consistent view between _pl() and _read() invocations
86 self._pendingmode = None
87
88 @contextlib.contextmanager
85 @contextlib.contextmanager
89 def parentchange(self):
86 def parentchange(self):
90 '''Context manager for handling dirstate parents.
87 '''Context manager for handling dirstate parents.
@@ -190,7 +187,7 b' class dirstate(object):'
190 @propertycache
187 @propertycache
191 def _pl(self):
188 def _pl(self):
192 try:
189 try:
193 fp = self._opendirstatefile()
190 fp = self._map._opendirstatefile()
194 st = fp.read(40)
191 st = fp.read(40)
195 fp.close()
192 fp.close()
196 l = len(st)
193 l = len(st)
@@ -401,23 +398,14 b' class dirstate(object):'
401 f.discard()
398 f.discard()
402 raise
399 raise
403
400
404 def _opendirstatefile(self):
405 fp, mode = txnutil.trypending(self._root, self._opener, self._filename)
406 if self._pendingmode is not None and self._pendingmode != mode:
407 fp.close()
408 raise error.Abort(_('working directory state may be '
409 'changed parallelly'))
410 self._pendingmode = mode
411 return fp
412
413 def _read(self):
401 def _read(self):
414 self._map = dirstatemap()
402 self._map = dirstatemap(self._ui, self._opener, self._root)
415
403
416 # ignore HG_PENDING because identity is used only for writing
404 # ignore HG_PENDING because identity is used only for writing
417 self._identity = util.filestat.frompath(
405 self._identity = util.filestat.frompath(
418 self._opener.join(self._filename))
406 self._opener.join(self._filename))
419 try:
407 try:
420 fp = self._opendirstatefile()
408 fp = self._map._opendirstatefile()
421 try:
409 try:
422 st = fp.read()
410 st = fp.read()
423 finally:
411 finally:
@@ -698,7 +686,7 b' class dirstate(object):'
698 return path
686 return path
699
687
700 def clear(self):
688 def clear(self):
701 self._map = dirstatemap()
689 self._map = dirstatemap(self._ui, self._opener, self._root)
702 self._nonnormalset = set()
690 self._nonnormalset = set()
703 self._otherparentset = set()
691 self._otherparentset = set()
704 if "_dirs" in self.__dict__:
692 if "_dirs" in self.__dict__:
@@ -1308,10 +1296,18 b' class dirstate(object):'
1308 self._opener.unlink(backupname)
1296 self._opener.unlink(backupname)
1309
1297
1310 class dirstatemap(object):
1298 class dirstatemap(object):
1311 def __init__(self):
1299 def __init__(self, ui, opener, root):
1300 self._ui = ui
1301 self._opener = opener
1302 self._root = root
1303 self._filename = 'dirstate'
1304
1312 self._map = {}
1305 self._map = {}
1313 self.copymap = {}
1306 self.copymap = {}
1314
1307
1308 # for consistent view between _pl() and _read() invocations
1309 self._pendingmode = None
1310
1315 def iteritems(self):
1311 def iteritems(self):
1316 return self._map.iteritems()
1312 return self._map.iteritems()
1317
1313
@@ -1375,3 +1371,13 b' class dirstatemap(object):'
1375 current dirstate.
1371 current dirstate.
1376 """
1372 """
1377 return util.dirs(self._map, 'r')
1373 return util.dirs(self._map, 'r')
1374
1375 def _opendirstatefile(self):
1376 fp, mode = txnutil.trypending(self._root, self._opener, self._filename)
1377 if self._pendingmode is not None and self._pendingmode != mode:
1378 fp.close()
1379 raise error.Abort(_('working directory state may be '
1380 'changed parallelly'))
1381 self._pendingmode = mode
1382 return fp
1383
General Comments 0
You need to be logged in to leave comments. Login now