##// END OF EJS Templates
bookmarks: check HG_PENDING strictly...
FUJIWARA Katsunori -
r31052:0332b8fa default
parent child Browse files
Show More
@@ -48,6 +48,7 b' from mercurial import ('
48 error,
48 error,
49 extensions,
49 extensions,
50 hg,
50 hg,
51 txnutil,
51 util,
52 util,
52 )
53 )
53
54
@@ -171,7 +172,28 b' def getbkfile(orig, repo):'
171 if _hassharedbookmarks(repo):
172 if _hassharedbookmarks(repo):
172 srcrepo = _getsrcrepo(repo)
173 srcrepo = _getsrcrepo(repo)
173 if srcrepo is not None:
174 if srcrepo is not None:
175 # just orig(srcrepo) doesn't work as expected, because
176 # HG_PENDING refers repo.root.
177 try:
178 fp, pending = txnutil.trypending(repo.root, repo.vfs,
179 'bookmarks')
180 if pending:
181 # only in this case, bookmark information in repo
182 # is up-to-date.
183 return fp
184 fp.close()
185 except IOError as inst:
186 if inst.errno != errno.ENOENT:
187 raise
188
189 # otherwise, we should read bookmarks from srcrepo,
190 # because .hg/bookmarks in srcrepo might be already
191 # changed via another sharing repo
174 repo = srcrepo
192 repo = srcrepo
193
194 # TODO: Pending changes in repo are still invisible in
195 # srcrepo, because bookmarks.pending is written only into repo.
196 # See also https://www.mercurial-scm.org/wiki/SharedRepository
175 return orig(repo)
197 return orig(repo)
176
198
177 def recordchange(orig, self, tr):
199 def recordchange(orig, self, tr):
@@ -19,6 +19,7 b' from . import ('
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
@@ -29,17 +30,8 b' def _getbkfile(repo):'
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.
@@ -896,3 +896,58 b' ensure changelog is written before bookm'
896 $ touch $TESTTMP/unpause
896 $ touch $TESTTMP/unpause
897
897
898 $ cd ..
898 $ cd ..
899
900 check whether HG_PENDING makes pending changes only in related
901 repositories visible to an external hook.
902
903 (emulate a transaction running concurrently by copied
904 .hg/bookmarks.pending in subsequent test)
905
906 $ cat > $TESTTMP/savepending.sh <<EOF
907 > cp .hg/bookmarks.pending .hg/bookmarks.pending.saved
908 > exit 1 # to avoid adding new bookmark for subsequent tests
909 > EOF
910
911 $ hg init unrelated
912 $ cd unrelated
913 $ echo a > a
914 $ hg add a
915 $ hg commit -m '#0'
916 $ hg --config hooks.pretxnclose="sh $TESTTMP/savepending.sh" bookmarks INVISIBLE
917 transaction abort!
918 rollback completed
919 abort: pretxnclose hook exited with status 1
920 [255]
921 $ cp .hg/bookmarks.pending.saved .hg/bookmarks.pending
922
923 (check visible bookmarks while transaction running in repo)
924
925 $ cat > $TESTTMP/checkpending.sh <<EOF
926 > echo "@repo"
927 > hg -R $TESTTMP/repo bookmarks
928 > echo "@unrelated"
929 > hg -R $TESTTMP/unrelated bookmarks
930 > exit 1 # to avoid adding new bookmark for subsequent tests
931 > EOF
932
933 $ cd ../repo
934 $ hg --config hooks.pretxnclose="sh $TESTTMP/checkpending.sh" bookmarks NEW
935 @repo
936 * NEW 6:81dcce76aa0b
937 X2 1:925d80f479bb
938 Y 4:125c9a1d6df6
939 Z 5:5fb12f0f2d51
940 Z@1 1:925d80f479bb
941 Z@2 4:125c9a1d6df6
942 foo 3:9ba5f110a0b3
943 foo@1 0:f7b1eb17ad24
944 foo@2 2:db815d6d32e6
945 four 3:9ba5f110a0b3
946 should-end-on-two 2:db815d6d32e6
947 x y 2:db815d6d32e6
948 @unrelated
949 no bookmarks set
950 transaction abort!
951 rollback completed
952 abort: pretxnclose hook exited with status 1
953 [255]
@@ -154,6 +154,67 b' test sharing bookmarks'
154 * bm1 2:c2e0ac586386
154 * bm1 2:c2e0ac586386
155 bm3 2:c2e0ac586386
155 bm3 2:c2e0ac586386
156
156
157 check whether HG_PENDING makes pending changes only in relatd
158 repositories visible to an external hook.
159
160 In "hg share" case, another transaction can't run in other
161 repositories sharing same source repository, because starting
162 transaction requires locking store of source repository.
163
164 Therefore, this test scenario ignores checking visibility of
165 .hg/bookmakrs.pending in repo2, which shares repo1 without bookmarks.
166
167 $ cat > $TESTTMP/checkbookmarks.sh <<EOF
168 > echo "@repo1"
169 > hg -R $TESTTMP/repo1 bookmarks
170 > echo "@repo2"
171 > hg -R $TESTTMP/repo2 bookmarks
172 > echo "@repo3"
173 > hg -R $TESTTMP/repo3 bookmarks
174 > exit 1 # to avoid adding new bookmark for subsequent tests
175 > EOF
176
177 $ cd ../repo1
178 $ hg --config hooks.pretxnclose="sh $TESTTMP/checkbookmarks.sh" -q book bmX
179 @repo1
180 bm1 2:c2e0ac586386
181 bm3 2:c2e0ac586386
182 * bmX 2:c2e0ac586386
183 @repo2
184 * bm2 3:0e6e70d1d5f1
185 @repo3
186 bm1 2:c2e0ac586386
187 * bm3 2:c2e0ac586386
188 bmX 2:c2e0ac586386
189 transaction abort!
190 rollback completed
191 abort: pretxnclose hook exited with status 1
192 [255]
193 $ hg book bm1
194
195 FYI, in contrast to above test, bmX is invisible in repo1 (= shared
196 src), because (1) HG_PENDING refers only repo3 and (2)
197 "bookmarks.pending" is written only into repo3.
198
199 $ cd ../repo3
200 $ hg --config hooks.pretxnclose="sh $TESTTMP/checkbookmarks.sh" -q book bmX
201 @repo1
202 * bm1 2:c2e0ac586386
203 bm3 2:c2e0ac586386
204 @repo2
205 * bm2 3:0e6e70d1d5f1
206 @repo3
207 bm1 2:c2e0ac586386
208 bm3 2:c2e0ac586386
209 * bmX 2:c2e0ac586386
210 transaction abort!
211 rollback completed
212 abort: pretxnclose hook exited with status 1
213 [255]
214 $ hg book bm3
215
216 $ cd ../repo1
217
157 test that commits work
218 test that commits work
158
219
159 $ echo 'shared bookmarks' > a
220 $ echo 'shared bookmarks' > a
General Comments 0
You need to be logged in to leave comments. Login now