Mercurial > hg
annotate mercurial/txnutil.py @ 47349:7138c863d0a1
dirstate-v2: Skip readdir in status based on directory mtime
When calling `read_dir` during `status` and the directory is found to be
eligible for caching (see code comments), write the directory’s mtime to the
dirstate. The presence of a directory mtime in the dirstate is meaningful
and indicates eligibility.
When an eligible directory mtime is found in the dirstate and `stat()` shows
that the mtime has not changed, `status` can skip calling `read_dir` again
and instead rely on the names of child nodes in the dirstate tree.
The `tempfile` crate is used to create a temporary file in order to use its
modification time as "current time" with the same truncation as other files
and directories would have in their own modification time.
Differential Revision: https://phab.mercurial-scm.org/D10826
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Fri, 28 May 2021 11:48:59 +0200 |
parents | 89a2afe31e82 |
children | 6000f5b25c9b |
rev | line source |
---|---|
31050
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
1 # txnutil.py - transaction related utilities |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
2 # |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
3 # Copyright FUJIWARA Katsunori <foozy@lares.dti.ne.jp> and others |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
4 # |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
7 |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
8 from __future__ import absolute_import |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
9 |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
10 import errno |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
11 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
31050
diff
changeset
|
12 from . import encoding |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
31050
diff
changeset
|
13 |
31050
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
14 |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
15 def mayhavepending(root): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43077
diff
changeset
|
16 """return whether 'root' may have pending changes, which are |
31050
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
17 visible to this process. |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43077
diff
changeset
|
18 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
19 return root == encoding.environ.get(b'HG_PENDING') |
31050
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
20 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
31050
diff
changeset
|
21 |
31050
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
22 def trypending(root, vfs, filename, **kwargs): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43077
diff
changeset
|
23 """Open file to be read according to HG_PENDING environment variable |
31050
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
24 |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
25 This opens '.pending' of specified 'filename' only when HG_PENDING |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
26 is equal to 'root'. |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
27 |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
28 This returns '(fp, is_pending_opened)' tuple. |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43077
diff
changeset
|
29 """ |
31050
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
30 if mayhavepending(root): |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
31 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
32 return (vfs(b'%s.pending' % filename, **kwargs), True) |
31050
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
33 except IOError as inst: |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
34 if inst.errno != errno.ENOENT: |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
35 raise |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
36 return (vfs(filename, **kwargs), False) |