Mercurial > hg > mercurial-source
annotate mercurial/bookmarks.py @ 36433:fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
In the loop "for mark in names", the rev is same in each iteration, so it does
not makes sense to call unhidehashlikerevs multiple times. Thanks to Yuya for
spotting this.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Mon, 15 Jan 2018 00:16:11 +0530 (2018-01-14) |
parents | 7336ac5e786e |
children | 5a2d505a9174 |
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 |
26501
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26302
diff
changeset
|
8 from __future__ import absolute_import |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26302
diff
changeset
|
9 |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26302
diff
changeset
|
10 import errno |
36040
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
11 import struct |
26501
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26302
diff
changeset
|
12 |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26302
diff
changeset
|
13 from .i18n import _ |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26302
diff
changeset
|
14 from .node import ( |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26302
diff
changeset
|
15 bin, |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26302
diff
changeset
|
16 hex, |
33739
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
17 short, |
36040
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
18 wdirid, |
26501
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26302
diff
changeset
|
19 ) |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26302
diff
changeset
|
20 from . import ( |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26302
diff
changeset
|
21 encoding, |
30104
af849596752c
bookmarks: abort 'push -B .' when no active bookmark
liscju <piotr.listkiewicz@gmail.com>
parents:
30050
diff
changeset
|
22 error, |
33929
7017567ebdf2
obsutil: move 'foreground' to the new modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33875
diff
changeset
|
23 obsutil, |
33875
d170f59f6f55
py3: fix kwargs handling for `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33794
diff
changeset
|
24 pycompat, |
33738
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
33577
diff
changeset
|
25 scmutil, |
31831
0332b8fafd05
bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
31413
diff
changeset
|
26 txnutil, |
26501
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26302
diff
changeset
|
27 util, |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26302
diff
changeset
|
28 ) |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
29 |
33792
4b81776baa7a
commands: move activebookmarklabel to bookmarks module
Sean Farley <sean@farley.io>
parents:
33790
diff
changeset
|
30 # label constants |
4b81776baa7a
commands: move activebookmarklabel to bookmarks module
Sean Farley <sean@farley.io>
parents:
33790
diff
changeset
|
31 # until 3.5, bookmarks.current was the advertised name, not |
4b81776baa7a
commands: move activebookmarklabel to bookmarks module
Sean Farley <sean@farley.io>
parents:
33790
diff
changeset
|
32 # bookmarks.active, so we must use both to avoid breaking old |
4b81776baa7a
commands: move activebookmarklabel to bookmarks module
Sean Farley <sean@farley.io>
parents:
33790
diff
changeset
|
33 # custom styles |
4b81776baa7a
commands: move activebookmarklabel to bookmarks module
Sean Farley <sean@farley.io>
parents:
33790
diff
changeset
|
34 activebookmarklabel = 'bookmarks.active bookmarks.current' |
4b81776baa7a
commands: move activebookmarklabel to bookmarks module
Sean Farley <sean@farley.io>
parents:
33790
diff
changeset
|
35 |
27826
34d26e22a2b0
bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents:
27825
diff
changeset
|
36 def _getbkfile(repo): |
34d26e22a2b0
bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents:
27825
diff
changeset
|
37 """Hook so that extensions that mess with the store can hook bm storage. |
34d26e22a2b0
bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents:
27825
diff
changeset
|
38 |
34d26e22a2b0
bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents:
27825
diff
changeset
|
39 For core, this just handles wether we should see pending |
34d26e22a2b0
bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents:
27825
diff
changeset
|
40 bookmarks or the committed ones. Other extensions (like share) |
34d26e22a2b0
bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents:
27825
diff
changeset
|
41 may need to tweak this behavior further. |
34d26e22a2b0
bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents:
27825
diff
changeset
|
42 """ |
31831
0332b8fafd05
bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
31413
diff
changeset
|
43 fp, pending = txnutil.trypending(repo.root, repo.vfs, 'bookmarks') |
0332b8fafd05
bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
31413
diff
changeset
|
44 return fp |
27826
34d26e22a2b0
bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents:
27825
diff
changeset
|
45 |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
46 class bmstore(dict): |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
47 """Storage for bookmarks. |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
48 |
28353
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
49 This object should do all bookmark-related reads and writes, so |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
50 that it's fairly simple to replace the storage underlying |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
51 bookmarks without having to clone the logic surrounding |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
52 bookmarks. This type also should manage the active bookmark, if |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
53 any. |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
54 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
55 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
|
56 {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
|
57 .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
|
58 """ |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
59 |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
60 def __init__(self, repo): |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
61 dict.__init__(self) |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
62 self._repo = repo |
33521
999aa9cfb4d3
bookmarks: move variable initialization earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33520
diff
changeset
|
63 self._clean = True |
999aa9cfb4d3
bookmarks: move variable initialization earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33520
diff
changeset
|
64 self._aclean = True |
33518
d7522f983f37
bookmarks: explicitly convert to 'node' during initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33517
diff
changeset
|
65 nm = repo.changelog.nodemap |
d7522f983f37
bookmarks: explicitly convert to 'node' during initialization
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33517
diff
changeset
|
66 tonode = bin # force local lookup |
33520
d6924192c0d5
bookmarks: directly use base dict 'setitem'
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33519
diff
changeset
|
67 setitem = dict.__setitem__ |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
68 try: |
33577
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
69 with _getbkfile(repo) as bkfile: |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
70 for line in bkfile: |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
71 line = line.strip() |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
72 if not line: |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
73 continue |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
74 try: |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
75 sha, refspec = line.split(' ', 1) |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
76 node = tonode(sha) |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
77 if node in nm: |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
78 refspec = encoding.tolocal(refspec) |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
79 setitem(self, refspec, node) |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
80 except (TypeError, ValueError): |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
81 # TypeError: |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
82 # - bin(...) |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
83 # ValueError: |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
84 # - node in nm, for non-20-bytes entry |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
85 # - split(...), for string without ' ' |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
86 repo.ui.warn(_('malformed line in .hg/bookmarks: %r\n') |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33576
diff
changeset
|
87 % line) |
26214
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26112
diff
changeset
|
88 except IOError as inst: |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
89 if inst.errno != errno.ENOENT: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
90 raise |
28353
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
91 self._active = _readactive(repo, self) |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
92 |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
93 @property |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
94 def active(self): |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
95 return self._active |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
96 |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
97 @active.setter |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
98 def active(self, mark): |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
99 if mark is not None and mark not in self: |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
100 raise AssertionError('bookmark %s does not exist!' % mark) |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
101 |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
102 self._active = mark |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
103 self._aclean = False |
27827
d9dcc5c09d77
bmstore: add basic clean-state tracking
Augie Fackler <augie@google.com>
parents:
27826
diff
changeset
|
104 |
d9dcc5c09d77
bmstore: add basic clean-state tracking
Augie Fackler <augie@google.com>
parents:
27826
diff
changeset
|
105 def __setitem__(self, *args, **kwargs): |
34300
08bf0ebc6c8e
bookmark: deprecate direct set of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
34299
diff
changeset
|
106 msg = ("'bookmarks[name] = node' is deprecated, " |
08bf0ebc6c8e
bookmark: deprecate direct set of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
34299
diff
changeset
|
107 "use 'bookmarks.applychanges'") |
08bf0ebc6c8e
bookmark: deprecate direct set of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
34299
diff
changeset
|
108 self._repo.ui.deprecwarn(msg, '4.3') |
08bf0ebc6c8e
bookmark: deprecate direct set of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
34299
diff
changeset
|
109 self._set(*args, **kwargs) |
08bf0ebc6c8e
bookmark: deprecate direct set of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
34299
diff
changeset
|
110 |
08bf0ebc6c8e
bookmark: deprecate direct set of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
34299
diff
changeset
|
111 def _set(self, key, value): |
27827
d9dcc5c09d77
bmstore: add basic clean-state tracking
Augie Fackler <augie@google.com>
parents:
27826
diff
changeset
|
112 self._clean = False |
34300
08bf0ebc6c8e
bookmark: deprecate direct set of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
34299
diff
changeset
|
113 return dict.__setitem__(self, key, value) |
27827
d9dcc5c09d77
bmstore: add basic clean-state tracking
Augie Fackler <augie@google.com>
parents:
27826
diff
changeset
|
114 |
d9dcc5c09d77
bmstore: add basic clean-state tracking
Augie Fackler <augie@google.com>
parents:
27826
diff
changeset
|
115 def __delitem__(self, key): |
34301
712a85b3677f
bookmark: deprecate direct del of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
34300
diff
changeset
|
116 msg = ("'del bookmarks[name]' is deprecated, " |
712a85b3677f
bookmark: deprecate direct del of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
34300
diff
changeset
|
117 "use 'bookmarks.applychanges'") |
712a85b3677f
bookmark: deprecate direct del of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
34300
diff
changeset
|
118 self._repo.ui.deprecwarn(msg, '4.3') |
712a85b3677f
bookmark: deprecate direct del of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
34300
diff
changeset
|
119 self._del(key) |
712a85b3677f
bookmark: deprecate direct del of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
34300
diff
changeset
|
120 |
712a85b3677f
bookmark: deprecate direct del of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
34300
diff
changeset
|
121 def _del(self, key): |
27827
d9dcc5c09d77
bmstore: add basic clean-state tracking
Augie Fackler <augie@google.com>
parents:
27826
diff
changeset
|
122 self._clean = False |
d9dcc5c09d77
bmstore: add basic clean-state tracking
Augie Fackler <augie@google.com>
parents:
27826
diff
changeset
|
123 return dict.__delitem__(self, key) |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
124 |
34263
ef54789a947d
bookmark: introduce a 'applychanges' function to gather bookmark movement
Boris Feld <boris.feld@octobus.net>
parents:
33929
diff
changeset
|
125 def applychanges(self, repo, tr, changes): |
ef54789a947d
bookmark: introduce a 'applychanges' function to gather bookmark movement
Boris Feld <boris.feld@octobus.net>
parents:
33929
diff
changeset
|
126 """Apply a list of changes to bookmarks |
ef54789a947d
bookmark: introduce a 'applychanges' function to gather bookmark movement
Boris Feld <boris.feld@octobus.net>
parents:
33929
diff
changeset
|
127 """ |
34299
f9e6e43c7987
bookmark: track bookmark changes at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
34298
diff
changeset
|
128 bmchanges = tr.changes.get('bookmarks') |
34263
ef54789a947d
bookmark: introduce a 'applychanges' function to gather bookmark movement
Boris Feld <boris.feld@octobus.net>
parents:
33929
diff
changeset
|
129 for name, node in changes: |
34299
f9e6e43c7987
bookmark: track bookmark changes at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
34298
diff
changeset
|
130 old = self.get(name) |
34263
ef54789a947d
bookmark: introduce a 'applychanges' function to gather bookmark movement
Boris Feld <boris.feld@octobus.net>
parents:
33929
diff
changeset
|
131 if node is None: |
34301
712a85b3677f
bookmark: deprecate direct del of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
34300
diff
changeset
|
132 self._del(name) |
34263
ef54789a947d
bookmark: introduce a 'applychanges' function to gather bookmark movement
Boris Feld <boris.feld@octobus.net>
parents:
33929
diff
changeset
|
133 else: |
34300
08bf0ebc6c8e
bookmark: deprecate direct set of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
34299
diff
changeset
|
134 self._set(name, node) |
34299
f9e6e43c7987
bookmark: track bookmark changes at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
34298
diff
changeset
|
135 if bmchanges is not None: |
f9e6e43c7987
bookmark: track bookmark changes at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
34298
diff
changeset
|
136 # if a previous value exist preserve the "initial" value |
f9e6e43c7987
bookmark: track bookmark changes at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
34298
diff
changeset
|
137 previous = bmchanges.get(name) |
f9e6e43c7987
bookmark: track bookmark changes at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
34298
diff
changeset
|
138 if previous is not None: |
f9e6e43c7987
bookmark: track bookmark changes at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
34298
diff
changeset
|
139 old = previous[0] |
f9e6e43c7987
bookmark: track bookmark changes at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
34298
diff
changeset
|
140 bmchanges[name] = (old, node) |
34298
3325c7dcabaa
bookmark: deprecate 'recordchange' in favor of 'applychanges'
Boris Feld <boris.feld@octobus.net>
parents:
34297
diff
changeset
|
141 self._recordchange(tr) |
34263
ef54789a947d
bookmark: introduce a 'applychanges' function to gather bookmark movement
Boris Feld <boris.feld@octobus.net>
parents:
33929
diff
changeset
|
142 |
22665
8319f7e78395
bookmark: add a `bmstore.recordupdate` to plug bookmarks into the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22664
diff
changeset
|
143 def recordchange(self, tr): |
34298
3325c7dcabaa
bookmark: deprecate 'recordchange' in favor of 'applychanges'
Boris Feld <boris.feld@octobus.net>
parents:
34297
diff
changeset
|
144 msg = ("'bookmarks.recorchange' is deprecated, " |
3325c7dcabaa
bookmark: deprecate 'recordchange' in favor of 'applychanges'
Boris Feld <boris.feld@octobus.net>
parents:
34297
diff
changeset
|
145 "use 'bookmarks.applychanges'") |
3325c7dcabaa
bookmark: deprecate 'recordchange' in favor of 'applychanges'
Boris Feld <boris.feld@octobus.net>
parents:
34297
diff
changeset
|
146 self._repo.ui.deprecwarn(msg, '4.3') |
3325c7dcabaa
bookmark: deprecate 'recordchange' in favor of 'applychanges'
Boris Feld <boris.feld@octobus.net>
parents:
34297
diff
changeset
|
147 return self._recordchange(tr) |
3325c7dcabaa
bookmark: deprecate 'recordchange' in favor of 'applychanges'
Boris Feld <boris.feld@octobus.net>
parents:
34297
diff
changeset
|
148 |
3325c7dcabaa
bookmark: deprecate 'recordchange' in favor of 'applychanges'
Boris Feld <boris.feld@octobus.net>
parents:
34297
diff
changeset
|
149 def _recordchange(self, tr): |
22665
8319f7e78395
bookmark: add a `bmstore.recordupdate` to plug bookmarks into the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22664
diff
changeset
|
150 """record that bookmarks have been changed in a transaction |
8319f7e78395
bookmark: add a `bmstore.recordupdate` to plug bookmarks into the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22664
diff
changeset
|
151 |
8319f7e78395
bookmark: add a `bmstore.recordupdate` to plug bookmarks into the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22664
diff
changeset
|
152 The transaction is then responsible for updating the file content.""" |
8319f7e78395
bookmark: add a `bmstore.recordupdate` to plug bookmarks into the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22664
diff
changeset
|
153 tr.addfilegenerator('bookmarks', ('bookmarks',), self._write, |
23317
197e17be5407
transaction: use 'location' instead of 'vfs' objects for file generation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23199
diff
changeset
|
154 location='plain') |
22941
da2758c0aca0
bookmarks: inform transaction-related hooks that some bookmarks were moved
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22667
diff
changeset
|
155 tr.hookargs['bookmark_moved'] = '1' |
22665
8319f7e78395
bookmark: add a `bmstore.recordupdate` to plug bookmarks into the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22664
diff
changeset
|
156 |
23469
65e48b8d20f5
bookmarks: factor out repository lookup from writing bookmarks file
Ryan McElroy <rmcelroy@fb.com>
parents:
23458
diff
changeset
|
157 def _writerepo(self, repo): |
65e48b8d20f5
bookmarks: factor out repository lookup from writing bookmarks file
Ryan McElroy <rmcelroy@fb.com>
parents:
23458
diff
changeset
|
158 """Factored out for extensibility""" |
28353
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
159 rbm = repo._bookmarks |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
160 if rbm.active not in self: |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
161 rbm.active = None |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
162 rbm._writeactive() |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
163 |
28454
24b4dbb16c60
with: use context manager for wlock in _writerepo
Bryan O'Sullivan <bryano@fb.com>
parents:
28353
diff
changeset
|
164 with repo.wlock(): |
30050
f92afd23a099
bookmarks: make writing files out avoid ambiguity of file stat
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29834
diff
changeset
|
165 file_ = repo.vfs('bookmarks', 'w', atomictemp=True, |
f92afd23a099
bookmarks: make writing files out avoid ambiguity of file stat
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29834
diff
changeset
|
166 checkambig=True) |
27828
6a1301e22bd7
bmstore: close file in a finally block in _writerepo
Augie Fackler <augie@google.com>
parents:
27827
diff
changeset
|
167 try: |
6a1301e22bd7
bmstore: close file in a finally block in _writerepo
Augie Fackler <augie@google.com>
parents:
27827
diff
changeset
|
168 self._write(file_) |
6a1301e22bd7
bmstore: close file in a finally block in _writerepo
Augie Fackler <augie@google.com>
parents:
27827
diff
changeset
|
169 except: # re-raises |
6a1301e22bd7
bmstore: close file in a finally block in _writerepo
Augie Fackler <augie@google.com>
parents:
27827
diff
changeset
|
170 file_.discard() |
6a1301e22bd7
bmstore: close file in a finally block in _writerepo
Augie Fackler <augie@google.com>
parents:
27827
diff
changeset
|
171 raise |
6a1301e22bd7
bmstore: close file in a finally block in _writerepo
Augie Fackler <augie@google.com>
parents:
27827
diff
changeset
|
172 finally: |
6a1301e22bd7
bmstore: close file in a finally block in _writerepo
Augie Fackler <augie@google.com>
parents:
27827
diff
changeset
|
173 file_.close() |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
174 |
28353
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
175 def _writeactive(self): |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
176 if self._aclean: |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
177 return |
28455
1c5f2c2c046b
with: use context manager for wlock in _writeactive
Bryan O'Sullivan <bryano@fb.com>
parents:
28454
diff
changeset
|
178 with self._repo.wlock(): |
28353
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
179 if self._active is not None: |
30050
f92afd23a099
bookmarks: make writing files out avoid ambiguity of file stat
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29834
diff
changeset
|
180 f = self._repo.vfs('bookmarks.current', 'w', atomictemp=True, |
f92afd23a099
bookmarks: make writing files out avoid ambiguity of file stat
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
29834
diff
changeset
|
181 checkambig=True) |
28353
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
182 try: |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
183 f.write(encoding.fromlocal(self._active)) |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
184 finally: |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
185 f.close() |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
186 else: |
32323 | 187 self._repo.vfs.tryunlink('bookmarks.current') |
28353
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
188 self._aclean = True |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
189 |
22664
6bd685d2a2de
bookmarks: split bookmark serialization and file handling
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22659
diff
changeset
|
190 def _write(self, fp): |
6bd685d2a2de
bookmarks: split bookmark serialization and file handling
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22659
diff
changeset
|
191 for name, node in self.iteritems(): |
6bd685d2a2de
bookmarks: split bookmark serialization and file handling
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22659
diff
changeset
|
192 fp.write("%s %s\n" % (hex(node), encoding.fromlocal(name))) |
27827
d9dcc5c09d77
bmstore: add basic clean-state tracking
Augie Fackler <augie@google.com>
parents:
27826
diff
changeset
|
193 self._clean = True |
29816
e6f490e32863
bookmarks: properly invalidate volatile sets when writing bookmarks
Augie Fackler <augie@google.com>
parents:
28853
diff
changeset
|
194 self._repo.invalidatevolatilesets() |
22664
6bd685d2a2de
bookmarks: split bookmark serialization and file handling
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22659
diff
changeset
|
195 |
28853
e4fe4e903e97
bookmarks: add 'hg push -B .' for pushing the active bookmark (issue4917)
liscju <piotr.listkiewicz@gmail.com>
parents:
28455
diff
changeset
|
196 def expandname(self, bname): |
e4fe4e903e97
bookmarks: add 'hg push -B .' for pushing the active bookmark (issue4917)
liscju <piotr.listkiewicz@gmail.com>
parents:
28455
diff
changeset
|
197 if bname == '.': |
30104
af849596752c
bookmarks: abort 'push -B .' when no active bookmark
liscju <piotr.listkiewicz@gmail.com>
parents:
30050
diff
changeset
|
198 if self.active: |
af849596752c
bookmarks: abort 'push -B .' when no active bookmark
liscju <piotr.listkiewicz@gmail.com>
parents:
30050
diff
changeset
|
199 return self.active |
af849596752c
bookmarks: abort 'push -B .' when no active bookmark
liscju <piotr.listkiewicz@gmail.com>
parents:
30050
diff
changeset
|
200 else: |
af849596752c
bookmarks: abort 'push -B .' when no active bookmark
liscju <piotr.listkiewicz@gmail.com>
parents:
30050
diff
changeset
|
201 raise error.Abort(_("no active bookmark")) |
28853
e4fe4e903e97
bookmarks: add 'hg push -B .' for pushing the active bookmark (issue4917)
liscju <piotr.listkiewicz@gmail.com>
parents:
28455
diff
changeset
|
202 return bname |
e4fe4e903e97
bookmarks: add 'hg push -B .' for pushing the active bookmark (issue4917)
liscju <piotr.listkiewicz@gmail.com>
parents:
28455
diff
changeset
|
203 |
33739
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
204 def checkconflict(self, mark, force=False, target=None): |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
205 """check repo for a potential clash of mark with an existing bookmark, |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
206 branch, or hash |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
207 |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
208 If target is supplied, then check that we are moving the bookmark |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
209 forward. |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
210 |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
211 If force is supplied, then forcibly move the bookmark to a new commit |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
212 regardless if it is a move forward. |
34296
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
34295
diff
changeset
|
213 |
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
34295
diff
changeset
|
214 If divergent bookmark are to be deleted, they will be returned as list. |
33739
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
215 """ |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
216 cur = self._repo.changectx('.').node() |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
217 if mark in self and not force: |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
218 if target: |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
219 if self[mark] == target and target == cur: |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
220 # re-activating a bookmark |
34296
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
34295
diff
changeset
|
221 return [] |
33739
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
222 rev = self._repo[target].rev() |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
223 anc = self._repo.changelog.ancestors([rev]) |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
224 bmctx = self._repo[self[mark]] |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
225 divs = [self._repo[b].node() for b in self |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
226 if b.split('@', 1)[0] == mark.split('@', 1)[0]] |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
227 |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
228 # allow resolving a single divergent bookmark even if moving |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
229 # the bookmark across branches when a revision is specified |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
230 # that contains a divergent bookmark |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
231 if bmctx.rev() not in anc and target in divs: |
34296
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
34295
diff
changeset
|
232 return divergent2delete(self._repo, [target], mark) |
33739
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
233 |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
234 deletefrom = [b for b in divs |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
235 if self._repo[b].rev() in anc or b == target] |
34296
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
34295
diff
changeset
|
236 delbms = divergent2delete(self._repo, deletefrom, mark) |
33739
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
237 if validdest(self._repo, bmctx, self._repo[target]): |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
238 self._repo.ui.status( |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
239 _("moving bookmark '%s' forward from %s\n") % |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
240 (mark, short(bmctx.node()))) |
34296
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
34295
diff
changeset
|
241 return delbms |
33739
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
242 raise error.Abort(_("bookmark '%s' already exists " |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
243 "(use -f to force)") % mark) |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
244 if ((mark in self._repo.branchmap() or |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
245 mark == self._repo.dirstate.branch()) and not force): |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
246 raise error.Abort( |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
247 _("a bookmark cannot have the name of an existing branch")) |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
248 if len(mark) > 3 and not force: |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
249 try: |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
250 shadowhash = (mark in self._repo) |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
251 except error.LookupError: # ambiguous identifier |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
252 shadowhash = False |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
253 if shadowhash: |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
254 self._repo.ui.warn( |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
255 _("bookmark %s matches a changeset hash\n" |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
256 "(did you leave a -r out of an 'hg bookmark' " |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
257 "command?)\n") |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
258 % mark) |
34296
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
34295
diff
changeset
|
259 return [] |
33739
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
33738
diff
changeset
|
260 |
28353
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
261 def _readactive(repo, marks): |
25281
c44534209a0a
bookmarks: rename readcurrent to readactive (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25280
diff
changeset
|
262 """ |
c44534209a0a
bookmarks: rename readcurrent to readactive (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25280
diff
changeset
|
263 Get the active bookmark. We can have an active bookmark that updates |
c44534209a0a
bookmarks: rename readcurrent to readactive (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25280
diff
changeset
|
264 itself as we commit. This function returns the name of that bookmark. |
c44534209a0a
bookmarks: rename readcurrent to readactive (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25280
diff
changeset
|
265 It is stored in .hg/bookmarks.current |
c44534209a0a
bookmarks: rename readcurrent to readactive (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25280
diff
changeset
|
266 """ |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
267 mark = None |
14027
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
268 try: |
23889
7cc77030c557
localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
23469
diff
changeset
|
269 file = repo.vfs('bookmarks.current') |
26214
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26112
diff
changeset
|
270 except IOError as inst: |
14027
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
271 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
|
272 raise |
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
273 return None |
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
274 try: |
28340
9fbae70faf65
bookmarks: make _readactive safe when readlines raises ENOENT
Augie Fackler <augie@google.com>
parents:
27916
diff
changeset
|
275 # No readline() in osutil.posixfile, reading everything is |
9fbae70faf65
bookmarks: make _readactive safe when readlines raises ENOENT
Augie Fackler <augie@google.com>
parents:
27916
diff
changeset
|
276 # cheap. |
9fbae70faf65
bookmarks: make _readactive safe when readlines raises ENOENT
Augie Fackler <augie@google.com>
parents:
27916
diff
changeset
|
277 # Note that it's possible for readlines() here to raise |
9fbae70faf65
bookmarks: make _readactive safe when readlines raises ENOENT
Augie Fackler <augie@google.com>
parents:
27916
diff
changeset
|
278 # IOError, since we might be reading the active mark over |
9fbae70faf65
bookmarks: make _readactive safe when readlines raises ENOENT
Augie Fackler <augie@google.com>
parents:
27916
diff
changeset
|
279 # static-http which only tries to load the file when we try |
9fbae70faf65
bookmarks: make _readactive safe when readlines raises ENOENT
Augie Fackler <augie@google.com>
parents:
27916
diff
changeset
|
280 # to read from it. |
13381
d073468e3c5f
bookmarks: read current bookmark as utf-8 and convert it to local
David Soria Parra <dsp@php.net>
parents:
13354
diff
changeset
|
281 mark = encoding.tolocal((file.readlines() or [''])[0]) |
28353
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
282 if mark == '' or mark not in marks: |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
283 mark = None |
28340
9fbae70faf65
bookmarks: make _readactive safe when readlines raises ENOENT
Augie Fackler <augie@google.com>
parents:
27916
diff
changeset
|
284 except IOError as inst: |
9fbae70faf65
bookmarks: make _readactive safe when readlines raises ENOENT
Augie Fackler <augie@google.com>
parents:
27916
diff
changeset
|
285 if inst.errno != errno.ENOENT: |
9fbae70faf65
bookmarks: make _readactive safe when readlines raises ENOENT
Augie Fackler <augie@google.com>
parents:
27916
diff
changeset
|
286 raise |
9fbae70faf65
bookmarks: make _readactive safe when readlines raises ENOENT
Augie Fackler <augie@google.com>
parents:
27916
diff
changeset
|
287 return None |
14027
78ab705a8147
bookmarks: be more restrictive in our Exception catching
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
14004
diff
changeset
|
288 finally: |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
289 file.close() |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
290 return mark |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
291 |
25280
e0b0fbd47491
bookmarks: rename setcurrent to activate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25279
diff
changeset
|
292 def activate(repo, mark): |
e0b0fbd47491
bookmarks: rename setcurrent to activate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25279
diff
changeset
|
293 """ |
e0b0fbd47491
bookmarks: rename setcurrent to activate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25279
diff
changeset
|
294 Set the given bookmark to be 'active', meaning that this bookmark will |
e0b0fbd47491
bookmarks: rename setcurrent to activate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25279
diff
changeset
|
295 follow new commits that are made. |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
296 The name is recorded in .hg/bookmarks.current |
25280
e0b0fbd47491
bookmarks: rename setcurrent to activate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25279
diff
changeset
|
297 """ |
28353
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
298 repo._bookmarks.active = mark |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
299 repo._bookmarks._writeactive() |
13352
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
300 |
25279
08ec11e3ae4c
bookmarks: rename unsetcurrent to deactivate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25011
diff
changeset
|
301 def deactivate(repo): |
08ec11e3ae4c
bookmarks: rename unsetcurrent to deactivate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25011
diff
changeset
|
302 """ |
27421
1aee2ab0f902
spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents:
27153
diff
changeset
|
303 Unset the active bookmark in this repository. |
25279
08ec11e3ae4c
bookmarks: rename unsetcurrent to deactivate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25011
diff
changeset
|
304 """ |
28353
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
305 repo._bookmarks.active = None |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
306 repo._bookmarks._writeactive() |
16191
7c75924a6926
update: delete bookmarks.current when explicitly updating to a rev (issue3276)
Idan Kamara <idankk86@gmail.com>
parents:
15984
diff
changeset
|
307 |
25377
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25353
diff
changeset
|
308 def isactivewdirparent(repo): |
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25353
diff
changeset
|
309 """ |
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25353
diff
changeset
|
310 Tell whether the 'active' bookmark (the one that follows new commits) |
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25353
diff
changeset
|
311 points to one of the parents of the current working directory (wdir). |
18471
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
312 |
25377
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25353
diff
changeset
|
313 While this is normally the case, it can on occasion be false; for example, |
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25353
diff
changeset
|
314 immediately after a pull, the active bookmark can be moved to point |
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25353
diff
changeset
|
315 to a place different than the wdir. This is solved by running `hg update`. |
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25353
diff
changeset
|
316 """ |
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25353
diff
changeset
|
317 mark = repo._activebookmark |
18471
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
318 marks = repo._bookmarks |
25377
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25353
diff
changeset
|
319 parents = [p.node() for p in repo[None].parents()] |
18471
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
320 return (mark in marks and marks[mark] in parents) |
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
321 |
34293
07b556d1b74e
bookmark: split out target computation from 'deletedivergent'
Boris Feld <boris.feld@octobus.net>
parents:
34282
diff
changeset
|
322 def divergent2delete(repo, deletefrom, bm): |
07b556d1b74e
bookmark: split out target computation from 'deletedivergent'
Boris Feld <boris.feld@octobus.net>
parents:
34282
diff
changeset
|
323 """find divergent versions of bm on nodes in deletefrom. |
07b556d1b74e
bookmark: split out target computation from 'deletedivergent'
Boris Feld <boris.feld@octobus.net>
parents:
34282
diff
changeset
|
324 |
07b556d1b74e
bookmark: split out target computation from 'deletedivergent'
Boris Feld <boris.feld@octobus.net>
parents:
34282
diff
changeset
|
325 the list of bookmark to delete.""" |
07b556d1b74e
bookmark: split out target computation from 'deletedivergent'
Boris Feld <boris.feld@octobus.net>
parents:
34282
diff
changeset
|
326 todelete = [] |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
327 marks = repo._bookmarks |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
328 divergent = [b for b in marks if b.split('@', 1)[0] == bm.split('@', 1)[0]] |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
329 for mark in divergent: |
21843
92666a869ea4
bookmarks: avoid deleting primary bookmarks on rebase
Matt Mackall <mpm@selenic.com>
parents:
20352
diff
changeset
|
330 if mark == '@' or '@' not in mark: |
92666a869ea4
bookmarks: avoid deleting primary bookmarks on rebase
Matt Mackall <mpm@selenic.com>
parents:
20352
diff
changeset
|
331 # can't be divergent by definition |
92666a869ea4
bookmarks: avoid deleting primary bookmarks on rebase
Matt Mackall <mpm@selenic.com>
parents:
20352
diff
changeset
|
332 continue |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
333 if mark and marks[mark] in deletefrom: |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
334 if mark != bm: |
34293
07b556d1b74e
bookmark: split out target computation from 'deletedivergent'
Boris Feld <boris.feld@octobus.net>
parents:
34282
diff
changeset
|
335 todelete.append(mark) |
07b556d1b74e
bookmark: split out target computation from 'deletedivergent'
Boris Feld <boris.feld@octobus.net>
parents:
34282
diff
changeset
|
336 return todelete |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
337 |
33164
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
338 def headsforactive(repo): |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
339 """Given a repo with an active bookmark, return divergent bookmark nodes. |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
340 |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
341 Args: |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
342 repo: A repository with an active bookmark. |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
343 |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
344 Returns: |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
345 A list of binary node ids that is the full list of other |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
346 revisions with bookmarks divergent from the active bookmark. If |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
347 there were no divergent bookmarks, then this list will contain |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
348 only one entry. |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
349 """ |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
350 if not repo._activebookmark: |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
351 raise ValueError( |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
352 'headsforactive() only makes sense with an active bookmark') |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
353 name = repo._activebookmark.split('@', 1)[0] |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
354 heads = [] |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
355 for mark, n in repo._bookmarks.iteritems(): |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
356 if mark.split('@', 1)[0] == name: |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
357 heads.append(n) |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
358 return heads |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
32323
diff
changeset
|
359 |
19523
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
360 def calculateupdate(ui, repo, checkout): |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
361 '''Return a tuple (targetrev, movemarkfrom) indicating the rev to |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
362 check out and where to move the active bookmark from, if needed.''' |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
363 movemarkfrom = None |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
364 if checkout is None: |
25511
d6e7ac651973
bookmarks: rename current to active in variables and comments
Ryan McElroy <rmcelroy@fb.com>
parents:
25492
diff
changeset
|
365 activemark = repo._activebookmark |
25377
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
25353
diff
changeset
|
366 if isactivewdirparent(repo): |
19523
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
367 movemarkfrom = repo['.'].node() |
25511
d6e7ac651973
bookmarks: rename current to active in variables and comments
Ryan McElroy <rmcelroy@fb.com>
parents:
25492
diff
changeset
|
368 elif activemark: |
d6e7ac651973
bookmarks: rename current to active in variables and comments
Ryan McElroy <rmcelroy@fb.com>
parents:
25492
diff
changeset
|
369 ui.status(_("updating to active bookmark %s\n") % activemark) |
d6e7ac651973
bookmarks: rename current to active in variables and comments
Ryan McElroy <rmcelroy@fb.com>
parents:
25492
diff
changeset
|
370 checkout = activemark |
19523
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
371 return (checkout, movemarkfrom) |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
372 |
13352
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
373 def update(repo, parents, node): |
19110
741d94aa92e4
bookmarks: resolve divergent bookmarks when moving active bookmark forward
Sean Farley <sean.michael.farley@gmail.com>
parents:
18988
diff
changeset
|
374 deletefrom = parents |
13352
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
375 marks = repo._bookmarks |
28353
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
28340
diff
changeset
|
376 active = marks.active |
25511
d6e7ac651973
bookmarks: rename current to active in variables and comments
Ryan McElroy <rmcelroy@fb.com>
parents:
25492
diff
changeset
|
377 if not active: |
16706
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
378 return False |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
379 |
34274
1adcb594eb6b
bookmarks: use 'applychanges' for bookmark update
Boris Feld <boris.feld@octobus.net>
parents:
34268
diff
changeset
|
380 bmchanges = [] |
25511
d6e7ac651973
bookmarks: rename current to active in variables and comments
Ryan McElroy <rmcelroy@fb.com>
parents:
25492
diff
changeset
|
381 if marks[active] in parents: |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
382 new = repo[node] |
19110
741d94aa92e4
bookmarks: resolve divergent bookmarks when moving active bookmark forward
Sean Farley <sean.michael.farley@gmail.com>
parents:
18988
diff
changeset
|
383 divs = [repo[b] for b in marks |
25511
d6e7ac651973
bookmarks: rename current to active in variables and comments
Ryan McElroy <rmcelroy@fb.com>
parents:
25492
diff
changeset
|
384 if b.split('@', 1)[0] == active.split('@', 1)[0]] |
19110
741d94aa92e4
bookmarks: resolve divergent bookmarks when moving active bookmark forward
Sean Farley <sean.michael.farley@gmail.com>
parents:
18988
diff
changeset
|
385 anc = repo.changelog.ancestors([new.rev()]) |
741d94aa92e4
bookmarks: resolve divergent bookmarks when moving active bookmark forward
Sean Farley <sean.michael.farley@gmail.com>
parents:
18988
diff
changeset
|
386 deletefrom = [b.node() for b in divs if b.rev() in anc or b == new] |
25511
d6e7ac651973
bookmarks: rename current to active in variables and comments
Ryan McElroy <rmcelroy@fb.com>
parents:
25492
diff
changeset
|
387 if validdest(repo, repo[marks[active]], new): |
34274
1adcb594eb6b
bookmarks: use 'applychanges' for bookmark update
Boris Feld <boris.feld@octobus.net>
parents:
34268
diff
changeset
|
388 bmchanges.append((active, new.node())) |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
389 |
34295
1424a769f31b
bookmark: use 'divergent2delete' when updating a bookmark
Boris Feld <boris.feld@octobus.net>
parents:
34293
diff
changeset
|
390 for bm in divergent2delete(repo, deletefrom, active): |
1424a769f31b
bookmark: use 'divergent2delete' when updating a bookmark
Boris Feld <boris.feld@octobus.net>
parents:
34293
diff
changeset
|
391 bmchanges.append((bm, None)) |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
392 |
34295
1424a769f31b
bookmark: use 'divergent2delete' when updating a bookmark
Boris Feld <boris.feld@octobus.net>
parents:
34293
diff
changeset
|
393 if bmchanges: |
36362
b9a0de08110e
bookmarks: use context managers for lock and transaction in update()
Martin von Zweigbergk <martinvonz@google.com>
parents:
36040
diff
changeset
|
394 with repo.lock(), repo.transaction('bookmark') as tr: |
34274
1adcb594eb6b
bookmarks: use 'applychanges' for bookmark update
Boris Feld <boris.feld@octobus.net>
parents:
34268
diff
changeset
|
395 marks.applychanges(repo, tr, bmchanges) |
34295
1424a769f31b
bookmark: use 'divergent2delete' when updating a bookmark
Boris Feld <boris.feld@octobus.net>
parents:
34293
diff
changeset
|
396 return bool(bmchanges) |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
397 |
31260
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
30104
diff
changeset
|
398 def listbinbookmarks(repo): |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
30104
diff
changeset
|
399 # We may try to list bookmarks on a repo type that does not |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
30104
diff
changeset
|
400 # support it (e.g., statichttprepository). |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
30104
diff
changeset
|
401 marks = getattr(repo, '_bookmarks', {}) |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
30104
diff
changeset
|
402 |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
30104
diff
changeset
|
403 hasnode = repo.changelog.hasnode |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
30104
diff
changeset
|
404 for k, v in marks.iteritems(): |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
30104
diff
changeset
|
405 # don't expose local divergent bookmarks |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
30104
diff
changeset
|
406 if hasnode(v) and ('@' not in k or k.endswith('@')): |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
30104
diff
changeset
|
407 yield k, v |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
30104
diff
changeset
|
408 |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
409 def listbookmarks(repo): |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
410 d = {} |
31261
55ec13c82ea0
bookmarks: use listbinbookmarks() in listbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
31260
diff
changeset
|
411 for book, node in listbinbookmarks(repo): |
55ec13c82ea0
bookmarks: use listbinbookmarks() in listbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
31260
diff
changeset
|
412 d[book] = hex(node) |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
413 return d |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
414 |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
415 def pushbookmark(repo, key, old, new): |
36363
ac7ee75ee664
bookmarks: use context managers for locks and transaction in pushbookmark()
Martin von Zweigbergk <martinvonz@google.com>
parents:
36362
diff
changeset
|
416 with repo.wlock(), repo.lock(), repo.transaction('bookmarks') as tr: |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
417 marks = repo._bookmarks |
22364
5c153c69fdb2
bookmarks: allow pushkey if new equals current
Durham Goode <durham@fb.com>
parents:
21843
diff
changeset
|
418 existing = hex(marks.get(key, '')) |
5c153c69fdb2
bookmarks: allow pushkey if new equals current
Durham Goode <durham@fb.com>
parents:
21843
diff
changeset
|
419 if existing != old and existing != new: |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
420 return False |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
421 if new == '': |
34268
505021482541
bookmark: use 'applychanges' when updating a bookmark through pushkey
Boris Feld <boris.feld@octobus.net>
parents:
34267
diff
changeset
|
422 changes = [(key, None)] |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
423 else: |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
424 if new not in repo: |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
425 return False |
34268
505021482541
bookmark: use 'applychanges' when updating a bookmark through pushkey
Boris Feld <boris.feld@octobus.net>
parents:
34267
diff
changeset
|
426 changes = [(key, repo[new].node())] |
505021482541
bookmark: use 'applychanges' when updating a bookmark through pushkey
Boris Feld <boris.feld@octobus.net>
parents:
34267
diff
changeset
|
427 marks.applychanges(repo, tr, changes) |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
428 return True |
13354
4e1ba6ead69c
bookmarks: move diff to core
Matt Mackall <mpm@selenic.com>
parents:
13353
diff
changeset
|
429 |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
430 def comparebookmarks(repo, srcmarks, dstmarks, targets=None): |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
431 '''Compare bookmarks between srcmarks and dstmarks |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
432 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
433 This returns tuple "(addsrc, adddst, advsrc, advdst, diverge, |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
434 differ, invalid)", each are list of bookmarks below: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
435 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
436 :addsrc: added on src side (removed on dst side, perhaps) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
437 :adddst: added on dst side (removed on src side, perhaps) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
438 :advsrc: advanced on src side |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
439 :advdst: advanced on dst side |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
440 :diverge: diverge |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
441 :differ: changed, but changeset referred on src is unknown on dst |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
442 :invalid: unknown on both side |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
443 :same: same on both side |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
444 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
445 Each elements of lists in result tuple is tuple "(bookmark name, |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
446 changeset ID on source side, changeset ID on destination |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
447 side)". Each changeset IDs are 40 hexadecimal digit string or |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
448 None. |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
449 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
450 Changeset IDs of tuples in "addsrc", "adddst", "differ" or |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
451 "invalid" list may be unknown for repo. |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
452 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
453 If "targets" is specified, only bookmarks listed in it are |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
454 examined. |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
455 ''' |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
456 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
457 if targets: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
458 bset = set(targets) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
459 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
460 srcmarkset = set(srcmarks) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
461 dstmarkset = set(dstmarks) |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
462 bset = srcmarkset | dstmarkset |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
463 |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
464 results = ([], [], [], [], [], [], [], []) |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
465 addsrc = results[0].append |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
466 adddst = results[1].append |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
467 advsrc = results[2].append |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
468 advdst = results[3].append |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
469 diverge = results[4].append |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
470 differ = results[5].append |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
471 invalid = results[6].append |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
472 same = results[7].append |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
473 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
474 for b in sorted(bset): |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
475 if b not in srcmarks: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
476 if b in dstmarks: |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
477 adddst((b, None, dstmarks[b])) |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
478 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
479 invalid((b, None, None)) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
480 elif b not in dstmarks: |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
481 addsrc((b, srcmarks[b], None)) |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
482 else: |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
483 scid = srcmarks[b] |
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
484 dcid = dstmarks[b] |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
485 if scid == dcid: |
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
486 same((b, scid, dcid)) |
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
487 elif scid in repo and dcid in repo: |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
488 sctx = repo[scid] |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
489 dctx = repo[dcid] |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
490 if sctx.rev() < dctx.rev(): |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
491 if validdest(repo, sctx, dctx): |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
492 advdst((b, scid, dcid)) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
493 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
494 diverge((b, scid, dcid)) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
495 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
496 if validdest(repo, dctx, sctx): |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
497 advsrc((b, scid, dcid)) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
498 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
499 diverge((b, scid, dcid)) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
500 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
501 # it is too expensive to examine in detail, in this case |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
502 differ((b, scid, dcid)) |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
503 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
504 return results |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
505 |
24475
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24474
diff
changeset
|
506 def _diverge(ui, b, path, localmarks, remotenode): |
24473
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24426
diff
changeset
|
507 '''Return appropriate diverged bookmark for specified ``path`` |
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24426
diff
changeset
|
508 |
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24426
diff
changeset
|
509 This returns None, if it is failed to assign any divergent |
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24426
diff
changeset
|
510 bookmark name. |
24475
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24474
diff
changeset
|
511 |
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24474
diff
changeset
|
512 This reuses already existing one with "@number" suffix, if it |
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24474
diff
changeset
|
513 refers ``remotenode``. |
24473
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24426
diff
changeset
|
514 ''' |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
515 if b == '@': |
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
516 b = '' |
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
517 # try to use an @pathalias suffix |
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
518 # if an @pathalias already exists, we overwrite (update) it |
22629
b3f74b405c20
bookmarks: fix divergent bookmark path normalization
Matt Mackall <mpm@selenic.com>
parents:
22627
diff
changeset
|
519 if path.startswith("file:"): |
b3f74b405c20
bookmarks: fix divergent bookmark path normalization
Matt Mackall <mpm@selenic.com>
parents:
22627
diff
changeset
|
520 path = util.url(path).path |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
521 for p, u in ui.configitems("paths"): |
22629
b3f74b405c20
bookmarks: fix divergent bookmark path normalization
Matt Mackall <mpm@selenic.com>
parents:
22627
diff
changeset
|
522 if u.startswith("file:"): |
b3f74b405c20
bookmarks: fix divergent bookmark path normalization
Matt Mackall <mpm@selenic.com>
parents:
22627
diff
changeset
|
523 u = util.url(u).path |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
524 if path == u: |
24474
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24473
diff
changeset
|
525 return '%s@%s' % (b, p) |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24473
diff
changeset
|
526 |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24473
diff
changeset
|
527 # assign a unique "@number" suffix newly |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24473
diff
changeset
|
528 for x in range(1, 100): |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24473
diff
changeset
|
529 n = '%s@%d' % (b, x) |
24475
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24474
diff
changeset
|
530 if n not in localmarks or localmarks[n] == remotenode: |
24474
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24473
diff
changeset
|
531 return n |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24473
diff
changeset
|
532 |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24473
diff
changeset
|
533 return None |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
534 |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
535 def unhexlifybookmarks(marks): |
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
536 binremotemarks = {} |
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
537 for name, node in marks.items(): |
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
538 binremotemarks[name] = bin(node) |
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
539 return binremotemarks |
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
540 |
36040
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
541 _binaryentry = struct.Struct('>20sH') |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
542 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
543 def binaryencode(bookmarks): |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
544 """encode a '(bookmark, node)' iterable into a binary stream |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
545 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
546 the binary format is: |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
547 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
548 <node><bookmark-length><bookmark-name> |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
549 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
550 :node: is a 20 bytes binary node, |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
551 :bookmark-length: an unsigned short, |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
552 :bookmark-name: the name of the bookmark (of length <bookmark-length>) |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
553 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
554 wdirid (all bits set) will be used as a special value for "missing" |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
555 """ |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
556 binarydata = [] |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
557 for book, node in bookmarks: |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
558 if not node: # None or '' |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
559 node = wdirid |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
560 binarydata.append(_binaryentry.pack(node, len(book))) |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
561 binarydata.append(book) |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
562 return ''.join(binarydata) |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
563 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
564 def binarydecode(stream): |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
565 """decode a binary stream into an '(bookmark, node)' iterable |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
566 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
567 the binary format is: |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
568 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
569 <node><bookmark-length><bookmark-name> |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
570 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
571 :node: is a 20 bytes binary node, |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
572 :bookmark-length: an unsigned short, |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
573 :bookmark-name: the name of the bookmark (of length <bookmark-length>)) |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
574 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
575 wdirid (all bits set) will be used as a special value for "missing" |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
576 """ |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
577 entrysize = _binaryentry.size |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
578 books = [] |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
579 while True: |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
580 entry = stream.read(entrysize) |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
581 if len(entry) < entrysize: |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
582 if entry: |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
583 raise error.Abort(_('bad bookmark stream')) |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
584 break |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
585 node, length = _binaryentry.unpack(entry) |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
586 bookmark = stream.read(length) |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
587 if len(bookmark) < length: |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
588 if entry: |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
589 raise error.Abort(_('bad bookmark stream')) |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
590 if node == wdirid: |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
591 node = None |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
592 books.append((bookmark, node)) |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
593 return books |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
35491
diff
changeset
|
594 |
22666
0f8120c1ecf5
pull: perform bookmark updates in the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22665
diff
changeset
|
595 def updatefromremote(ui, repo, remotemarks, path, trfunc, explicit=()): |
13648
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
596 ui.debug("checking for updated bookmarks\n") |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
597 localmarks = repo._bookmarks |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
598 (addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
599 ) = comparebookmarks(repo, remotemarks, localmarks) |
15614
260a6449d83a
bookmarks: mark divergent bookmarks with book@pathalias when source in [paths]
Matt Mackall <mpm@selenic.com>
parents:
15613
diff
changeset
|
600 |
22644
1ec7cdaf898f
bookmarks: allow `updatefromremote` to be quiet
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22629
diff
changeset
|
601 status = ui.status |
1ec7cdaf898f
bookmarks: allow `updatefromremote` to be quiet
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22629
diff
changeset
|
602 warn = ui.warn |
34282
0407a51b9d8c
codemod: register core configitems using a script
Jun Wu <quark@fb.com>
parents:
34274
diff
changeset
|
603 if ui.configbool('ui', 'quietbookmarkmove'): |
22644
1ec7cdaf898f
bookmarks: allow `updatefromremote` to be quiet
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22629
diff
changeset
|
604 status = warn = ui.debug |
1ec7cdaf898f
bookmarks: allow `updatefromremote` to be quiet
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22629
diff
changeset
|
605 |
22659
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
606 explicit = set(explicit) |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
607 changed = [] |
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
608 for b, scid, dcid in addsrc: |
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
609 if scid in repo: # add remote bookmarks for changes we already have |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
610 changed.append((b, scid, status, |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
611 _("adding remote bookmark %s\n") % (b))) |
26107
847fce27effc
bookmark: informs of failure to upgrade a bookmark
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25511
diff
changeset
|
612 elif b in explicit: |
847fce27effc
bookmark: informs of failure to upgrade a bookmark
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25511
diff
changeset
|
613 explicit.remove(b) |
847fce27effc
bookmark: informs of failure to upgrade a bookmark
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25511
diff
changeset
|
614 ui.warn(_("remote bookmark %s points to locally missing %s\n") |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
615 % (b, hex(scid)[:12])) |
26107
847fce27effc
bookmark: informs of failure to upgrade a bookmark
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25511
diff
changeset
|
616 |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
617 for b, scid, dcid in advsrc: |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
618 changed.append((b, scid, status, |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
619 _("updating bookmark %s\n") % (b))) |
22659
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
620 # remove normal movement from explicit set |
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
621 explicit.difference_update(d[0] for d in changed) |
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
622 |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
623 for b, scid, dcid in diverge: |
22659
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
624 if b in explicit: |
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
625 explicit.discard(b) |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
626 changed.append((b, scid, status, |
23199
c35ffa4249ca
bookmarks: fix formatting of exchange message (issue4439)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23081
diff
changeset
|
627 _("importing bookmark %s\n") % (b))) |
22659
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
628 else: |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
629 db = _diverge(ui, b, path, localmarks, scid) |
24473
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24426
diff
changeset
|
630 if db: |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
631 changed.append((db, scid, warn, |
24473
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24426
diff
changeset
|
632 _("divergent bookmark %s stored as %s\n") % |
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24426
diff
changeset
|
633 (b, db))) |
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24426
diff
changeset
|
634 else: |
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24426
diff
changeset
|
635 warn(_("warning: failed to assign numbered name " |
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24426
diff
changeset
|
636 "to divergent bookmark %s\n") % (b)) |
22659
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
637 for b, scid, dcid in adddst + advdst: |
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
638 if b in explicit: |
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
639 explicit.discard(b) |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
640 changed.append((b, scid, status, |
23199
c35ffa4249ca
bookmarks: fix formatting of exchange message (issue4439)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23081
diff
changeset
|
641 _("importing bookmark %s\n") % (b))) |
26107
847fce27effc
bookmark: informs of failure to upgrade a bookmark
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25511
diff
changeset
|
642 for b, scid, dcid in differ: |
847fce27effc
bookmark: informs of failure to upgrade a bookmark
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25511
diff
changeset
|
643 if b in explicit: |
847fce27effc
bookmark: informs of failure to upgrade a bookmark
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25511
diff
changeset
|
644 explicit.remove(b) |
847fce27effc
bookmark: informs of failure to upgrade a bookmark
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25511
diff
changeset
|
645 ui.warn(_("remote bookmark %s points to locally missing %s\n") |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
646 % (b, hex(scid)[:12])) |
22659
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
647 |
13648
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
648 if changed: |
22666
0f8120c1ecf5
pull: perform bookmark updates in the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22665
diff
changeset
|
649 tr = trfunc() |
34267
2a8ce4e79a47
bookmark: use 'applychanges' when updating from a remote
Boris Feld <boris.feld@octobus.net>
parents:
34266
diff
changeset
|
650 changes = [] |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
651 for b, node, writer, msg in sorted(changed): |
34267
2a8ce4e79a47
bookmark: use 'applychanges' when updating from a remote
Boris Feld <boris.feld@octobus.net>
parents:
34266
diff
changeset
|
652 changes.append((b, node)) |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
653 writer(msg) |
34267
2a8ce4e79a47
bookmark: use 'applychanges' when updating from a remote
Boris Feld <boris.feld@octobus.net>
parents:
34266
diff
changeset
|
654 localmarks.applychanges(repo, tr, changes) |
13648
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
655 |
24522
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
656 def incoming(ui, repo, other): |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
657 '''Show bookmarks incoming from other to repo |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
658 ''' |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
659 ui.status(_("searching for changed bookmarks\n")) |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
660 |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
661 remotemarks = unhexlifybookmarks(other.listkeys('bookmarks')) |
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
662 r = comparebookmarks(repo, remotemarks, repo._bookmarks) |
24522
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
663 addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
664 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
665 incomings = [] |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
666 if ui.debugflag: |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
667 getid = lambda id: id |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
668 else: |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
669 getid = lambda id: id[:12] |
24799
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24797
diff
changeset
|
670 if ui.verbose: |
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24797
diff
changeset
|
671 def add(b, id, st): |
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24797
diff
changeset
|
672 incomings.append(" %-25s %s %s\n" % (b, getid(id), st)) |
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24797
diff
changeset
|
673 else: |
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24797
diff
changeset
|
674 def add(b, id, st): |
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24797
diff
changeset
|
675 incomings.append(" %-25s %s\n" % (b, getid(id))) |
24522
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
676 for b, scid, dcid in addsrc: |
25011
5947a68fa271
bookmarks: add i18n hints to bookmark sync states
Wagner Bruna <wbruna@yahoo.com>
parents:
24800
diff
changeset
|
677 # i18n: "added" refers to a bookmark |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
678 add(b, hex(scid), _('added')) |
24796
3d7c512b258d
bookmarks: show incoming bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24525
diff
changeset
|
679 for b, scid, dcid in advsrc: |
25011
5947a68fa271
bookmarks: add i18n hints to bookmark sync states
Wagner Bruna <wbruna@yahoo.com>
parents:
24800
diff
changeset
|
680 # i18n: "advanced" refers to a bookmark |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
681 add(b, hex(scid), _('advanced')) |
24796
3d7c512b258d
bookmarks: show incoming bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24525
diff
changeset
|
682 for b, scid, dcid in diverge: |
25011
5947a68fa271
bookmarks: add i18n hints to bookmark sync states
Wagner Bruna <wbruna@yahoo.com>
parents:
24800
diff
changeset
|
683 # i18n: "diverged" refers to a bookmark |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
684 add(b, hex(scid), _('diverged')) |
24796
3d7c512b258d
bookmarks: show incoming bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24525
diff
changeset
|
685 for b, scid, dcid in differ: |
25011
5947a68fa271
bookmarks: add i18n hints to bookmark sync states
Wagner Bruna <wbruna@yahoo.com>
parents:
24800
diff
changeset
|
686 # i18n: "changed" refers to a bookmark |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
687 add(b, hex(scid), _('changed')) |
24522
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
688 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
689 if not incomings: |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
690 ui.status(_("no changed bookmarks found\n")) |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
691 return 1 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
692 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
693 for s in sorted(incomings): |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
694 ui.write(s) |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
695 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
696 return 0 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24475
diff
changeset
|
697 |
24523
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
698 def outgoing(ui, repo, other): |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
699 '''Show bookmarks outgoing from repo to other |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
700 ''' |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
701 ui.status(_("searching for changed bookmarks\n")) |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
702 |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
703 remotemarks = unhexlifybookmarks(other.listkeys('bookmarks')) |
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
704 r = comparebookmarks(repo, repo._bookmarks, remotemarks) |
24523
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
705 addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
706 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
707 outgoings = [] |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
708 if ui.debugflag: |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
709 getid = lambda id: id |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
710 else: |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
711 getid = lambda id: id[:12] |
24800
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24799
diff
changeset
|
712 if ui.verbose: |
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24799
diff
changeset
|
713 def add(b, id, st): |
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24799
diff
changeset
|
714 outgoings.append(" %-25s %s %s\n" % (b, getid(id), st)) |
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24799
diff
changeset
|
715 else: |
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24799
diff
changeset
|
716 def add(b, id, st): |
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24799
diff
changeset
|
717 outgoings.append(" %-25s %s\n" % (b, getid(id))) |
24523
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
718 for b, scid, dcid in addsrc: |
25011
5947a68fa271
bookmarks: add i18n hints to bookmark sync states
Wagner Bruna <wbruna@yahoo.com>
parents:
24800
diff
changeset
|
719 # i18n: "added refers to a bookmark |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
720 add(b, hex(scid), _('added')) |
24797
8ea893ab0572
bookmarks: show outgoing bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24796
diff
changeset
|
721 for b, scid, dcid in adddst: |
25011
5947a68fa271
bookmarks: add i18n hints to bookmark sync states
Wagner Bruna <wbruna@yahoo.com>
parents:
24800
diff
changeset
|
722 # i18n: "deleted" refers to a bookmark |
24800
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24799
diff
changeset
|
723 add(b, ' ' * 40, _('deleted')) |
24797
8ea893ab0572
bookmarks: show outgoing bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24796
diff
changeset
|
724 for b, scid, dcid in advsrc: |
25011
5947a68fa271
bookmarks: add i18n hints to bookmark sync states
Wagner Bruna <wbruna@yahoo.com>
parents:
24800
diff
changeset
|
725 # i18n: "advanced" refers to a bookmark |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
726 add(b, hex(scid), _('advanced')) |
24797
8ea893ab0572
bookmarks: show outgoing bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24796
diff
changeset
|
727 for b, scid, dcid in diverge: |
25011
5947a68fa271
bookmarks: add i18n hints to bookmark sync states
Wagner Bruna <wbruna@yahoo.com>
parents:
24800
diff
changeset
|
728 # i18n: "diverged" refers to a bookmark |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
729 add(b, hex(scid), _('diverged')) |
24797
8ea893ab0572
bookmarks: show outgoing bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24796
diff
changeset
|
730 for b, scid, dcid in differ: |
25011
5947a68fa271
bookmarks: add i18n hints to bookmark sync states
Wagner Bruna <wbruna@yahoo.com>
parents:
24800
diff
changeset
|
731 # i18n: "changed" refers to a bookmark |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
732 add(b, hex(scid), _('changed')) |
24523
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
733 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
734 if not outgoings: |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
735 ui.status(_("no changed bookmarks found\n")) |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
736 return 1 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
737 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
738 for s in sorted(outgoings): |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
739 ui.write(s) |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
740 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
741 return 0 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24522
diff
changeset
|
742 |
24525
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24524
diff
changeset
|
743 def summary(repo, other): |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24524
diff
changeset
|
744 '''Compare bookmarks between repo and other for "hg summary" output |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24524
diff
changeset
|
745 |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24524
diff
changeset
|
746 This returns "(# of incoming, # of outgoing)" tuple. |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24524
diff
changeset
|
747 ''' |
31362
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
748 remotemarks = unhexlifybookmarks(other.listkeys('bookmarks')) |
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
31361
diff
changeset
|
749 r = comparebookmarks(repo, remotemarks, repo._bookmarks) |
24525
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24524
diff
changeset
|
750 addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24524
diff
changeset
|
751 return (len(addsrc), len(adddst)) |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24524
diff
changeset
|
752 |
17545
fc530080013b
bookmarks: extract valid destination logic in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17408
diff
changeset
|
753 def validdest(repo, old, new): |
fc530080013b
bookmarks: extract valid destination logic in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17408
diff
changeset
|
754 """Is the new bookmark destination a valid update from the old one""" |
18007
cf91b36f368c
clfilter: `bookmark.validdest` should run on unfiltered repo
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17922
diff
changeset
|
755 repo = repo.unfiltered() |
17546
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17545
diff
changeset
|
756 if old == new: |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17545
diff
changeset
|
757 # Old == new -> nothing to update. |
17625
b83c18204c36
bookmarks: avoid redundant creation/assignment of "validdests" in "validdest()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17546
diff
changeset
|
758 return False |
17546
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17545
diff
changeset
|
759 elif not old: |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17545
diff
changeset
|
760 # old is nullrev, anything is valid. |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17545
diff
changeset
|
761 # (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:
17546
diff
changeset
|
762 return True |
17546
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17545
diff
changeset
|
763 elif repo.obsstore: |
33929
7017567ebdf2
obsutil: move 'foreground' to the new modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33875
diff
changeset
|
764 return new.node() in obsutil.foreground(repo, [old.node()]) |
17546
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17545
diff
changeset
|
765 else: |
24251
d8e0c591781c
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
23889
diff
changeset
|
766 # still an independent clause as it is lazier (and therefore faster) |
17627
84f12b832ee8
bookmarks: use "changectx.descendant()" for efficient descendant examination
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17625
diff
changeset
|
767 return old.descendant(new) |
33738
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
33577
diff
changeset
|
768 |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
33577
diff
changeset
|
769 def checkformat(repo, mark): |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
33577
diff
changeset
|
770 """return a valid version of a potential bookmark name |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
33577
diff
changeset
|
771 |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
33577
diff
changeset
|
772 Raises an abort error if the bookmark name is not valid. |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
33577
diff
changeset
|
773 """ |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
33577
diff
changeset
|
774 mark = mark.strip() |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
33577
diff
changeset
|
775 if not mark: |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
33577
diff
changeset
|
776 raise error.Abort(_("bookmark names cannot consist entirely of " |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
33577
diff
changeset
|
777 "whitespace")) |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
33577
diff
changeset
|
778 scmutil.checknewlabel(repo, mark, 'bookmark') |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
33577
diff
changeset
|
779 return mark |
33788
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
33739
diff
changeset
|
780 |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
33739
diff
changeset
|
781 def delete(repo, tr, names): |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
33739
diff
changeset
|
782 """remove a mark from the bookmark store |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
33739
diff
changeset
|
783 |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
33739
diff
changeset
|
784 Raises an abort error if mark does not exist. |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
33739
diff
changeset
|
785 """ |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
33739
diff
changeset
|
786 marks = repo._bookmarks |
34264
67b5f81f17cf
bookmark: use 'applychanges' for bookmark deletion
Boris Feld <boris.feld@octobus.net>
parents:
34263
diff
changeset
|
787 changes = [] |
33788
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
33739
diff
changeset
|
788 for mark in names: |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
33739
diff
changeset
|
789 if mark not in marks: |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
33739
diff
changeset
|
790 raise error.Abort(_("bookmark '%s' does not exist") % mark) |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
33739
diff
changeset
|
791 if mark == repo._activebookmark: |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
33739
diff
changeset
|
792 deactivate(repo) |
34264
67b5f81f17cf
bookmark: use 'applychanges' for bookmark deletion
Boris Feld <boris.feld@octobus.net>
parents:
34263
diff
changeset
|
793 changes.append((mark, None)) |
67b5f81f17cf
bookmark: use 'applychanges' for bookmark deletion
Boris Feld <boris.feld@octobus.net>
parents:
34263
diff
changeset
|
794 marks.applychanges(repo, tr, changes) |
33789
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
795 |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
796 def rename(repo, tr, old, new, force=False, inactive=False): |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
797 """rename a bookmark from old to new |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
798 |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
799 If force is specified, then the new name can overwrite an existing |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
800 bookmark. |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
801 |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
802 If inactive is specified, then do not activate the new bookmark. |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
803 |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
804 Raises an abort error if old is not in the bookmark store. |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
805 """ |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
806 marks = repo._bookmarks |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
807 mark = checkformat(repo, new) |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
808 if old not in marks: |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
809 raise error.Abort(_("bookmark '%s' does not exist") % old) |
34296
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
34295
diff
changeset
|
810 changes = [] |
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
34295
diff
changeset
|
811 for bm in marks.checkconflict(mark, force): |
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
34295
diff
changeset
|
812 changes.append((bm, None)) |
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
34295
diff
changeset
|
813 changes.extend([(mark, marks[old]), (old, None)]) |
34265
916d4cde530e
bookmark: use 'applychanges' for bookmark renaming
Boris Feld <boris.feld@octobus.net>
parents:
34264
diff
changeset
|
814 marks.applychanges(repo, tr, changes) |
33789
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
815 if repo._activebookmark == old and not inactive: |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33788
diff
changeset
|
816 activate(repo, mark) |
33790
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
817 |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
818 def addbookmarks(repo, tr, names, rev=None, force=False, inactive=False): |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
819 """add a list of bookmarks |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
820 |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
821 If force is specified, then the new name can overwrite an existing |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
822 bookmark. |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
823 |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
824 If inactive is specified, then do not activate any bookmark. Otherwise, the |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
825 first bookmark is activated. |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
826 |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
827 Raises an abort error if old is not in the bookmark store. |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
828 """ |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
829 marks = repo._bookmarks |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
830 cur = repo.changectx('.').node() |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
831 newact = None |
34266
146c0371eadf
bookmark: use 'applychanges' for adding new bookmark
Boris Feld <boris.feld@octobus.net>
parents:
34265
diff
changeset
|
832 changes = [] |
36433
fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36397
diff
changeset
|
833 hiddenrev = None |
fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36397
diff
changeset
|
834 |
fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36397
diff
changeset
|
835 # unhide revs if any |
fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36397
diff
changeset
|
836 if rev: |
fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36397
diff
changeset
|
837 repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn') |
fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36397
diff
changeset
|
838 |
33790
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
839 for mark in names: |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
840 mark = checkformat(repo, mark) |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
841 if newact is None: |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
842 newact = mark |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
843 if inactive and mark == repo._activebookmark: |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
844 deactivate(repo) |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
845 return |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
846 tgt = cur |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
847 if rev: |
36397
7336ac5e786e
bookmarks: add bookmarks to hidden revs if directaccess config is set
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36363
diff
changeset
|
848 ctx = scmutil.revsingle(repo, rev) |
7336ac5e786e
bookmarks: add bookmarks to hidden revs if directaccess config is set
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36363
diff
changeset
|
849 if ctx.hidden(): |
36433
fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36397
diff
changeset
|
850 hiddenrev = ctx.hex()[:12] |
36397
7336ac5e786e
bookmarks: add bookmarks to hidden revs if directaccess config is set
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36363
diff
changeset
|
851 tgt = ctx.node() |
34296
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
34295
diff
changeset
|
852 for bm in marks.checkconflict(mark, force, tgt): |
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
34295
diff
changeset
|
853 changes.append((bm, None)) |
34266
146c0371eadf
bookmark: use 'applychanges' for adding new bookmark
Boris Feld <boris.feld@octobus.net>
parents:
34265
diff
changeset
|
854 changes.append((mark, tgt)) |
36433
fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36397
diff
changeset
|
855 |
fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36397
diff
changeset
|
856 if hiddenrev: |
fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36397
diff
changeset
|
857 repo.ui.warn(_("bookmarking hidden changeset %s\n") % hiddenrev) |
34266
146c0371eadf
bookmark: use 'applychanges' for adding new bookmark
Boris Feld <boris.feld@octobus.net>
parents:
34265
diff
changeset
|
858 marks.applychanges(repo, tr, changes) |
33790
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
859 if not inactive and cur == marks[newact] and not rev: |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
860 activate(repo, newact) |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
861 elif cur != tgt and newact == repo._activebookmark: |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33789
diff
changeset
|
862 deactivate(repo) |
33793
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33792
diff
changeset
|
863 |
33794
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
864 def _printbookmarks(ui, repo, bmarks, **opts): |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
865 """private method to print bookmarks |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
866 |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
867 Provides a way for extensions to control how bookmarks are printed (e.g. |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
868 prepend or postpend names) |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
869 """ |
33875
d170f59f6f55
py3: fix kwargs handling for `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33794
diff
changeset
|
870 opts = pycompat.byteskwargs(opts) |
33794
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
871 fm = ui.formatter('bookmarks', opts) |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
872 hexfn = fm.hexfunc |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
873 if len(bmarks) == 0 and fm.isplain(): |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
874 ui.status(_("no bookmarks set\n")) |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
875 for bmark, (n, prefix, label) in sorted(bmarks.iteritems()): |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
876 fm.startitem() |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
877 if not ui.quiet: |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
878 fm.plain(' %s ' % prefix, label=label) |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
879 fm.write('bookmark', '%s', bmark, label=label) |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
880 pad = " " * (25 - encoding.colwidth(bmark)) |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
881 fm.condwrite(not ui.quiet, 'rev node', pad + ' %d:%s', |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
882 repo.changelog.rev(n), hexfn(n), label=label) |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
883 fm.data(active=(activebookmarklabel in label)) |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
884 fm.plain('\n') |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
885 fm.end() |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
886 |
33793
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33792
diff
changeset
|
887 def printbookmarks(ui, repo, **opts): |
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33792
diff
changeset
|
888 """print bookmarks to a formatter |
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33792
diff
changeset
|
889 |
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33792
diff
changeset
|
890 Provides a way for extensions to control how bookmarks are printed. |
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33792
diff
changeset
|
891 """ |
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33792
diff
changeset
|
892 marks = repo._bookmarks |
33794
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
893 bmarks = {} |
33793
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33792
diff
changeset
|
894 for bmark, n in sorted(marks.iteritems()): |
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33792
diff
changeset
|
895 active = repo._activebookmark |
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33792
diff
changeset
|
896 if bmark == active: |
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33792
diff
changeset
|
897 prefix, label = '*', activebookmarklabel |
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33792
diff
changeset
|
898 else: |
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33792
diff
changeset
|
899 prefix, label = ' ', '' |
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33792
diff
changeset
|
900 |
33794
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
901 bmarks[bmark] = (n, prefix, label) |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33793
diff
changeset
|
902 _printbookmarks(ui, repo, bmarks, **opts) |
35491
ee5f0d047b41
bookmark: add a dedicated txnclose-bookmark hook
Boris Feld <boris.feld@octobus.net>
parents:
34301
diff
changeset
|
903 |
ee5f0d047b41
bookmark: add a dedicated txnclose-bookmark hook
Boris Feld <boris.feld@octobus.net>
parents:
34301
diff
changeset
|
904 def preparehookargs(name, old, new): |
ee5f0d047b41
bookmark: add a dedicated txnclose-bookmark hook
Boris Feld <boris.feld@octobus.net>
parents:
34301
diff
changeset
|
905 if new is None: |
ee5f0d047b41
bookmark: add a dedicated txnclose-bookmark hook
Boris Feld <boris.feld@octobus.net>
parents:
34301
diff
changeset
|
906 new = '' |
ee5f0d047b41
bookmark: add a dedicated txnclose-bookmark hook
Boris Feld <boris.feld@octobus.net>
parents:
34301
diff
changeset
|
907 if old is None: |
ee5f0d047b41
bookmark: add a dedicated txnclose-bookmark hook
Boris Feld <boris.feld@octobus.net>
parents:
34301
diff
changeset
|
908 old = '' |
ee5f0d047b41
bookmark: add a dedicated txnclose-bookmark hook
Boris Feld <boris.feld@octobus.net>
parents:
34301
diff
changeset
|
909 return {'bookmark': name, |
ee5f0d047b41
bookmark: add a dedicated txnclose-bookmark hook
Boris Feld <boris.feld@octobus.net>
parents:
34301
diff
changeset
|
910 'node': hex(new), |
ee5f0d047b41
bookmark: add a dedicated txnclose-bookmark hook
Boris Feld <boris.feld@octobus.net>
parents:
34301
diff
changeset
|
911 'oldnode': hex(old)} |