Mercurial > hg
comparison mercurial/dirstate.py @ 31050:206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
This patch adds new file txnutil.py, because:
- transaction.py is too large to import small utility logic
- scmutil.py or so causes cyclic importing in phases.py
mayhavepending() is defined separately for convenience in subsequent
patch.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Tue, 21 Feb 2017 01:20:59 +0900 |
parents | ad15646dc61c |
children | 49e5491ed9bd |
comparison
equal
deleted
inserted
replaced
31049:20027be9f23d | 31050:206532700213 |
---|---|
21 osutil, | 21 osutil, |
22 parsers, | 22 parsers, |
23 pathutil, | 23 pathutil, |
24 pycompat, | 24 pycompat, |
25 scmutil, | 25 scmutil, |
26 txnutil, | |
26 util, | 27 util, |
27 ) | 28 ) |
28 | 29 |
29 propertycache = util.propertycache | 30 propertycache = util.propertycache |
30 filecache = scmutil.filecache | 31 filecache = scmutil.filecache |
56 try: | 57 try: |
57 return parsers.nonnormalentries(dmap) | 58 return parsers.nonnormalentries(dmap) |
58 except AttributeError: | 59 except AttributeError: |
59 return set(fname for fname, e in dmap.iteritems() | 60 return set(fname for fname, e in dmap.iteritems() |
60 if e[0] != 'n' or e[3] == -1) | 61 if e[0] != 'n' or e[3] == -1) |
61 | |
62 def _trypending(root, vfs, filename): | |
63 '''Open file to be read according to HG_PENDING environment variable | |
64 | |
65 This opens '.pending' of specified 'filename' only when HG_PENDING | |
66 is equal to 'root'. | |
67 | |
68 This returns '(fp, is_pending_opened)' tuple. | |
69 ''' | |
70 if root == encoding.environ.get('HG_PENDING'): | |
71 try: | |
72 return (vfs('%s.pending' % filename), True) | |
73 except IOError as inst: | |
74 if inst.errno != errno.ENOENT: | |
75 raise | |
76 return (vfs(filename), False) | |
77 | 62 |
78 class dirstate(object): | 63 class dirstate(object): |
79 | 64 |
80 def __init__(self, opener, ui, root, validate): | 65 def __init__(self, opener, ui, root, validate): |
81 '''Create a new dirstate object. | 66 '''Create a new dirstate object. |
383 except: # re-raises | 368 except: # re-raises |
384 f.discard() | 369 f.discard() |
385 raise | 370 raise |
386 | 371 |
387 def _opendirstatefile(self): | 372 def _opendirstatefile(self): |
388 fp, mode = _trypending(self._root, self._opener, self._filename) | 373 fp, mode = txnutil.trypending(self._root, self._opener, self._filename) |
389 if self._pendingmode is not None and self._pendingmode != mode: | 374 if self._pendingmode is not None and self._pendingmode != mode: |
390 fp.close() | 375 fp.close() |
391 raise error.Abort(_('working directory state may be ' | 376 raise error.Abort(_('working directory state may be ' |
392 'changed parallelly')) | 377 'changed parallelly')) |
393 self._pendingmode = mode | 378 self._pendingmode = mode |