Mercurial > hg
comparison mercurial/bookmarks.py @ 31052:0332b8fafd05
bookmarks: check HG_PENDING strictly
Before this patch, checking HG_PENDING in bookmarks.py might cause
unintentional reading unrelated '.hg/bookmarks.pending' in, because it
just examines existence of HG_PENDING environment variable.
This patch uses txnutil.trypending() to check HG_PENDING strictly.
This patch also changes share extension.
Enabling share extension (+ bookmark sharing) makes
bookmarks._getbkfile() receive repo to be shared (= "srcrepo"). On the
other hand, HG_PENDING always refers current working repo (=
"currepo"), and bookmarks.pending is written only into currepo.
Therefore, we should try to read .hg/bookmarks.pending of currepo in
at first. If it doesn't exist, we try to read .hg/bookmarks of srcrepo
in.
Even after this patch, an external hook spawned in currepo can't see
pending changes in currepo via srcrepo, even though such changes
become visible after closing transaction, because there is no easy and
cheap way to know existence of pending changes in currepo via srcrepo.
Please see https://www.mercurial-scm.org/wiki/SharedRepository, too.
BTW, this patch may cause failure of bisect in the repository of
Mercurial itself, if examination at bisecting assumes that an external
hook can see all pending changes while nested transactions across
repositories.
This invisibility issue will be fixed by subsequent patch, which
allows HG_PENDING to refer multiple repositories.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Tue, 21 Feb 2017 01:21:00 +0900 |
parents | ad15646dc61c |
children | 8a32d6352196 |
comparison
equal
deleted
inserted
replaced
31051:96eaefd350ae | 31052:0332b8fafd05 |
---|---|
17 from . import ( | 17 from . import ( |
18 encoding, | 18 encoding, |
19 error, | 19 error, |
20 lock as lockmod, | 20 lock as lockmod, |
21 obsolete, | 21 obsolete, |
22 txnutil, | |
22 util, | 23 util, |
23 ) | 24 ) |
24 | 25 |
25 def _getbkfile(repo): | 26 def _getbkfile(repo): |
26 """Hook so that extensions that mess with the store can hook bm storage. | 27 """Hook so that extensions that mess with the store can hook bm storage. |
27 | 28 |
28 For core, this just handles wether we should see pending | 29 For core, this just handles wether we should see pending |
29 bookmarks or the committed ones. Other extensions (like share) | 30 bookmarks or the committed ones. Other extensions (like share) |
30 may need to tweak this behavior further. | 31 may need to tweak this behavior further. |
31 """ | 32 """ |
32 bkfile = None | 33 fp, pending = txnutil.trypending(repo.root, repo.vfs, 'bookmarks') |
33 if 'HG_PENDING' in encoding.environ: | 34 return fp |
34 try: | |
35 bkfile = repo.vfs('bookmarks.pending') | |
36 except IOError as inst: | |
37 if inst.errno != errno.ENOENT: | |
38 raise | |
39 if bkfile is None: | |
40 bkfile = repo.vfs('bookmarks') | |
41 return bkfile | |
42 | |
43 | 35 |
44 class bmstore(dict): | 36 class bmstore(dict): |
45 """Storage for bookmarks. | 37 """Storage for bookmarks. |
46 | 38 |
47 This object should do all bookmark-related reads and writes, so | 39 This object should do all bookmark-related reads and writes, so |