Mercurial > hg
annotate mercurial/txnutil.py @ 39845:e6d3d39cc1c7
revlog: use proper version comparison during verify
Verify appears to want to compare the changelog's revlog version
number with the version number of filelogs and error if they are
different. But what it was actually doing was comparing the full
32-bit header integer, which contains 2 shorts: 1 for the revlog
version number and 1 for feature flags.
This commit tweaks the verification code so it only looks at the
version number component of the header and emits a warning if they
differ.
The new code is more robust because it accounts for future revlog
version numbers without them needing to be special cased.
Differential Revision: https://phab.mercurial-scm.org/D4704
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 19 Sep 2018 11:38:05 -0700 |
parents | 206532700213 |
children | 2372284d9457 |
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 |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
12 from . 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
|
13 encoding, |
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 |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
16 def 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
|
17 '''return whether 'root' may have pending changes, which are |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
18 visible to this process. |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
19 ''' |
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 return root == encoding.environ.get('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
|
21 |
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): |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
23 '''Open file to be read according to HG_PENDING environment variable |
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. |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
29 ''' |
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: |
206532700213
txnutil: factor out the logic to read file in according to HG_PENDING
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
32 return (vfs('%s.pending' % filename, **kwargs), True) |
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) |