Mercurial > hg
annotate mercurial/bookmarks.py @ 17995:a5d85476da6e
clfilter: ensure `branchcache` logic runs unfiltered
The current branchcache construction is not aware of filtering. We keep
the status quo, ensuring that the branch cache logic is computed as
before: without any filtering.
author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
---|---|
date | Mon, 26 Nov 2012 19:25:44 +0100 |
parents | 7f5dab94e48c |
children | cf91b36f368c |
rev | line source |
---|---|
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
1 # Mercurial bookmark support code |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
2 # |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
3 # Copyright 2008 David Soria Parra <dsp@php.net> |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
4 # |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
7 |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
8 from mercurial.i18n import _ |
14064
e4bfb9c337f3
remove unused imports and variables
Alexander Solovyov <alexander@solovyov.net>
parents:
14039
diff
changeset
|
9 from mercurial.node import hex |
17916
ed225834b372
bookmark: simplify mutability check in `validdest`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17866
diff
changeset
|
10 from mercurial import encoding, error, util, obsolete |
14027
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
11 import errno, os |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
12 |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
13 class bmstore(dict): |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
14 """Storage for bookmarks. |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
15 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
16 This object should do all bookmark reads and writes, so that it's |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
17 fairly simple to replace the storage underlying bookmarks without |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
18 having to clone the logic surrounding bookmarks. |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
19 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
20 This particular bmstore implementation stores bookmarks as |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
21 {hash}\s{name}\n (the same format as localtags) in |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
22 .hg/bookmarks. The mapping is stored as {name: nodeid}. |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
23 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
24 This class does NOT handle the "current" bookmark state at this |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
25 time. |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
26 """ |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
27 |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
28 def __init__(self, repo): |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
29 dict.__init__(self) |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
30 self._repo = repo |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
31 try: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
32 for line in repo.vfs('bookmarks'): |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
33 line = line.strip() |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
34 if not line: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
35 continue |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
36 if ' ' not in line: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
37 repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n') |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
38 % line) |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
39 continue |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
40 sha, refspec = line.split(' ', 1) |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
41 refspec = encoding.tolocal(refspec) |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
42 try: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
43 self[refspec] = repo.changelog.lookup(sha) |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
44 except LookupError: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
45 pass |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
46 except IOError, inst: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
47 if inst.errno != errno.ENOENT: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
48 raise |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
49 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
50 def write(self): |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
51 '''Write bookmarks |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
52 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
53 Write the given bookmark => hash dictionary to the .hg/bookmarks file |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
54 in a format equal to those of localtags. |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
55 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
56 We also store a backup of the previous state in undo.bookmarks that |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
57 can be copied back on rollback. |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
58 ''' |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
59 repo = self._repo |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
60 if repo._bookmarkcurrent not in self: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
61 setcurrent(repo, None) |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
62 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
63 wlock = repo.wlock() |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
64 try: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
65 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
66 file = repo.vfs('bookmarks', 'w', atomictemp=True) |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
67 for name, node in self.iteritems(): |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
68 file.write("%s %s\n" % (hex(node), encoding.fromlocal(name))) |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
69 file.close() |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
70 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
71 # touch 00changelog.i so hgweb reloads bookmarks (no lock needed) |
14027
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
72 try: |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
73 os.utime(repo.sjoin('00changelog.i'), None) |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
74 except OSError: |
14027
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
75 pass |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
76 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
77 finally: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
78 wlock.release() |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
79 |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
80 def readcurrent(repo): |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
81 '''Get the current bookmark |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
82 |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
83 If we use gittishsh branches we have a current bookmark that |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
84 we are on. This function returns the name of the bookmark. It |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
85 is stored in .hg/bookmarks.current |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
86 ''' |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
87 mark = None |
14027
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
88 try: |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
89 file = repo.opener('bookmarks.current') |
14027
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
90 except IOError, inst: |
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
91 if inst.errno != errno.ENOENT: |
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
92 raise |
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
93 return None |
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
94 try: |
17425
e95ec38f86b0
fix wording and not-completely-trivial spelling errors and bad docstrings
Mads Kiilerich <mads@kiilerich.com>
parents:
16719
diff
changeset
|
95 # No readline() in osutil.posixfile, reading everything is cheap |
13381
d073468e3c5f
bookmarks: read current bookmark as utf-8 and convert it to local
David Soria Parra <dsp@php.net>
parents:
13354
diff
changeset
|
96 mark = encoding.tolocal((file.readlines() or [''])[0]) |
13627
71a96f6c205d
bookmarks: discard current bookmark if absent from the bookmarks (issue2692)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
13478
diff
changeset
|
97 if mark == '' or mark not in repo._bookmarks: |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
98 mark = None |
14027
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
99 finally: |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
100 file.close() |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
101 return mark |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
102 |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
103 def setcurrent(repo, mark): |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
104 '''Set the name of the bookmark that we are currently on |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
105 |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
106 Set the name of the bookmark that we are on (hg update <bookmark>). |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
107 The name is recorded in .hg/bookmarks.current |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
108 ''' |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
109 current = repo._bookmarkcurrent |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
110 if current == mark: |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
111 return |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
112 |
13647
c0c599709846
bookmarks: remove API limitation in setcurrent
David Soria Parra <dsp@php.net>
parents:
13646
diff
changeset
|
113 if mark not in repo._bookmarks: |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
114 mark = '' |
13425
0fe36c347c00
bookmarks: forbid \0 \r \n : in bookmark names (BC)
David Soria Parra <dsp@php.net>
parents:
13416
diff
changeset
|
115 |
15908
60cb4f381a78
bookmarks: backout locking change in 12dea4d998ec
Matt Mackall <mpm@selenic.com>
parents:
15887
diff
changeset
|
116 wlock = repo.wlock() |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
117 try: |
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
118 file = repo.opener('bookmarks.current', 'w', atomictemp=True) |
14559
e29821ca94cf
bookmarks: recognize the current bookmark when the local encoding isn't UTF-8
LUO Zheng <xmuluo@gmail.com>
parents:
14268
diff
changeset
|
119 file.write(encoding.fromlocal(mark)) |
15057
774da7121fc9
atomictempfile: make close() consistent with other file-like objects.
Greg Ward <greg@gerg.ca>
parents:
14946
diff
changeset
|
120 file.close() |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
121 finally: |
15908
60cb4f381a78
bookmarks: backout locking change in 12dea4d998ec
Matt Mackall <mpm@selenic.com>
parents:
15887
diff
changeset
|
122 wlock.release() |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
123 repo._bookmarkcurrent = mark |
13352
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
124 |
16191
7c75924a6926
update: delete bookmarks.current when explicitly updating to a rev (issue3276)
Idan Kamara <idankk86@gmail.com>
parents:
15984
diff
changeset
|
125 def unsetcurrent(repo): |
7c75924a6926
update: delete bookmarks.current when explicitly updating to a rev (issue3276)
Idan Kamara <idankk86@gmail.com>
parents:
15984
diff
changeset
|
126 wlock = repo.wlock() |
7c75924a6926
update: delete bookmarks.current when explicitly updating to a rev (issue3276)
Idan Kamara <idankk86@gmail.com>
parents:
15984
diff
changeset
|
127 try: |
16194
6ba530122d8b
bookmarks: restore python 2.4 compatibility
Gilles Moris <gilles.moris@free.fr>
parents:
16191
diff
changeset
|
128 try: |
6ba530122d8b
bookmarks: restore python 2.4 compatibility
Gilles Moris <gilles.moris@free.fr>
parents:
16191
diff
changeset
|
129 util.unlink(repo.join('bookmarks.current')) |
6ba530122d8b
bookmarks: restore python 2.4 compatibility
Gilles Moris <gilles.moris@free.fr>
parents:
16191
diff
changeset
|
130 repo._bookmarkcurrent = None |
6ba530122d8b
bookmarks: restore python 2.4 compatibility
Gilles Moris <gilles.moris@free.fr>
parents:
16191
diff
changeset
|
131 except OSError, inst: |
6ba530122d8b
bookmarks: restore python 2.4 compatibility
Gilles Moris <gilles.moris@free.fr>
parents:
16191
diff
changeset
|
132 if inst.errno != errno.ENOENT: |
6ba530122d8b
bookmarks: restore python 2.4 compatibility
Gilles Moris <gilles.moris@free.fr>
parents:
16191
diff
changeset
|
133 raise |
16191
7c75924a6926
update: delete bookmarks.current when explicitly updating to a rev (issue3276)
Idan Kamara <idankk86@gmail.com>
parents:
15984
diff
changeset
|
134 finally: |
7c75924a6926
update: delete bookmarks.current when explicitly updating to a rev (issue3276)
Idan Kamara <idankk86@gmail.com>
parents:
15984
diff
changeset
|
135 wlock.release() |
7c75924a6926
update: delete bookmarks.current when explicitly updating to a rev (issue3276)
Idan Kamara <idankk86@gmail.com>
parents:
15984
diff
changeset
|
136 |
13663
d16c99f16f00
bundle: update current bookmark to most recent revision on current branch
David Soria Parra <dsp@php.net>
parents:
13647
diff
changeset
|
137 def updatecurrentbookmark(repo, oldnode, curbranch): |
d16c99f16f00
bundle: update current bookmark to most recent revision on current branch
David Soria Parra <dsp@php.net>
parents:
13647
diff
changeset
|
138 try: |
16719
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16706
diff
changeset
|
139 return update(repo, oldnode, repo.branchtip(curbranch)) |
e7bf09acd410
localrepo: add branchtip() method for faster single-branch lookups
Brodie Rao <brodie@sf.io>
parents:
16706
diff
changeset
|
140 except error.RepoLookupError: |
13663
d16c99f16f00
bundle: update current bookmark to most recent revision on current branch
David Soria Parra <dsp@php.net>
parents:
13647
diff
changeset
|
141 if curbranch == "default": # no default branch! |
15621
013688350c7d
bookmarks: update and updatecurrentbookmark return status
Kevin Bullock <kbullock@ringworld.org>
parents:
15614
diff
changeset
|
142 return update(repo, oldnode, repo.lookup("tip")) |
13663
d16c99f16f00
bundle: update current bookmark to most recent revision on current branch
David Soria Parra <dsp@php.net>
parents:
13647
diff
changeset
|
143 else: |
d16c99f16f00
bundle: update current bookmark to most recent revision on current branch
David Soria Parra <dsp@php.net>
parents:
13647
diff
changeset
|
144 raise util.Abort(_("branch %s not found") % curbranch) |
d16c99f16f00
bundle: update current bookmark to most recent revision on current branch
David Soria Parra <dsp@php.net>
parents:
13647
diff
changeset
|
145 |
13352
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
146 def update(repo, parents, node): |
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
147 marks = repo._bookmarks |
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
148 update = False |
16706
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
149 cur = repo._bookmarkcurrent |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
150 if not cur: |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
151 return False |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
152 |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
153 toupdate = [b for b in marks if b.split('@', 1)[0] == cur.split('@', 1)[0]] |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
154 for mark in toupdate: |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
155 if mark and marks[mark] in parents: |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
156 old = repo[marks[mark]] |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
157 new = repo[node] |
17627
84f12b832ee8
bookmarks: use "changectx.descendant()" for efficient descendant examination
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17625
diff
changeset
|
158 if old.descendant(new) and mark == cur: |
16706
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
159 marks[cur] = new.node() |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
160 update = True |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
161 if mark != cur: |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
162 del marks[mark] |
13352
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
163 if update: |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
164 marks.write() |
15621
013688350c7d
bookmarks: update and updatecurrentbookmark return status
Kevin Bullock <kbullock@ringworld.org>
parents:
15614
diff
changeset
|
165 return update |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
166 |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
167 def listbookmarks(repo): |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
168 # We may try to list bookmarks on a repo type that does not |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
169 # support it (e.g., statichttprepository). |
14946
28762bf809d8
bookmarks: use getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents:
14848
diff
changeset
|
170 marks = getattr(repo, '_bookmarks', {}) |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
171 |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
172 d = {} |
14946
28762bf809d8
bookmarks: use getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents:
14848
diff
changeset
|
173 for k, v in marks.iteritems(): |
15613
2fad18f15409
bookmarks: shadow divergent bookmarks of foo with foo@n
Matt Mackall <mpm@selenic.com>
parents:
15237
diff
changeset
|
174 # don't expose local divergent bookmarks |
16276
6b16ded5c810
bookmarks: clone non-divergent bookmarks with @ in them
Kevin Bullock <kbullock@ringworld.org>
parents:
16194
diff
changeset
|
175 if '@' not in k or k.endswith('@'): |
15613
2fad18f15409
bookmarks: shadow divergent bookmarks of foo with foo@n
Matt Mackall <mpm@selenic.com>
parents:
15237
diff
changeset
|
176 d[k] = hex(v) |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
177 return d |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
178 |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
179 def pushbookmark(repo, key, old, new): |
15908
60cb4f381a78
bookmarks: backout locking change in 12dea4d998ec
Matt Mackall <mpm@selenic.com>
parents:
15887
diff
changeset
|
180 w = repo.wlock() |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
181 try: |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
182 marks = repo._bookmarks |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
183 if hex(marks.get(key, '')) != old: |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
184 return False |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
185 if new == '': |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
186 del marks[key] |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
187 else: |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
188 if new not in repo: |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
189 return False |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
190 marks[key] = repo[new].node() |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
191 marks.write() |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
192 return True |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
193 finally: |
15908
60cb4f381a78
bookmarks: backout locking change in 12dea4d998ec
Matt Mackall <mpm@selenic.com>
parents:
15887
diff
changeset
|
194 w.release() |
13354
4e1ba6ead69c
bookmarks: move diff to core
Matt Mackall <mpm@selenic.com>
parents:
13353
diff
changeset
|
195 |
15614
260a6449d83a
bookmarks: mark divergent bookmarks with book@pathalias when source in [paths]
Matt Mackall <mpm@selenic.com>
parents:
15613
diff
changeset
|
196 def updatefromremote(ui, repo, remote, path): |
13646
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
197 ui.debug("checking for updated bookmarks\n") |
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
198 rb = remote.listkeys('bookmarks') |
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
199 changed = False |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
200 localmarks = repo._bookmarks |
13646
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
201 for k in rb.keys(): |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
202 if k in localmarks: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
203 nr, nl = rb[k], localmarks[k] |
13646
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
204 if nr in repo: |
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
205 cr = repo[nr] |
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
206 cl = repo[nl] |
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
207 if cl.rev() >= cr.rev(): |
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
208 continue |
17550
fc530080013b
bookmarks: extract valid destination logic in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17425
diff
changeset
|
209 if validdest(repo, cl, cr): |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
210 localmarks[k] = cr.node() |
13646
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
211 changed = True |
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
212 ui.status(_("updating bookmark %s\n") % k) |
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
213 else: |
17770
6c81b8ebf66e
bookmarks: when @ bookmark diverges, don't double the @ sign (BC)
David M. Carr <david@carrclan.us>
parents:
17738
diff
changeset
|
214 if k == '@': |
6c81b8ebf66e
bookmarks: when @ bookmark diverges, don't double the @ sign (BC)
David M. Carr <david@carrclan.us>
parents:
17738
diff
changeset
|
215 kd = '' |
6c81b8ebf66e
bookmarks: when @ bookmark diverges, don't double the @ sign (BC)
David M. Carr <david@carrclan.us>
parents:
17738
diff
changeset
|
216 else: |
6c81b8ebf66e
bookmarks: when @ bookmark diverges, don't double the @ sign (BC)
David M. Carr <david@carrclan.us>
parents:
17738
diff
changeset
|
217 kd = k |
15614
260a6449d83a
bookmarks: mark divergent bookmarks with book@pathalias when source in [paths]
Matt Mackall <mpm@selenic.com>
parents:
15613
diff
changeset
|
218 # find a unique @ suffix |
15613
2fad18f15409
bookmarks: shadow divergent bookmarks of foo with foo@n
Matt Mackall <mpm@selenic.com>
parents:
15237
diff
changeset
|
219 for x in range(1, 100): |
17770
6c81b8ebf66e
bookmarks: when @ bookmark diverges, don't double the @ sign (BC)
David M. Carr <david@carrclan.us>
parents:
17738
diff
changeset
|
220 n = '%s@%d' % (kd, x) |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
221 if n not in localmarks: |
15613
2fad18f15409
bookmarks: shadow divergent bookmarks of foo with foo@n
Matt Mackall <mpm@selenic.com>
parents:
15237
diff
changeset
|
222 break |
15614
260a6449d83a
bookmarks: mark divergent bookmarks with book@pathalias when source in [paths]
Matt Mackall <mpm@selenic.com>
parents:
15613
diff
changeset
|
223 # try to use an @pathalias suffix |
260a6449d83a
bookmarks: mark divergent bookmarks with book@pathalias when source in [paths]
Matt Mackall <mpm@selenic.com>
parents:
15613
diff
changeset
|
224 # if an @pathalias already exists, we overwrite (update) it |
260a6449d83a
bookmarks: mark divergent bookmarks with book@pathalias when source in [paths]
Matt Mackall <mpm@selenic.com>
parents:
15613
diff
changeset
|
225 for p, u in ui.configitems("paths"): |
260a6449d83a
bookmarks: mark divergent bookmarks with book@pathalias when source in [paths]
Matt Mackall <mpm@selenic.com>
parents:
15613
diff
changeset
|
226 if path == u: |
17770
6c81b8ebf66e
bookmarks: when @ bookmark diverges, don't double the @ sign (BC)
David M. Carr <david@carrclan.us>
parents:
17738
diff
changeset
|
227 n = '%s@%s' % (kd, p) |
15614
260a6449d83a
bookmarks: mark divergent bookmarks with book@pathalias when source in [paths]
Matt Mackall <mpm@selenic.com>
parents:
15613
diff
changeset
|
228 |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
229 localmarks[n] = cr.node() |
15613
2fad18f15409
bookmarks: shadow divergent bookmarks of foo with foo@n
Matt Mackall <mpm@selenic.com>
parents:
15237
diff
changeset
|
230 changed = True |
2fad18f15409
bookmarks: shadow divergent bookmarks of foo with foo@n
Matt Mackall <mpm@selenic.com>
parents:
15237
diff
changeset
|
231 ui.warn(_("divergent bookmark %s stored as %s\n") % (k, n)) |
16697
c285aae10f6c
bookmarks: pull new bookmarks from remote by default (BC)
Levi Bard <levi@unity3d.com>
parents:
16573
diff
changeset
|
232 elif rb[k] in repo: |
c285aae10f6c
bookmarks: pull new bookmarks from remote by default (BC)
Levi Bard <levi@unity3d.com>
parents:
16573
diff
changeset
|
233 # add remote bookmarks for changes we already have |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
234 localmarks[k] = repo[rb[k]].node() |
16697
c285aae10f6c
bookmarks: pull new bookmarks from remote by default (BC)
Levi Bard <levi@unity3d.com>
parents:
16573
diff
changeset
|
235 changed = True |
c285aae10f6c
bookmarks: pull new bookmarks from remote by default (BC)
Levi Bard <levi@unity3d.com>
parents:
16573
diff
changeset
|
236 ui.status(_("adding remote bookmark %s\n") % k) |
15613
2fad18f15409
bookmarks: shadow divergent bookmarks of foo with foo@n
Matt Mackall <mpm@selenic.com>
parents:
15237
diff
changeset
|
237 |
13646
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
238 if changed: |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
239 localmarks.write() |
13646
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
240 |
17667
2b6a795f19f7
bookmarks: rename arguments/variables for source code readability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17627
diff
changeset
|
241 def diff(ui, dst, src): |
13354
4e1ba6ead69c
bookmarks: move diff to core
Matt Mackall <mpm@selenic.com>
parents:
13353
diff
changeset
|
242 ui.status(_("searching for changed bookmarks\n")) |
4e1ba6ead69c
bookmarks: move diff to core
Matt Mackall <mpm@selenic.com>
parents:
13353
diff
changeset
|
243 |
17667
2b6a795f19f7
bookmarks: rename arguments/variables for source code readability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17627
diff
changeset
|
244 smarks = src.listkeys('bookmarks') |
2b6a795f19f7
bookmarks: rename arguments/variables for source code readability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17627
diff
changeset
|
245 dmarks = dst.listkeys('bookmarks') |
13354
4e1ba6ead69c
bookmarks: move diff to core
Matt Mackall <mpm@selenic.com>
parents:
13353
diff
changeset
|
246 |
17667
2b6a795f19f7
bookmarks: rename arguments/variables for source code readability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17627
diff
changeset
|
247 diff = sorted(set(smarks) - set(dmarks)) |
13354
4e1ba6ead69c
bookmarks: move diff to core
Matt Mackall <mpm@selenic.com>
parents:
13353
diff
changeset
|
248 for k in diff: |
17667
2b6a795f19f7
bookmarks: rename arguments/variables for source code readability
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17627
diff
changeset
|
249 mark = ui.debugflag and smarks[k] or smarks[k][:12] |
15984
894f83a35653
bookmarks: respect --debug during incoming/outgoing
David Soria Parra <dsp@php.net>
parents:
15908
diff
changeset
|
250 ui.write(" %-25s %s\n" % (k, mark)) |
13354
4e1ba6ead69c
bookmarks: move diff to core
Matt Mackall <mpm@selenic.com>
parents:
13353
diff
changeset
|
251 |
4e1ba6ead69c
bookmarks: move diff to core
Matt Mackall <mpm@selenic.com>
parents:
13353
diff
changeset
|
252 if len(diff) <= 0: |
4e1ba6ead69c
bookmarks: move diff to core
Matt Mackall <mpm@selenic.com>
parents:
13353
diff
changeset
|
253 ui.status(_("no changed bookmarks found\n")) |
4e1ba6ead69c
bookmarks: move diff to core
Matt Mackall <mpm@selenic.com>
parents:
13353
diff
changeset
|
254 return 1 |
4e1ba6ead69c
bookmarks: move diff to core
Matt Mackall <mpm@selenic.com>
parents:
13353
diff
changeset
|
255 return 0 |
17550
fc530080013b
bookmarks: extract valid destination logic in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17425
diff
changeset
|
256 |
fc530080013b
bookmarks: extract valid destination logic in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17425
diff
changeset
|
257 def validdest(repo, old, new): |
fc530080013b
bookmarks: extract valid destination logic in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17425
diff
changeset
|
258 """Is the new bookmark destination a valid update from the old one""" |
17551
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
259 if old == new: |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
260 # Old == new -> nothing to update. |
17625
b83c18204c36
bookmarks: avoid redundant creation/assignment of "validdests" in "validdest()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17551
diff
changeset
|
261 return False |
17551
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
262 elif not old: |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
263 # old is nullrev, anything is valid. |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
264 # (new != nullrev has been excluded by the previous check) |
17625
b83c18204c36
bookmarks: avoid redundant creation/assignment of "validdests" in "validdest()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17551
diff
changeset
|
265 return True |
17551
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
266 elif repo.obsstore: |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
267 # We only need this complicated logic if there is obsolescence |
17738
b8424c92ba2b
spelling: fix minor spell checker issues
Mads Kiilerich <mads@kiilerich.com>
parents:
17667
diff
changeset
|
268 # XXX will probably deserve an optimised revset. |
17865
daf32ebfde6b
bookmark: prevent crashing when a successor is unknown locally (issue3680)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
269 nm = repo.changelog.nodemap |
17551
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
270 validdests = set([old]) |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
271 plen = -1 |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
272 # compute the whole set of successors or descendants |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
273 while len(validdests) != plen: |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
274 plen = len(validdests) |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
275 succs = set(c.node() for c in validdests) |
17917
12178f07de97
bookmark: issue a single call to `allsuccessors` per loop
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17916
diff
changeset
|
276 mutable = [c.node() for c in validdests if c.mutable()] |
12178f07de97
bookmark: issue a single call to `allsuccessors` per loop
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17916
diff
changeset
|
277 succs.update(obsolete.allsuccessors(repo.obsstore, mutable)) |
17866
75b43843eb4d
bookmark: simplify nodemap check introduced in the previous changeset
Thomas Arendsen Hein <thomas@intevation.de>
parents:
17865
diff
changeset
|
278 known = (n for n in succs if n in nm) |
17865
daf32ebfde6b
bookmark: prevent crashing when a successor is unknown locally (issue3680)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17827
diff
changeset
|
279 validdests = set(repo.set('%ln::', known)) |
17625
b83c18204c36
bookmarks: avoid redundant creation/assignment of "validdests" in "validdest()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17551
diff
changeset
|
280 return new in validdests |
17551
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
281 else: |
17627
84f12b832ee8
bookmarks: use "changectx.descendant()" for efficient descendant examination
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17625
diff
changeset
|
282 return old.descendant(new) |