Mercurial > hg
annotate mercurial/bookmarks.py @ 48826:3ce8001fd768
setup: remove more Python 2 support code
I'll inline print() etc in future patches.
Differential Revision: https://phab.mercurial-scm.org/D12270
author | Augie Fackler <augie@google.com> |
---|---|
date | Wed, 02 Mar 2022 10:07:21 -0500 |
parents | 21ac6aedd5e5 |
children | 6000f5b25c9b |
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 |
25917
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25743
diff
changeset
|
8 from __future__ import absolute_import |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25743
diff
changeset
|
9 |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25743
diff
changeset
|
10 import errno |
35257
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
11 import struct |
25917
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25743
diff
changeset
|
12 |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25743
diff
changeset
|
13 from .i18n import _ |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25743
diff
changeset
|
14 from .node import ( |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25743
diff
changeset
|
15 bin, |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25743
diff
changeset
|
16 hex, |
32956
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
17 short, |
25917
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25743
diff
changeset
|
18 ) |
43089
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
19 from .pycompat import getattr |
25917
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25743
diff
changeset
|
20 from . import ( |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25743
diff
changeset
|
21 encoding, |
29354
af849596752c
bookmarks: abort 'push -B .' when no active bookmark
liscju <piotr.listkiewicz@gmail.com>
parents:
29300
diff
changeset
|
22 error, |
33146
7017567ebdf2
obsutil: move 'foreground' to the new modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33092
diff
changeset
|
23 obsutil, |
33092
d170f59f6f55
py3: fix kwargs handling for `hg bookmarks`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33011
diff
changeset
|
24 pycompat, |
48599
dfbfa802876b
requirements: move "bookmark in store" requirements in the right module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48244
diff
changeset
|
25 requirements, |
32955
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
32794
diff
changeset
|
26 scmutil, |
31052
0332b8fafd05
bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
30634
diff
changeset
|
27 txnutil, |
25917
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25743
diff
changeset
|
28 util, |
aa323b53e3f9
bookmarks: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25743
diff
changeset
|
29 ) |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46780
diff
changeset
|
30 from .utils import ( |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46780
diff
changeset
|
31 urlutil, |
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46780
diff
changeset
|
32 ) |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
33 |
33009
4b81776baa7a
commands: move activebookmarklabel to bookmarks module
Sean Farley <sean@farley.io>
parents:
33007
diff
changeset
|
34 # label constants |
4b81776baa7a
commands: move activebookmarklabel to bookmarks module
Sean Farley <sean@farley.io>
parents:
33007
diff
changeset
|
35 # until 3.5, bookmarks.current was the advertised name, not |
4b81776baa7a
commands: move activebookmarklabel to bookmarks module
Sean Farley <sean@farley.io>
parents:
33007
diff
changeset
|
36 # bookmarks.active, so we must use both to avoid breaking old |
4b81776baa7a
commands: move activebookmarklabel to bookmarks module
Sean Farley <sean@farley.io>
parents:
33007
diff
changeset
|
37 # custom styles |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
38 activebookmarklabel = b'bookmarks.active bookmarks.current' |
33009
4b81776baa7a
commands: move activebookmarklabel to bookmarks module
Sean Farley <sean@farley.io>
parents:
33007
diff
changeset
|
39 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
40 |
42325
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
41 def bookmarksinstore(repo): |
48599
dfbfa802876b
requirements: move "bookmark in store" requirements in the right module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48244
diff
changeset
|
42 return requirements.BOOKMARKS_IN_STORE_REQUIREMENT in repo.requirements |
42325
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
43 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
44 |
42325
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
45 def bookmarksvfs(repo): |
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
46 return repo.svfs if bookmarksinstore(repo) else repo.vfs |
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
47 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
48 |
27186
34d26e22a2b0
bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents:
27185
diff
changeset
|
49 def _getbkfile(repo): |
34d26e22a2b0
bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents:
27185
diff
changeset
|
50 """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:
27185
diff
changeset
|
51 |
34d26e22a2b0
bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents:
27185
diff
changeset
|
52 For core, this just handles wether we should see pending |
34d26e22a2b0
bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents:
27185
diff
changeset
|
53 bookmarks or the committed ones. Other extensions (like share) |
34d26e22a2b0
bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents:
27185
diff
changeset
|
54 may need to tweak this behavior further. |
34d26e22a2b0
bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents:
27185
diff
changeset
|
55 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
56 fp, pending = txnutil.trypending( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
57 repo.root, bookmarksvfs(repo), b'bookmarks' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
58 ) |
31052
0332b8fafd05
bookmarks: check HG_PENDING strictly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
30634
diff
changeset
|
59 return fp |
27186
34d26e22a2b0
bookmarks: hoist getbkfile out of bmstore class
Augie Fackler <augie@google.com>
parents:
27185
diff
changeset
|
60 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
61 |
37847
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
62 class bmstore(object): |
41533
0f64091cc851
global: make some docstrings raw strings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41365
diff
changeset
|
63 r"""Storage for bookmarks. |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
64 |
27698
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
65 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:
27685
diff
changeset
|
66 that it's fairly simple to replace the storage underlying |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
67 bookmarks without having to clone the logic surrounding |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
68 bookmarks. This type also should manage the active bookmark, if |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
69 any. |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
70 |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
71 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
|
72 {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
|
73 .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
|
74 """ |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
75 |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
76 def __init__(self, repo): |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
77 self._repo = repo |
37847
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
78 self._refmap = refmap = {} # refspec: node |
37850
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
79 self._nodemap = nodemap = {} # node: sorted([refspec, ...]) |
32738
999aa9cfb4d3
bookmarks: move variable initialization earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32737
diff
changeset
|
80 self._clean = True |
999aa9cfb4d3
bookmarks: move variable initialization earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32737
diff
changeset
|
81 self._aclean = True |
43544
886ec3962c66
index: use `index.has_node` in `bookmarks.bmstore`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43117
diff
changeset
|
82 has_node = repo.changelog.index.has_node |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
83 tonode = bin # force local lookup |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
84 try: |
32794
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32793
diff
changeset
|
85 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:
32793
diff
changeset
|
86 for line in bkfile: |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32793
diff
changeset
|
87 line = line.strip() |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32793
diff
changeset
|
88 if not line: |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32793
diff
changeset
|
89 continue |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32793
diff
changeset
|
90 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
91 sha, refspec = line.split(b' ', 1) |
32794
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32793
diff
changeset
|
92 node = tonode(sha) |
43544
886ec3962c66
index: use `index.has_node` in `bookmarks.bmstore`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43117
diff
changeset
|
93 if has_node(node): |
32794
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32793
diff
changeset
|
94 refspec = encoding.tolocal(refspec) |
37847
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
95 refmap[refspec] = node |
37850
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
96 nrefs = nodemap.get(node) |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
97 if nrefs is None: |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
98 nodemap[node] = [refspec] |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
99 else: |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
100 nrefs.append(refspec) |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
101 if nrefs[-2] > refspec: |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
102 # bookmarks weren't sorted before 4.5 |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
103 nrefs.sort() |
32794
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32793
diff
changeset
|
104 except (TypeError, ValueError): |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32793
diff
changeset
|
105 # TypeError: |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32793
diff
changeset
|
106 # - bin(...) |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32793
diff
changeset
|
107 # ValueError: |
6f775d10e83b
bookmarks: make sure we close the bookmark file after reading
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32793
diff
changeset
|
108 # - 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:
32793
diff
changeset
|
109 # - split(...), for string without ' ' |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
110 bookmarkspath = b'.hg/bookmarks' |
42325
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
111 if bookmarksinstore(repo): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
112 bookmarkspath = b'.hg/store/bookmarks' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
113 repo.ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
114 _(b'malformed line in %s: %r\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
115 % (bookmarkspath, pycompat.bytestr(line)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
116 ) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25569
diff
changeset
|
117 except IOError as inst: |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
118 if inst.errno != errno.ENOENT: |
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
119 raise |
27698
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
120 self._active = _readactive(repo, self) |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
121 |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
122 @property |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
123 def active(self): |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
124 return self._active |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
125 |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
126 @active.setter |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
127 def active(self, mark): |
37847
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
128 if mark is not None and mark not in self._refmap: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
129 raise AssertionError(b'bookmark %s does not exist!' % mark) |
27698
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
130 |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
131 self._active = mark |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
132 self._aclean = False |
27187
d9dcc5c09d77
bmstore: add basic clean-state tracking
Augie Fackler <augie@google.com>
parents:
27186
diff
changeset
|
133 |
37847
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
134 def __len__(self): |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
135 return len(self._refmap) |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
136 |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
137 def __iter__(self): |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
138 return iter(self._refmap) |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
139 |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
140 def iteritems(self): |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
141 return pycompat.iteritems(self._refmap) |
37847
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
142 |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
143 def items(self): |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
144 return self._refmap.items() |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
145 |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
146 # TODO: maybe rename to allnames()? |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
147 def keys(self): |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
148 return self._refmap.keys() |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
149 |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
150 # TODO: maybe rename to allnodes()? but nodes would have to be deduplicated |
37850
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
151 # could be self._nodemap.keys() |
37847
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
152 def values(self): |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
153 return self._refmap.values() |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
154 |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
155 def __contains__(self, mark): |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
156 return mark in self._refmap |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
157 |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
158 def __getitem__(self, mark): |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
159 return self._refmap[mark] |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
160 |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
161 def get(self, mark, default=None): |
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
162 return self._refmap.get(mark, default) |
33517
08bf0ebc6c8e
bookmark: deprecate direct set of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
33516
diff
changeset
|
163 |
37849
82a153e6dc4a
bookmarks: make argument names of _set/_del() more specific
Yuya Nishihara <yuya@tcha.org>
parents:
37848
diff
changeset
|
164 def _set(self, mark, node): |
27187
d9dcc5c09d77
bmstore: add basic clean-state tracking
Augie Fackler <augie@google.com>
parents:
27186
diff
changeset
|
165 self._clean = False |
37850
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
166 if mark in self._refmap: |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
167 self._del(mark) |
37849
82a153e6dc4a
bookmarks: make argument names of _set/_del() more specific
Yuya Nishihara <yuya@tcha.org>
parents:
37848
diff
changeset
|
168 self._refmap[mark] = node |
37850
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
169 nrefs = self._nodemap.get(node) |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
170 if nrefs is None: |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
171 self._nodemap[node] = [mark] |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
172 else: |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
173 nrefs.append(mark) |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
174 nrefs.sort() |
33518
712a85b3677f
bookmark: deprecate direct del of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
33517
diff
changeset
|
175 |
37849
82a153e6dc4a
bookmarks: make argument names of _set/_del() more specific
Yuya Nishihara <yuya@tcha.org>
parents:
37848
diff
changeset
|
176 def _del(self, mark): |
44370
edaae3616ba3
bookmarks: avoid traceback when two pushes race to delete the same bookmark
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
43601
diff
changeset
|
177 if mark not in self._refmap: |
edaae3616ba3
bookmarks: avoid traceback when two pushes race to delete the same bookmark
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
43601
diff
changeset
|
178 return |
27187
d9dcc5c09d77
bmstore: add basic clean-state tracking
Augie Fackler <augie@google.com>
parents:
27186
diff
changeset
|
179 self._clean = False |
37850
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
180 node = self._refmap.pop(mark) |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
181 nrefs = self._nodemap[node] |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
182 if len(nrefs) == 1: |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
183 assert nrefs[0] == mark |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
184 del self._nodemap[node] |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
185 else: |
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
186 nrefs.remove(mark) |
35679
5a2d505a9174
bookmark: deprecate direct update of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
35647
diff
changeset
|
187 |
37848
6e2259847f5f
bookmarks: extract function that looks up bookmark names by node
Yuya Nishihara <yuya@tcha.org>
parents:
37847
diff
changeset
|
188 def names(self, node): |
6e2259847f5f
bookmarks: extract function that looks up bookmark names by node
Yuya Nishihara <yuya@tcha.org>
parents:
37847
diff
changeset
|
189 """Return a sorted list of bookmarks pointing to the specified node""" |
37850
04ceb267271a
bookmarks: cache reverse mapping (issue5868)
Yuya Nishihara <yuya@tcha.org>
parents:
37849
diff
changeset
|
190 return self._nodemap.get(node, []) |
37848
6e2259847f5f
bookmarks: extract function that looks up bookmark names by node
Yuya Nishihara <yuya@tcha.org>
parents:
37847
diff
changeset
|
191 |
33480
ef54789a947d
bookmark: introduce a 'applychanges' function to gather bookmark movement
Boris Feld <boris.feld@octobus.net>
parents:
33146
diff
changeset
|
192 def applychanges(self, repo, tr, changes): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
193 """Apply a list of changes to bookmarks""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
194 bmchanges = tr.changes.get(b'bookmarks') |
33480
ef54789a947d
bookmark: introduce a 'applychanges' function to gather bookmark movement
Boris Feld <boris.feld@octobus.net>
parents:
33146
diff
changeset
|
195 for name, node in changes: |
37847
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
196 old = self._refmap.get(name) |
33480
ef54789a947d
bookmark: introduce a 'applychanges' function to gather bookmark movement
Boris Feld <boris.feld@octobus.net>
parents:
33146
diff
changeset
|
197 if node is None: |
33518
712a85b3677f
bookmark: deprecate direct del of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
33517
diff
changeset
|
198 self._del(name) |
33480
ef54789a947d
bookmark: introduce a 'applychanges' function to gather bookmark movement
Boris Feld <boris.feld@octobus.net>
parents:
33146
diff
changeset
|
199 else: |
33517
08bf0ebc6c8e
bookmark: deprecate direct set of a bookmark value
Boris Feld <boris.feld@octobus.net>
parents:
33516
diff
changeset
|
200 self._set(name, node) |
33516
f9e6e43c7987
bookmark: track bookmark changes at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
33515
diff
changeset
|
201 if bmchanges is not None: |
f9e6e43c7987
bookmark: track bookmark changes at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
33515
diff
changeset
|
202 # 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:
33515
diff
changeset
|
203 previous = bmchanges.get(name) |
f9e6e43c7987
bookmark: track bookmark changes at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
33515
diff
changeset
|
204 if previous is not None: |
f9e6e43c7987
bookmark: track bookmark changes at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
33515
diff
changeset
|
205 old = previous[0] |
f9e6e43c7987
bookmark: track bookmark changes at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
33515
diff
changeset
|
206 bmchanges[name] = (old, node) |
33515
3325c7dcabaa
bookmark: deprecate 'recordchange' in favor of 'applychanges'
Boris Feld <boris.feld@octobus.net>
parents:
33514
diff
changeset
|
207 self._recordchange(tr) |
33480
ef54789a947d
bookmark: introduce a 'applychanges' function to gather bookmark movement
Boris Feld <boris.feld@octobus.net>
parents:
33146
diff
changeset
|
208 |
33515
3325c7dcabaa
bookmark: deprecate 'recordchange' in favor of 'applychanges'
Boris Feld <boris.feld@octobus.net>
parents:
33514
diff
changeset
|
209 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
|
210 """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
|
211 |
8319f7e78395
bookmark: add a `bmstore.recordupdate` to plug bookmarks into the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22664
diff
changeset
|
212 The transaction is then responsible for updating the file content.""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
213 location = b'' if bookmarksinstore(self._repo) else b'plain' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
214 tr.addfilegenerator( |
48685
21ac6aedd5e5
transaction: do not rely on a global variable to post_finalize file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48599
diff
changeset
|
215 b'bookmarks', |
21ac6aedd5e5
transaction: do not rely on a global variable to post_finalize file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48599
diff
changeset
|
216 (b'bookmarks',), |
21ac6aedd5e5
transaction: do not rely on a global variable to post_finalize file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48599
diff
changeset
|
217 self._write, |
21ac6aedd5e5
transaction: do not rely on a global variable to post_finalize file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48599
diff
changeset
|
218 location=location, |
21ac6aedd5e5
transaction: do not rely on a global variable to post_finalize file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48599
diff
changeset
|
219 post_finalize=True, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
220 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
221 tr.hookargs[b'bookmark_moved'] = b'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
|
222 |
23469
65e48b8d20f5
bookmarks: factor out repository lookup from writing bookmarks file
Ryan McElroy <rmcelroy@fb.com>
parents:
23458
diff
changeset
|
223 def _writerepo(self, repo): |
65e48b8d20f5
bookmarks: factor out repository lookup from writing bookmarks file
Ryan McElroy <rmcelroy@fb.com>
parents:
23458
diff
changeset
|
224 """Factored out for extensibility""" |
27698
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
225 rbm = repo._bookmarks |
37847
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
226 if rbm.active not in self._refmap: |
27698
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
227 rbm.active = None |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
228 rbm._writeactive() |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
229 |
42325
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
230 if bookmarksinstore(repo): |
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
231 vfs = repo.svfs |
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
232 lock = repo.lock() |
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
233 else: |
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
234 vfs = repo.vfs |
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
235 lock = repo.wlock() |
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
236 with lock: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
237 with vfs(b'bookmarks', b'w', atomictemp=True, checkambig=True) as f: |
42311
ec5bd3ab26bf
bookmarks: use context manager when writing files
Martin von Zweigbergk <martinvonz@google.com>
parents:
41533
diff
changeset
|
238 self._write(f) |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
239 |
27698
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
240 def _writeactive(self): |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
241 if self._aclean: |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
242 return |
27800
1c5f2c2c046b
with: use context manager for wlock in _writeactive
Bryan O'Sullivan <bryano@fb.com>
parents:
27799
diff
changeset
|
243 with self._repo.wlock(): |
27698
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
244 if self._active is not None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
245 with self._repo.vfs( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
246 b'bookmarks.current', b'w', atomictemp=True, checkambig=True |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
247 ) as f: |
27698
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
248 f.write(encoding.fromlocal(self._active)) |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
249 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
250 self._repo.vfs.tryunlink(b'bookmarks.current') |
27698
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
251 self._aclean = True |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
252 |
22664
6bd685d2a2de
bookmarks: split bookmark serialization and file handling
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22659
diff
changeset
|
253 def _write(self, fp): |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
254 for name, node in sorted(pycompat.iteritems(self._refmap)): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
255 fp.write(b"%s %s\n" % (hex(node), encoding.fromlocal(name))) |
27187
d9dcc5c09d77
bmstore: add basic clean-state tracking
Augie Fackler <augie@google.com>
parents:
27186
diff
changeset
|
256 self._clean = True |
29066
e6f490e32863
bookmarks: properly invalidate volatile sets when writing bookmarks
Augie Fackler <augie@google.com>
parents:
28182
diff
changeset
|
257 self._repo.invalidatevolatilesets() |
22664
6bd685d2a2de
bookmarks: split bookmark serialization and file handling
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22659
diff
changeset
|
258 |
28182
e4fe4e903e97
bookmarks: add 'hg push -B .' for pushing the active bookmark (issue4917)
liscju <piotr.listkiewicz@gmail.com>
parents:
27800
diff
changeset
|
259 def expandname(self, bname): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
260 if bname == b'.': |
29354
af849596752c
bookmarks: abort 'push -B .' when no active bookmark
liscju <piotr.listkiewicz@gmail.com>
parents:
29300
diff
changeset
|
261 if self.active: |
af849596752c
bookmarks: abort 'push -B .' when no active bookmark
liscju <piotr.listkiewicz@gmail.com>
parents:
29300
diff
changeset
|
262 return self.active |
af849596752c
bookmarks: abort 'push -B .' when no active bookmark
liscju <piotr.listkiewicz@gmail.com>
parents:
29300
diff
changeset
|
263 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
264 raise error.RepoLookupError(_(b"no active bookmark")) |
28182
e4fe4e903e97
bookmarks: add 'hg push -B .' for pushing the active bookmark (issue4917)
liscju <piotr.listkiewicz@gmail.com>
parents:
27800
diff
changeset
|
265 return bname |
e4fe4e903e97
bookmarks: add 'hg push -B .' for pushing the active bookmark (issue4917)
liscju <piotr.listkiewicz@gmail.com>
parents:
27800
diff
changeset
|
266 |
32956
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
267 def checkconflict(self, mark, force=False, target=None): |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
268 """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:
32955
diff
changeset
|
269 branch, or hash |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
270 |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
271 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:
32955
diff
changeset
|
272 forward. |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
273 |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
274 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:
32955
diff
changeset
|
275 regardless if it is a move forward. |
33513
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
33512
diff
changeset
|
276 |
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
33512
diff
changeset
|
277 If divergent bookmark are to be deleted, they will be returned as list. |
32956
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
278 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
279 cur = self._repo[b'.'].node() |
37847
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
280 if mark in self._refmap and not force: |
32956
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
281 if target: |
37847
8256962e798c
bookmarks: hide dict behind bmstore class
Yuya Nishihara <yuya@tcha.org>
parents:
37641
diff
changeset
|
282 if self._refmap[mark] == target and target == cur: |
32956
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
283 # re-activating a bookmark |
33513
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
33512
diff
changeset
|
284 return [] |
32956
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
285 rev = self._repo[target].rev() |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
286 anc = self._repo.changelog.ancestors([rev]) |
42978
e3bb2a58af1e
bookmarks: remove changectx() method from bmstore (API)
Augie Fackler <augie@google.com>
parents:
42914
diff
changeset
|
287 bmctx = self._repo[self[mark]] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
288 divs = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
289 self._refmap[b] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
290 for b in self._refmap |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
291 if b.split(b'@', 1)[0] == mark.split(b'@', 1)[0] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
292 ] |
32956
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
293 |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
294 # allow resolving a single divergent bookmark even if moving |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
295 # the bookmark across branches when a revision is specified |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
296 # that contains a divergent bookmark |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
297 if bmctx.rev() not in anc and target in divs: |
33513
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
33512
diff
changeset
|
298 return divergent2delete(self._repo, [target], mark) |
32956
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
299 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
300 deletefrom = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
301 b for b in divs if self._repo[b].rev() in anc or b == target |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
302 ] |
33513
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
33512
diff
changeset
|
303 delbms = divergent2delete(self._repo, deletefrom, mark) |
32956
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
304 if validdest(self._repo, bmctx, self._repo[target]): |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
305 self._repo.ui.status( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
306 _(b"moving bookmark '%s' forward from %s\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
307 % (mark, short(bmctx.node())) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
308 ) |
33513
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
33512
diff
changeset
|
309 return delbms |
32956
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
310 raise error.Abort( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43106
diff
changeset
|
311 _(b"bookmark '%s' already exists (use -f to force)") % mark |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
312 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
313 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
314 mark in self._repo.branchmap() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
315 or mark == self._repo.dirstate.branch() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
316 ) and not force: |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
317 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
318 _(b"a bookmark cannot have the name of an existing branch") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
319 ) |
32956
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
320 if len(mark) > 3 and not force: |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
321 try: |
37397
46d9f998c3ed
bookmarks: use isrevsymbol() for detecting collision with existing symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37375
diff
changeset
|
322 shadowhash = scmutil.isrevsymbol(self._repo, mark) |
32956
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
323 except error.LookupError: # ambiguous identifier |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
324 shadowhash = False |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
325 if shadowhash: |
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
326 self._repo.ui.warn( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
327 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
328 b"bookmark %s matches a changeset hash\n" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
329 b"(did you leave a -r out of an 'hg bookmark' " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
330 b"command?)\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
331 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
332 % mark |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
333 ) |
33513
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
33512
diff
changeset
|
334 return [] |
32956
4f0a7f604449
commands: move checkconflict to bookmarks module
Sean Farley <sean@farley.io>
parents:
32955
diff
changeset
|
335 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
336 |
27698
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
337 def _readactive(repo, marks): |
24946
c44534209a0a
bookmarks: rename readcurrent to readactive (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24945
diff
changeset
|
338 """ |
c44534209a0a
bookmarks: rename readcurrent to readactive (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24945
diff
changeset
|
339 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:
24945
diff
changeset
|
340 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:
24945
diff
changeset
|
341 It is stored in .hg/bookmarks.current |
c44534209a0a
bookmarks: rename readcurrent to readactive (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24945
diff
changeset
|
342 """ |
42312
2b77183ac477
bookmarks: use vfs.tryread() instead of reimplementing it
Martin von Zweigbergk <martinvonz@google.com>
parents:
42311
diff
changeset
|
343 # No readline() in osutil.posixfile, reading everything is |
2b77183ac477
bookmarks: use vfs.tryread() instead of reimplementing it
Martin von Zweigbergk <martinvonz@google.com>
parents:
42311
diff
changeset
|
344 # cheap. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
345 content = repo.vfs.tryread(b'bookmarks.current') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
346 mark = encoding.tolocal((content.splitlines() or [b''])[0]) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
347 if mark == b'' or mark not in marks: |
42312
2b77183ac477
bookmarks: use vfs.tryread() instead of reimplementing it
Martin von Zweigbergk <martinvonz@google.com>
parents:
42311
diff
changeset
|
348 mark = None |
13351
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
349 return mark |
6c5368cd2df9
bookmarks: move read methods to core
Matt Mackall <mpm@selenic.com>
parents:
13350
diff
changeset
|
350 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
351 |
24945
e0b0fbd47491
bookmarks: rename setcurrent to activate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24944
diff
changeset
|
352 def activate(repo, mark): |
e0b0fbd47491
bookmarks: rename setcurrent to activate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24944
diff
changeset
|
353 """ |
e0b0fbd47491
bookmarks: rename setcurrent to activate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24944
diff
changeset
|
354 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:
24944
diff
changeset
|
355 follow new commits that are made. |
13350
a7376b92caaa
bookmarks: move basic io to core
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
356 The name is recorded in .hg/bookmarks.current |
24945
e0b0fbd47491
bookmarks: rename setcurrent to activate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24944
diff
changeset
|
357 """ |
27698
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
358 repo._bookmarks.active = mark |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
359 repo._bookmarks._writeactive() |
13352
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
360 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
361 |
24944
08ec11e3ae4c
bookmarks: rename unsetcurrent to deactivate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24832
diff
changeset
|
362 def deactivate(repo): |
08ec11e3ae4c
bookmarks: rename unsetcurrent to deactivate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24832
diff
changeset
|
363 """ |
26781
1aee2ab0f902
spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents:
26520
diff
changeset
|
364 Unset the active bookmark in this repository. |
24944
08ec11e3ae4c
bookmarks: rename unsetcurrent to deactivate (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24832
diff
changeset
|
365 """ |
27698
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
366 repo._bookmarks.active = None |
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
367 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
|
368 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
369 |
24986
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24962
diff
changeset
|
370 def isactivewdirparent(repo): |
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24962
diff
changeset
|
371 """ |
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24962
diff
changeset
|
372 Tell whether the 'active' bookmark (the one that follows new commits) |
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24962
diff
changeset
|
373 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
|
374 |
24986
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24962
diff
changeset
|
375 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:
24962
diff
changeset
|
376 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:
24962
diff
changeset
|
377 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:
24962
diff
changeset
|
378 """ |
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24962
diff
changeset
|
379 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
|
380 marks = repo._bookmarks |
24986
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24962
diff
changeset
|
381 parents = [p.node() for p in repo[None].parents()] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
382 return mark in marks and marks[mark] in parents |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
383 |
18471
2096e025a728
update: update to current bookmark if it moved out from under us (issue3682)
Kevin Bullock <kbullock@ringworld.org>
parents:
18363
diff
changeset
|
384 |
33510
07b556d1b74e
bookmark: split out target computation from 'deletedivergent'
Boris Feld <boris.feld@octobus.net>
parents:
33499
diff
changeset
|
385 def divergent2delete(repo, deletefrom, bm): |
07b556d1b74e
bookmark: split out target computation from 'deletedivergent'
Boris Feld <boris.feld@octobus.net>
parents:
33499
diff
changeset
|
386 """find divergent versions of bm on nodes in deletefrom. |
07b556d1b74e
bookmark: split out target computation from 'deletedivergent'
Boris Feld <boris.feld@octobus.net>
parents:
33499
diff
changeset
|
387 |
07b556d1b74e
bookmark: split out target computation from 'deletedivergent'
Boris Feld <boris.feld@octobus.net>
parents:
33499
diff
changeset
|
388 the list of bookmark to delete.""" |
07b556d1b74e
bookmark: split out target computation from 'deletedivergent'
Boris Feld <boris.feld@octobus.net>
parents:
33499
diff
changeset
|
389 todelete = [] |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
390 marks = repo._bookmarks |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
391 divergent = [ |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
392 b for b in marks if b.split(b'@', 1)[0] == bm.split(b'@', 1)[0] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
393 ] |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
394 for mark in divergent: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
395 if mark == b'@' or b'@' not in mark: |
21843
92666a869ea4
bookmarks: avoid deleting primary bookmarks on rebase
Matt Mackall <mpm@selenic.com>
parents:
20352
diff
changeset
|
396 # can't be divergent by definition |
92666a869ea4
bookmarks: avoid deleting primary bookmarks on rebase
Matt Mackall <mpm@selenic.com>
parents:
20352
diff
changeset
|
397 continue |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
398 if mark and marks[mark] in deletefrom: |
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
399 if mark != bm: |
33510
07b556d1b74e
bookmark: split out target computation from 'deletedivergent'
Boris Feld <boris.feld@octobus.net>
parents:
33499
diff
changeset
|
400 todelete.append(mark) |
07b556d1b74e
bookmark: split out target computation from 'deletedivergent'
Boris Feld <boris.feld@octobus.net>
parents:
33499
diff
changeset
|
401 return todelete |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
402 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
403 |
32381
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
404 def headsforactive(repo): |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
405 """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:
31544
diff
changeset
|
406 |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
407 Args: |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
408 repo: A repository with an active bookmark. |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
409 |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
410 Returns: |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
411 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:
31544
diff
changeset
|
412 revisions with bookmarks divergent from the active bookmark. If |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
413 there were no divergent bookmarks, then this list will contain |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
414 only one entry. |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
415 """ |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
416 if not repo._activebookmark: |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
417 raise ValueError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
418 b'headsforactive() only makes sense with an active bookmark' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
419 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
420 name = repo._activebookmark.split(b'@', 1)[0] |
32381
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
421 heads = [] |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
422 for mark, n in pycompat.iteritems(repo._bookmarks): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
423 if mark.split(b'@', 1)[0] == name: |
32381
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
424 heads.append(n) |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
425 return heads |
b9942bc6b292
localrepo: extract bookmarkheads method to bookmarks.py
Augie Fackler <augie@google.com>
parents:
31544
diff
changeset
|
426 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
427 |
37375
a973bb92ab71
bookmarks: drop always-None argument from calculateupdate()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37359
diff
changeset
|
428 def calculateupdate(ui, repo): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
429 """Return a tuple (activemark, movemarkfrom) indicating the active bookmark |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
430 and where to move the active bookmark from, if needed.""" |
37375
a973bb92ab71
bookmarks: drop always-None argument from calculateupdate()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37359
diff
changeset
|
431 checkout, movemarkfrom = None, None |
a973bb92ab71
bookmarks: drop always-None argument from calculateupdate()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37359
diff
changeset
|
432 activemark = repo._activebookmark |
a973bb92ab71
bookmarks: drop always-None argument from calculateupdate()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37359
diff
changeset
|
433 if isactivewdirparent(repo): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
434 movemarkfrom = repo[b'.'].node() |
37375
a973bb92ab71
bookmarks: drop always-None argument from calculateupdate()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37359
diff
changeset
|
435 elif activemark: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
436 ui.status(_(b"updating to active bookmark %s\n") % activemark) |
37375
a973bb92ab71
bookmarks: drop always-None argument from calculateupdate()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37359
diff
changeset
|
437 checkout = activemark |
19523
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
438 return (checkout, movemarkfrom) |
f37b5a17e6a0
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
Kevin Bullock <kbullock@ringworld.org>
parents:
19110
diff
changeset
|
439 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
440 |
13352
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
441 def update(repo, parents, node): |
19110
741d94aa92e4
bookmarks: resolve divergent bookmarks when moving active bookmark forward
Sean Farley <sean.michael.farley@gmail.com>
parents:
18984
diff
changeset
|
442 deletefrom = parents |
13352
f9cd37fca5ba
bookmarks: move update into core
Matt Mackall <mpm@selenic.com>
parents:
13351
diff
changeset
|
443 marks = repo._bookmarks |
27698
dad6404ccddb
bmstore: add handling of the active bookmark
Augie Fackler <augie@google.com>
parents:
27685
diff
changeset
|
444 active = marks.active |
25100
d6e7ac651973
bookmarks: rename current to active in variables and comments
Ryan McElroy <rmcelroy@fb.com>
parents:
25081
diff
changeset
|
445 if not active: |
16706
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
446 return False |
a270ec977ba6
bookmarks: delete divergent bookmarks on merge
David Soria Parra <dsp@php.net>
parents:
16697
diff
changeset
|
447 |
33491
1adcb594eb6b
bookmarks: use 'applychanges' for bookmark update
Boris Feld <boris.feld@octobus.net>
parents:
33485
diff
changeset
|
448 bmchanges = [] |
25100
d6e7ac651973
bookmarks: rename current to active in variables and comments
Ryan McElroy <rmcelroy@fb.com>
parents:
25081
diff
changeset
|
449 if marks[active] in parents: |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
450 new = repo[node] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
451 divs = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
452 repo[marks[b]] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
453 for b in marks |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
454 if b.split(b'@', 1)[0] == active.split(b'@', 1)[0] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
455 ] |
19110
741d94aa92e4
bookmarks: resolve divergent bookmarks when moving active bookmark forward
Sean Farley <sean.michael.farley@gmail.com>
parents:
18984
diff
changeset
|
456 anc = repo.changelog.ancestors([new.rev()]) |
741d94aa92e4
bookmarks: resolve divergent bookmarks when moving active bookmark forward
Sean Farley <sean.michael.farley@gmail.com>
parents:
18984
diff
changeset
|
457 deletefrom = [b.node() for b in divs if b.rev() in anc or b == new] |
42978
e3bb2a58af1e
bookmarks: remove changectx() method from bmstore (API)
Augie Fackler <augie@google.com>
parents:
42914
diff
changeset
|
458 if validdest(repo, repo[marks[active]], new): |
33491
1adcb594eb6b
bookmarks: use 'applychanges' for bookmark update
Boris Feld <boris.feld@octobus.net>
parents:
33485
diff
changeset
|
459 bmchanges.append((active, new.node())) |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
460 |
33512
1424a769f31b
bookmark: use 'divergent2delete' when updating a bookmark
Boris Feld <boris.feld@octobus.net>
parents:
33510
diff
changeset
|
461 for bm in divergent2delete(repo, deletefrom, active): |
1424a769f31b
bookmark: use 'divergent2delete' when updating a bookmark
Boris Feld <boris.feld@octobus.net>
parents:
33510
diff
changeset
|
462 bmchanges.append((bm, None)) |
18513
37ce336ab2dd
bookmarks: factor out delete divergent code
Siddharth Agarwal <sid0@fb.com>
parents:
18496
diff
changeset
|
463 |
33512
1424a769f31b
bookmark: use 'divergent2delete' when updating a bookmark
Boris Feld <boris.feld@octobus.net>
parents:
33510
diff
changeset
|
464 if bmchanges: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
465 with repo.lock(), repo.transaction(b'bookmark') as tr: |
33491
1adcb594eb6b
bookmarks: use 'applychanges' for bookmark update
Boris Feld <boris.feld@octobus.net>
parents:
33485
diff
changeset
|
466 marks.applychanges(repo, tr, bmchanges) |
33512
1424a769f31b
bookmark: use 'divergent2delete' when updating a bookmark
Boris Feld <boris.feld@octobus.net>
parents:
33510
diff
changeset
|
467 return bool(bmchanges) |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
468 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
469 |
44371
0275000564c4
bookmarks: refactor in preparation for next commit
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44370
diff
changeset
|
470 def isdivergent(b): |
0275000564c4
bookmarks: refactor in preparation for next commit
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44370
diff
changeset
|
471 return b'@' in b and not b.endswith(b'@') |
0275000564c4
bookmarks: refactor in preparation for next commit
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44370
diff
changeset
|
472 |
0275000564c4
bookmarks: refactor in preparation for next commit
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44370
diff
changeset
|
473 |
30481
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
29354
diff
changeset
|
474 def listbinbookmarks(repo): |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
29354
diff
changeset
|
475 # We may try to list bookmarks on a repo type that does not |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
29354
diff
changeset
|
476 # support it (e.g., statichttprepository). |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
29354
diff
changeset
|
477 marks = getattr(repo, '_bookmarks', {}) |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
29354
diff
changeset
|
478 |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
29354
diff
changeset
|
479 hasnode = repo.changelog.hasnode |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
480 for k, v in pycompat.iteritems(marks): |
30481
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
29354
diff
changeset
|
481 # don't expose local divergent bookmarks |
44371
0275000564c4
bookmarks: refactor in preparation for next commit
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44370
diff
changeset
|
482 if hasnode(v) and not isdivergent(k): |
30481
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
29354
diff
changeset
|
483 yield k, v |
0a3b11a7489a
bookmarks: introduce listbinbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
29354
diff
changeset
|
484 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
485 |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
486 def listbookmarks(repo): |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
487 d = {} |
30482
55ec13c82ea0
bookmarks: use listbinbookmarks() in listbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
30481
diff
changeset
|
488 for book, node in listbinbookmarks(repo): |
55ec13c82ea0
bookmarks: use listbinbookmarks() in listbookmarks()
Stanislau Hlebik <stash@fb.com>
parents:
30481
diff
changeset
|
489 d[book] = hex(node) |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
490 return d |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
491 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
492 |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
493 def pushbookmark(repo, key, old, new): |
44372
8407031f195f
bookmarks: prevent pushes of divergent bookmarks (foo@remote)
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44371
diff
changeset
|
494 if isdivergent(key): |
8407031f195f
bookmarks: prevent pushes of divergent bookmarks (foo@remote)
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44371
diff
changeset
|
495 return False |
42325
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
496 if bookmarksinstore(repo): |
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
497 wlock = util.nullcontextmanager() |
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
498 else: |
526750cdd02d
bookmarks: keep bookmarks in .hg/store if new config set
Martin von Zweigbergk <martinvonz@google.com>
parents:
42312
diff
changeset
|
499 wlock = repo.wlock() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
500 with wlock, repo.lock(), repo.transaction(b'bookmarks') as tr: |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
501 marks = repo._bookmarks |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
502 existing = hex(marks.get(key, b'')) |
22364
5c153c69fdb2
bookmarks: allow pushkey if new equals current
Durham Goode <durham@fb.com>
parents:
21843
diff
changeset
|
503 if existing != old and existing != new: |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
504 return False |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
505 if new == b'': |
33485
505021482541
bookmark: use 'applychanges' when updating a bookmark through pushkey
Boris Feld <boris.feld@octobus.net>
parents:
33484
diff
changeset
|
506 changes = [(key, None)] |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
507 else: |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
508 if new not in repo: |
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
509 return False |
33485
505021482541
bookmark: use 'applychanges' when updating a bookmark through pushkey
Boris Feld <boris.feld@octobus.net>
parents:
33484
diff
changeset
|
510 changes = [(key, repo[new].node())] |
505021482541
bookmark: use 'applychanges' when updating a bookmark through pushkey
Boris Feld <boris.feld@octobus.net>
parents:
33484
diff
changeset
|
511 marks.applychanges(repo, tr, changes) |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
13352
diff
changeset
|
512 return True |
13354
4e1ba6ead69c
bookmarks: move diff to core
Matt Mackall <mpm@selenic.com>
parents:
13353
diff
changeset
|
513 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
514 |
30583
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
30582
diff
changeset
|
515 def comparebookmarks(repo, srcmarks, dstmarks, targets=None): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
516 """Compare bookmarks between srcmarks and dstmarks |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
517 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
518 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
|
519 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
|
520 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
521 :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
|
522 :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
|
523 :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
|
524 :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
|
525 :diverge: diverge |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
526 :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
|
527 :invalid: unknown on both side |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
528 :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
|
529 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
530 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
|
531 changeset ID on source side, changeset ID on destination |
42914
08fce968d00b
doc: fix up confusing doc comment
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
42325
diff
changeset
|
532 side)". Each changeset ID is a binary node or None. |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
533 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
534 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
|
535 "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
|
536 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
537 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
|
538 examined. |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
539 """ |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
540 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
541 if targets: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
542 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
|
543 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
544 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
|
545 dstmarkset = set(dstmarks) |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
546 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
|
547 |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
548 results = ([], [], [], [], [], [], [], []) |
20024
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
549 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
|
550 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
|
551 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
|
552 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
|
553 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
|
554 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
|
555 invalid = results[6].append |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
556 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
|
557 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
558 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
|
559 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
|
560 if b in dstmarks: |
30583
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
30582
diff
changeset
|
561 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
|
562 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
563 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
|
564 elif b not in dstmarks: |
30583
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
30582
diff
changeset
|
565 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
|
566 else: |
30583
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
30582
diff
changeset
|
567 scid = srcmarks[b] |
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
30582
diff
changeset
|
568 dcid = dstmarks[b] |
23081
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
569 if scid == dcid: |
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
570 same((b, scid, dcid)) |
e62c330a044f
bookmarks: explicitly track identical bookmarks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22941
diff
changeset
|
571 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
|
572 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
|
573 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
|
574 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
|
575 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
|
576 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
|
577 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
578 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
|
579 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
580 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
|
581 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
|
582 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
583 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
|
584 else: |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
585 # 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
|
586 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
|
587 |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
588 return results |
059b695150c2
bookmarks: add function to centralize the logic to compare bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19951
diff
changeset
|
589 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
590 |
24355
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24354
diff
changeset
|
591 def _diverge(ui, b, path, localmarks, remotenode): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
592 """Return appropriate diverged bookmark for specified ``path`` |
24353
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24306
diff
changeset
|
593 |
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24306
diff
changeset
|
594 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:
24306
diff
changeset
|
595 bookmark name. |
24355
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24354
diff
changeset
|
596 |
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24354
diff
changeset
|
597 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:
24354
diff
changeset
|
598 refers ``remotenode``. |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
599 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
600 if b == b'@': |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
601 b = b'' |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
602 # try to use an @pathalias suffix |
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
603 # if an @pathalias already exists, we overwrite (update) it |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
604 if path.startswith(b"file:"): |
46907
ffd3e823a7e5
urlutil: extract `url` related code from `util` into the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46780
diff
changeset
|
605 path = urlutil.url(path).path |
47188
353718f741a8
bookmark: use `list_paths` to access path definition
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47012
diff
changeset
|
606 for name, p in urlutil.list_paths(ui): |
353718f741a8
bookmark: use `list_paths` to access path definition
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47012
diff
changeset
|
607 loc = p.rawloc |
353718f741a8
bookmark: use `list_paths` to access path definition
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47012
diff
changeset
|
608 if loc.startswith(b"file:"): |
353718f741a8
bookmark: use `list_paths` to access path definition
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47012
diff
changeset
|
609 loc = urlutil.url(loc).path |
353718f741a8
bookmark: use `list_paths` to access path definition
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47012
diff
changeset
|
610 if path == loc: |
353718f741a8
bookmark: use `list_paths` to access path definition
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47012
diff
changeset
|
611 return b'%s@%s' % (b, name) |
24354
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24353
diff
changeset
|
612 |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24353
diff
changeset
|
613 # assign a unique "@number" suffix newly |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24353
diff
changeset
|
614 for x in range(1, 100): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
615 n = b'%s@%d' % (b, x) |
24355
ca4b89683078
bookmarks: reuse @number bookmark, if it refers changeset referred remotely
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24354
diff
changeset
|
616 if n not in localmarks or localmarks[n] == remotenode: |
24354
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24353
diff
changeset
|
617 return n |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24353
diff
changeset
|
618 |
194e1e3ebc29
bookmarks: check @pathalias suffix before available @number for efficiency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24353
diff
changeset
|
619 return None |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
620 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
621 |
30583
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
30582
diff
changeset
|
622 def unhexlifybookmarks(marks): |
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
30582
diff
changeset
|
623 binremotemarks = {} |
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
30582
diff
changeset
|
624 for name, node in marks.items(): |
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
30582
diff
changeset
|
625 binremotemarks[name] = bin(node) |
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
30582
diff
changeset
|
626 return binremotemarks |
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
30582
diff
changeset
|
627 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
628 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
629 _binaryentry = struct.Struct(b'>20sH') |
35257
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
630 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
631 |
46780
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
45942
diff
changeset
|
632 def binaryencode(repo, bookmarks): |
35257
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
633 """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:
34708
diff
changeset
|
634 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
635 the binary format is: |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
636 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
637 <node><bookmark-length><bookmark-name> |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
638 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
639 :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:
34708
diff
changeset
|
640 :bookmark-length: an unsigned short, |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
641 :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:
34708
diff
changeset
|
642 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
643 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:
34708
diff
changeset
|
644 """ |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
645 binarydata = [] |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
646 for book, node in bookmarks: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
647 if not node: # None or '' |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46907
diff
changeset
|
648 node = repo.nodeconstants.wdirid |
35257
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
649 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:
34708
diff
changeset
|
650 binarydata.append(book) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
651 return b''.join(binarydata) |
35257
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
652 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
653 |
46780
6266d19556ad
node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
45942
diff
changeset
|
654 def binarydecode(repo, stream): |
35257
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
655 """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:
34708
diff
changeset
|
656 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
657 the binary format is: |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
658 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
659 <node><bookmark-length><bookmark-name> |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
660 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
661 :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:
34708
diff
changeset
|
662 :bookmark-length: an unsigned short, |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
663 :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:
34708
diff
changeset
|
664 |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
665 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:
34708
diff
changeset
|
666 """ |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
667 entrysize = _binaryentry.size |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
668 books = [] |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
669 while True: |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
670 entry = stream.read(entrysize) |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
671 if len(entry) < entrysize: |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
672 if entry: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
673 raise error.Abort(_(b'bad bookmark stream')) |
35257
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
674 break |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
675 node, length = _binaryentry.unpack(entry) |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
676 bookmark = stream.read(length) |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
677 if len(bookmark) < length: |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
678 if entry: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
679 raise error.Abort(_(b'bad bookmark stream')) |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46907
diff
changeset
|
680 if node == repo.nodeconstants.wdirid: |
35257
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
681 node = None |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
682 books.append((bookmark, node)) |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
683 return books |
3340d46a5c3f
bookmark: add methods to binary encode and decode bookmark values
Boris Feld <boris.feld@octobus.net>
parents:
34708
diff
changeset
|
684 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
685 |
48033
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
686 def mirroring_remote(ui, repo, remotemarks): |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
687 """computes the bookmark changes that set the local bookmarks to |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
688 remotemarks""" |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
689 changed = [] |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
690 localmarks = repo._bookmarks |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
691 for (b, id) in pycompat.iteritems(remotemarks): |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
692 if id != localmarks.get(b, None) and id in repo: |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
693 changed.append((b, id, ui.debug, _(b"updating bookmark %s\n") % b)) |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
694 for b in localmarks: |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
695 if b not in remotemarks: |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
696 changed.append( |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
697 (b, None, ui.debug, _(b"removing bookmark %s\n") % b) |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
698 ) |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
699 return changed |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
700 |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
701 |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
702 def merging_from_remote(ui, repo, remotemarks, path, explicit=()): |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
703 """computes the bookmark changes that merge remote bookmarks into the |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
704 local bookmarks, based on comparebookmarks""" |
17922
7f5dab94e48c
bookmarks: introduce a bmstore to manage bookmark persistence
Augie Fackler <raf@durin42.com>
parents:
17918
diff
changeset
|
705 localmarks = repo._bookmarks |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
706 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
707 addsrc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
708 adddst, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
709 advsrc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
710 advdst, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
711 diverge, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
712 differ, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
713 invalid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
714 same, |
30583
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
30582
diff
changeset
|
715 ) = 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
|
716 |
22644
1ec7cdaf898f
bookmarks: allow `updatefromremote` to be quiet
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22629
diff
changeset
|
717 status = ui.status |
1ec7cdaf898f
bookmarks: allow `updatefromremote` to be quiet
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22629
diff
changeset
|
718 warn = ui.warn |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
719 if ui.configbool(b'ui', b'quietbookmarkmove'): |
22644
1ec7cdaf898f
bookmarks: allow `updatefromremote` to be quiet
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22629
diff
changeset
|
720 status = warn = ui.debug |
1ec7cdaf898f
bookmarks: allow `updatefromremote` to be quiet
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22629
diff
changeset
|
721 |
22659
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
722 explicit = set(explicit) |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
723 changed = [] |
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
724 for b, scid, dcid in addsrc: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
725 if scid in repo: # add remote bookmarks for changes we already have |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
726 changed.append( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
727 (b, scid, status, _(b"adding remote bookmark %s\n") % b) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
728 ) |
25564
847fce27effc
bookmark: informs of failure to upgrade a bookmark
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25100
diff
changeset
|
729 elif b in explicit: |
847fce27effc
bookmark: informs of failure to upgrade a bookmark
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25100
diff
changeset
|
730 explicit.remove(b) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
731 ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
732 _(b"remote bookmark %s points to locally missing %s\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
733 % (b, hex(scid)[:12]) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
734 ) |
25564
847fce27effc
bookmark: informs of failure to upgrade a bookmark
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25100
diff
changeset
|
735 |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
736 for b, scid, dcid in advsrc: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
737 changed.append((b, scid, status, _(b"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
|
738 # 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
|
739 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
|
740 |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
741 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
|
742 if b in explicit: |
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
743 explicit.discard(b) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
744 changed.append((b, scid, status, _(b"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
|
745 else: |
30583
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
30582
diff
changeset
|
746 db = _diverge(ui, b, path, localmarks, scid) |
24353
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24306
diff
changeset
|
747 if db: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
748 changed.append( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
749 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
750 db, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
751 scid, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
752 warn, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
753 _(b"divergent bookmark %s stored as %s\n") % (b, db), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
754 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
755 ) |
24353
3f6bf9f29e7b
bookmarks: prevent divergent bookmark from being updated unexpectedly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24306
diff
changeset
|
756 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
757 warn( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
758 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
759 b"warning: failed to assign numbered name " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
760 b"to divergent bookmark %s\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
761 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
762 % b |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
763 ) |
22659
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
764 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
|
765 if b in explicit: |
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
766 explicit.discard(b) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
767 changed.append((b, scid, status, _(b"importing bookmark %s\n") % b)) |
25564
847fce27effc
bookmark: informs of failure to upgrade a bookmark
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25100
diff
changeset
|
768 for b, scid, dcid in differ: |
847fce27effc
bookmark: informs of failure to upgrade a bookmark
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25100
diff
changeset
|
769 if b in explicit: |
847fce27effc
bookmark: informs of failure to upgrade a bookmark
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25100
diff
changeset
|
770 explicit.remove(b) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
771 ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
772 _(b"remote bookmark %s points to locally missing %s\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
773 % (b, hex(scid)[:12]) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
774 ) |
48033
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
775 return changed |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
776 |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
777 |
48242
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48033
diff
changeset
|
778 def updatefromremote( |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48033
diff
changeset
|
779 ui, repo, remotemarks, path, trfunc, explicit=(), mode=None |
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48033
diff
changeset
|
780 ): |
48244
b56858d85a7b
bookmarks: add a `ignore` variant of the bookmark mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48243
diff
changeset
|
781 if mode == b'ignore': |
b56858d85a7b
bookmarks: add a `ignore` variant of the bookmark mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48243
diff
changeset
|
782 # This should move to an higher level to avoid fetching bookmark at all |
b56858d85a7b
bookmarks: add a `ignore` variant of the bookmark mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48243
diff
changeset
|
783 return |
48033
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
784 ui.debug(b"checking for updated bookmarks\n") |
48242
4d2ab365699e
bookmarks: move the `mirror` option to the `paths` section
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48033
diff
changeset
|
785 if mode == b'mirror': |
48033
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
786 changed = mirroring_remote(ui, repo, remotemarks) |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
787 else: |
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
788 changed = merging_from_remote(ui, repo, remotemarks, path, explicit) |
22659
798185707833
pull: merge bookmark updates and imports
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22658
diff
changeset
|
789 |
13646
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
790 if changed: |
22666
0f8120c1ecf5
pull: perform bookmark updates in the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22665
diff
changeset
|
791 tr = trfunc() |
33484
2a8ce4e79a47
bookmark: use 'applychanges' when updating from a remote
Boris Feld <boris.feld@octobus.net>
parents:
33483
diff
changeset
|
792 changes = [] |
44824
f189c5280d48
py3: fix exception in pull when several things happen to a bookmark
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
44372
diff
changeset
|
793 key = lambda t: (t[0], t[1] or b'') |
f189c5280d48
py3: fix exception in pull when several things happen to a bookmark
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
44372
diff
changeset
|
794 for b, node, writer, msg in sorted(changed, key=key): |
33484
2a8ce4e79a47
bookmark: use 'applychanges' when updating from a remote
Boris Feld <boris.feld@octobus.net>
parents:
33483
diff
changeset
|
795 changes.append((b, node)) |
20025
e8a11791abfc
bookmarks: rewrite "updatefromremote()" by "compare()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20024
diff
changeset
|
796 writer(msg) |
48033
62f325f9b347
bookmarks: add an option to make pull mirror remote bookmarks
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47188
diff
changeset
|
797 repo._bookmarks.applychanges(repo, tr, changes) |
13646
31eac42d9123
bookmarks: separate bookmarks update code from localrepo's pull.
David Soria Parra <dsp@php.net>
parents:
13627
diff
changeset
|
798 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
799 |
48243
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
800 def incoming(ui, repo, peer, mode=None): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
801 """Show bookmarks incoming from other to repo""" |
48244
b56858d85a7b
bookmarks: add a `ignore` variant of the bookmark mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48243
diff
changeset
|
802 if mode == b'ignore': |
b56858d85a7b
bookmarks: add a `ignore` variant of the bookmark mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48243
diff
changeset
|
803 ui.status(_(b"bookmarks exchange disabled with this path\n")) |
b56858d85a7b
bookmarks: add a `ignore` variant of the bookmark mode
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48243
diff
changeset
|
804 return 0 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
805 ui.status(_(b"searching for changed bookmarks\n")) |
24397
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
806 |
37641
add129811176
bookmarks: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37450
diff
changeset
|
807 with peer.commandexecutor() as e: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
808 remotemarks = unhexlifybookmarks( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
809 e.callcommand( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
810 b'listkeys', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
811 { |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
812 b'namespace': b'bookmarks', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
813 }, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
814 ).result() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
815 ) |
37641
add129811176
bookmarks: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37450
diff
changeset
|
816 |
24397
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
817 incomings = [] |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
818 if ui.debugflag: |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
819 getid = lambda id: id |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
820 else: |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
821 getid = lambda id: id[:12] |
24660
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24658
diff
changeset
|
822 if ui.verbose: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
823 |
24660
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24658
diff
changeset
|
824 def add(b, id, st): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
825 incomings.append(b" %-25s %s %s\n" % (b, getid(id), st)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
826 |
24660
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24658
diff
changeset
|
827 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
828 |
24660
bf13b44bbb0a
bookmarks: show detailed status about incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24658
diff
changeset
|
829 def add(b, id, st): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
830 incomings.append(b" %-25s %s\n" % (b, getid(id))) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
831 |
48243
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
832 if mode == b'mirror': |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
833 localmarks = repo._bookmarks |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
834 allmarks = set(remotemarks.keys()) | set(localmarks.keys()) |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
835 for b in sorted(allmarks): |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
836 loc = localmarks.get(b) |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
837 rem = remotemarks.get(b) |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
838 if loc == rem: |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
839 continue |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
840 elif loc is None: |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
841 add(b, hex(rem), _(b'added')) |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
842 elif rem is None: |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
843 add(b, hex(repo.nullid), _(b'removed')) |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
844 else: |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
845 add(b, hex(rem), _(b'changed')) |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
846 else: |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
847 r = comparebookmarks(repo, remotemarks, repo._bookmarks) |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
848 addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = r |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
849 |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
850 for b, scid, dcid in addsrc: |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
851 # i18n: "added" refers to a bookmark |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
852 add(b, hex(scid), _(b'added')) |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
853 for b, scid, dcid in advsrc: |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
854 # i18n: "advanced" refers to a bookmark |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
855 add(b, hex(scid), _(b'advanced')) |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
856 for b, scid, dcid in diverge: |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
857 # i18n: "diverged" refers to a bookmark |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
858 add(b, hex(scid), _(b'diverged')) |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
859 for b, scid, dcid in differ: |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
860 # i18n: "changed" refers to a bookmark |
76c071bba40d
bookmarks: add support for `mirror` mode to `incoming`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48242
diff
changeset
|
861 add(b, hex(scid), _(b'changed')) |
24397
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
862 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
863 if not incomings: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
864 ui.status(_(b"no changed bookmarks found\n")) |
24397
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
865 return 1 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
866 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
867 for s in sorted(incomings): |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
868 ui.write(s) |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
869 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
870 return 0 |
d0ea2028e8e6
bookmarks: add incoming() to replace diff() for incoming bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24355
diff
changeset
|
871 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
872 |
24398
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
873 def outgoing(ui, repo, other): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
874 """Show bookmarks outgoing from repo to other""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
875 ui.status(_(b"searching for changed bookmarks\n")) |
24398
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
876 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
877 remotemarks = unhexlifybookmarks(other.listkeys(b'bookmarks')) |
30583
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
30582
diff
changeset
|
878 r = comparebookmarks(repo, repo._bookmarks, remotemarks) |
24398
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
879 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:
24397
diff
changeset
|
880 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
881 outgoings = [] |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
882 if ui.debugflag: |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
883 getid = lambda id: id |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
884 else: |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
885 getid = lambda id: id[:12] |
24661
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24660
diff
changeset
|
886 if ui.verbose: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
887 |
24661
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24660
diff
changeset
|
888 def add(b, id, st): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
889 outgoings.append(b" %-25s %s %s\n" % (b, getid(id), st)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
890 |
24661
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24660
diff
changeset
|
891 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
892 |
24661
8cf70c97a6e1
bookmarks: show detailed status about outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24660
diff
changeset
|
893 def add(b, id, st): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
894 outgoings.append(b" %-25s %s\n" % (b, getid(id))) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
895 |
24398
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
896 for b, scid, dcid in addsrc: |
24832
5947a68fa271
bookmarks: add i18n hints to bookmark sync states
Wagner Bruna <wbruna@yahoo.com>
parents:
24661
diff
changeset
|
897 # i18n: "added refers to a bookmark |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
898 add(b, hex(scid), _(b'added')) |
24658
8ea893ab0572
bookmarks: show outgoing bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24657
diff
changeset
|
899 for b, scid, dcid in adddst: |
24832
5947a68fa271
bookmarks: add i18n hints to bookmark sync states
Wagner Bruna <wbruna@yahoo.com>
parents:
24661
diff
changeset
|
900 # i18n: "deleted" refers to a bookmark |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
901 add(b, b' ' * 40, _(b'deleted')) |
24658
8ea893ab0572
bookmarks: show outgoing bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24657
diff
changeset
|
902 for b, scid, dcid in advsrc: |
24832
5947a68fa271
bookmarks: add i18n hints to bookmark sync states
Wagner Bruna <wbruna@yahoo.com>
parents:
24661
diff
changeset
|
903 # i18n: "advanced" refers to a bookmark |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
904 add(b, hex(scid), _(b'advanced')) |
24658
8ea893ab0572
bookmarks: show outgoing bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24657
diff
changeset
|
905 for b, scid, dcid in diverge: |
24832
5947a68fa271
bookmarks: add i18n hints to bookmark sync states
Wagner Bruna <wbruna@yahoo.com>
parents:
24661
diff
changeset
|
906 # i18n: "diverged" refers to a bookmark |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
907 add(b, hex(scid), _(b'diverged')) |
24658
8ea893ab0572
bookmarks: show outgoing bookmarks more exactly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24657
diff
changeset
|
908 for b, scid, dcid in differ: |
24832
5947a68fa271
bookmarks: add i18n hints to bookmark sync states
Wagner Bruna <wbruna@yahoo.com>
parents:
24661
diff
changeset
|
909 # i18n: "changed" refers to a bookmark |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
910 add(b, hex(scid), _(b'changed')) |
24398
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
911 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
912 if not outgoings: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
913 ui.status(_(b"no changed bookmarks found\n")) |
24398
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
914 return 1 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
915 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
916 for s in sorted(outgoings): |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
917 ui.write(s) |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
918 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
919 return 0 |
c0096a2bd3ff
bookmarks: add outgoing() to replace diff() for outgoing bookmarks
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24397
diff
changeset
|
920 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
921 |
37641
add129811176
bookmarks: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37450
diff
changeset
|
922 def summary(repo, peer): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
923 """Compare bookmarks between repo and other for "hg summary" output |
24400
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24399
diff
changeset
|
924 |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24399
diff
changeset
|
925 This returns "(# of incoming, # of outgoing)" tuple. |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
926 """ |
37641
add129811176
bookmarks: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37450
diff
changeset
|
927 with peer.commandexecutor() as e: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
928 remotemarks = unhexlifybookmarks( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
929 e.callcommand( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
930 b'listkeys', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
931 { |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
932 b'namespace': b'bookmarks', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
933 }, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45913
diff
changeset
|
934 ).result() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
935 ) |
37641
add129811176
bookmarks: use command executor for wire protocol commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37450
diff
changeset
|
936 |
30583
8f8211903b83
bookmarks: make bookmarks.comparebookmarks accept binary nodes (API)
Stanislau Hlebik <stash@fb.com>
parents:
30582
diff
changeset
|
937 r = comparebookmarks(repo, remotemarks, repo._bookmarks) |
24400
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24399
diff
changeset
|
938 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:
24399
diff
changeset
|
939 return (len(addsrc), len(adddst)) |
03c84c966ef5
bookmarks: rewrite comparing bookmarks in commands.summary() by compare()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24399
diff
changeset
|
940 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
941 |
17550
fc530080013b
bookmarks: extract valid destination logic in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17425
diff
changeset
|
942 def validdest(repo, old, new): |
fc530080013b
bookmarks: extract valid destination logic in a dedicated function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17425
diff
changeset
|
943 """Is the new bookmark destination a valid update from the old one""" |
18008
cf91b36f368c
clfilter: `bookmark.validdest` should run on unfiltered repo
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17922
diff
changeset
|
944 repo = repo.unfiltered() |
17551
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
945 if old == new: |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
946 # Old == new -> nothing to update. |
17625
b83c18204c36
bookmarks: avoid redundant creation/assignment of "validdests" in "validdest()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17551
diff
changeset
|
947 return False |
17551
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
948 elif not old: |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
949 # old is nullrev, anything is valid. |
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
950 # (new != nullrev has been excluded by the previous check) |
17625
b83c18204c36
bookmarks: avoid redundant creation/assignment of "validdests" in "validdest()"
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17551
diff
changeset
|
951 return True |
17551
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
952 elif repo.obsstore: |
33146
7017567ebdf2
obsutil: move 'foreground' to the new modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33092
diff
changeset
|
953 return new.node() in obsutil.foreground(repo, [old.node()]) |
17551
a7b3fdaf768d
bookmark: take successors into account when updating (issue3561)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
17550
diff
changeset
|
954 else: |
24180
d8e0c591781c
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
23877
diff
changeset
|
955 # still an independent clause as it is lazier (and therefore faster) |
38670
fbec9c0b32d3
context: rename descendant() to isancestorof()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38538
diff
changeset
|
956 return old.isancestorof(new) |
32955
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
32794
diff
changeset
|
957 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
958 |
32955
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
32794
diff
changeset
|
959 def checkformat(repo, mark): |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
32794
diff
changeset
|
960 """return a valid version of a potential bookmark name |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
32794
diff
changeset
|
961 |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
32794
diff
changeset
|
962 Raises an abort error if the bookmark name is not valid. |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
32794
diff
changeset
|
963 """ |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
32794
diff
changeset
|
964 mark = mark.strip() |
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
32794
diff
changeset
|
965 if not mark: |
45913
9acbe30953e8
errors: raise InputError on bad bookmark argument
Martin von Zweigbergk <martinvonz@google.com>
parents:
44824
diff
changeset
|
966 raise error.InputError( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43106
diff
changeset
|
967 _(b"bookmark names cannot consist entirely of whitespace") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
968 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
969 scmutil.checknewlabel(repo, mark, b'bookmark') |
32955
70661eeb8ddb
commands: move checkformat to bookmarks module
Sean Farley <sean@farley.io>
parents:
32794
diff
changeset
|
970 return mark |
33005
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
32956
diff
changeset
|
971 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
972 |
33005
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
32956
diff
changeset
|
973 def delete(repo, tr, names): |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
32956
diff
changeset
|
974 """remove a mark from the bookmark store |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
32956
diff
changeset
|
975 |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
32956
diff
changeset
|
976 Raises an abort error if mark does not exist. |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
32956
diff
changeset
|
977 """ |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
32956
diff
changeset
|
978 marks = repo._bookmarks |
33481
67b5f81f17cf
bookmark: use 'applychanges' for bookmark deletion
Boris Feld <boris.feld@octobus.net>
parents:
33480
diff
changeset
|
979 changes = [] |
33005
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
32956
diff
changeset
|
980 for mark in names: |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
32956
diff
changeset
|
981 if mark not in marks: |
45913
9acbe30953e8
errors: raise InputError on bad bookmark argument
Martin von Zweigbergk <martinvonz@google.com>
parents:
44824
diff
changeset
|
982 raise error.InputError(_(b"bookmark '%s' does not exist") % mark) |
33005
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
32956
diff
changeset
|
983 if mark == repo._activebookmark: |
9343fce87789
bookmarks: factor out delete logic from commands
Sean Farley <sean@farley.io>
parents:
32956
diff
changeset
|
984 deactivate(repo) |
33481
67b5f81f17cf
bookmark: use 'applychanges' for bookmark deletion
Boris Feld <boris.feld@octobus.net>
parents:
33480
diff
changeset
|
985 changes.append((mark, None)) |
67b5f81f17cf
bookmark: use 'applychanges' for bookmark deletion
Boris Feld <boris.feld@octobus.net>
parents:
33480
diff
changeset
|
986 marks.applychanges(repo, tr, changes) |
33006
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33005
diff
changeset
|
987 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
988 |
33006
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33005
diff
changeset
|
989 def rename(repo, tr, old, new, force=False, inactive=False): |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33005
diff
changeset
|
990 """rename a bookmark from old to new |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33005
diff
changeset
|
991 |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33005
diff
changeset
|
992 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:
33005
diff
changeset
|
993 bookmark. |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33005
diff
changeset
|
994 |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33005
diff
changeset
|
995 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:
33005
diff
changeset
|
996 |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33005
diff
changeset
|
997 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:
33005
diff
changeset
|
998 """ |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33005
diff
changeset
|
999 marks = repo._bookmarks |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33005
diff
changeset
|
1000 mark = checkformat(repo, new) |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33005
diff
changeset
|
1001 if old not in marks: |
45913
9acbe30953e8
errors: raise InputError on bad bookmark argument
Martin von Zweigbergk <martinvonz@google.com>
parents:
44824
diff
changeset
|
1002 raise error.InputError(_(b"bookmark '%s' does not exist") % old) |
33513
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
33512
diff
changeset
|
1003 changes = [] |
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
33512
diff
changeset
|
1004 for bm in marks.checkconflict(mark, force): |
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
33512
diff
changeset
|
1005 changes.append((bm, None)) |
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
33512
diff
changeset
|
1006 changes.extend([(mark, marks[old]), (old, None)]) |
33482
916d4cde530e
bookmark: use 'applychanges' for bookmark renaming
Boris Feld <boris.feld@octobus.net>
parents:
33481
diff
changeset
|
1007 marks.applychanges(repo, tr, changes) |
33006
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33005
diff
changeset
|
1008 if repo._activebookmark == old and not inactive: |
e0a8dd6c87c7
bookmarks: factor out rename logic from commands
Sean Farley <sean@farley.io>
parents:
33005
diff
changeset
|
1009 activate(repo, mark) |
33007
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1010 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
1011 |
33007
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1012 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:
33006
diff
changeset
|
1013 """add a list of bookmarks |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1014 |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1015 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:
33006
diff
changeset
|
1016 bookmark. |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1017 |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1018 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:
33006
diff
changeset
|
1019 first bookmark is activated. |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1020 |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1021 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:
33006
diff
changeset
|
1022 """ |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1023 marks = repo._bookmarks |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1024 cur = repo[b'.'].node() |
33007
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1025 newact = None |
33483
146c0371eadf
bookmark: use 'applychanges' for adding new bookmark
Boris Feld <boris.feld@octobus.net>
parents:
33482
diff
changeset
|
1026 changes = [] |
35647
fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35611
diff
changeset
|
1027 |
fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35611
diff
changeset
|
1028 # unhide revs if any |
fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35611
diff
changeset
|
1029 if rev: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1030 repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn') |
43600
fe2e0d100187
bookmarks: use changectx instead of remembering hex of hidden revision
Yuya Nishihara <yuya@tcha.org>
parents:
43599
diff
changeset
|
1031 |
43601
a80d5ddecc2d
bookmarks: accept explicit -r 'wdir()' when adding new bookmarks (issue6218)
Yuya Nishihara <yuya@tcha.org>
parents:
43600
diff
changeset
|
1032 ctx = scmutil.revsingle(repo, rev, None) |
a80d5ddecc2d
bookmarks: accept explicit -r 'wdir()' when adding new bookmarks (issue6218)
Yuya Nishihara <yuya@tcha.org>
parents:
43600
diff
changeset
|
1033 # bookmarking wdir means creating a bookmark on p1 and activating it |
a80d5ddecc2d
bookmarks: accept explicit -r 'wdir()' when adding new bookmarks (issue6218)
Yuya Nishihara <yuya@tcha.org>
parents:
43600
diff
changeset
|
1034 activatenew = not inactive and ctx.rev() is None |
a80d5ddecc2d
bookmarks: accept explicit -r 'wdir()' when adding new bookmarks (issue6218)
Yuya Nishihara <yuya@tcha.org>
parents:
43600
diff
changeset
|
1035 if ctx.node() is None: |
a80d5ddecc2d
bookmarks: accept explicit -r 'wdir()' when adding new bookmarks (issue6218)
Yuya Nishihara <yuya@tcha.org>
parents:
43600
diff
changeset
|
1036 ctx = ctx.p1() |
43600
fe2e0d100187
bookmarks: use changectx instead of remembering hex of hidden revision
Yuya Nishihara <yuya@tcha.org>
parents:
43599
diff
changeset
|
1037 tgt = ctx.node() |
43601
a80d5ddecc2d
bookmarks: accept explicit -r 'wdir()' when adding new bookmarks (issue6218)
Yuya Nishihara <yuya@tcha.org>
parents:
43600
diff
changeset
|
1038 assert tgt |
35647
fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35611
diff
changeset
|
1039 |
33007
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1040 for mark in names: |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1041 mark = checkformat(repo, mark) |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1042 if newact is None: |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1043 newact = mark |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1044 if inactive and mark == repo._activebookmark: |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1045 deactivate(repo) |
43598
2a8cd7edf409
bookmarks: fix handling of multiple bookmarks with one to be deactivated
Yuya Nishihara <yuya@tcha.org>
parents:
43544
diff
changeset
|
1046 continue |
33513
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
33512
diff
changeset
|
1047 for bm in marks.checkconflict(mark, force, tgt): |
904894edb205
bookmark: use 'divergent2delete' in checkconflict
Boris Feld <boris.feld@octobus.net>
parents:
33512
diff
changeset
|
1048 changes.append((bm, None)) |
33483
146c0371eadf
bookmark: use 'applychanges' for adding new bookmark
Boris Feld <boris.feld@octobus.net>
parents:
33482
diff
changeset
|
1049 changes.append((mark, tgt)) |
35647
fc39e2bfcd70
bookmarks: calculate visibility exceptions only once
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35611
diff
changeset
|
1050 |
43598
2a8cd7edf409
bookmarks: fix handling of multiple bookmarks with one to be deactivated
Yuya Nishihara <yuya@tcha.org>
parents:
43544
diff
changeset
|
1051 # nothing changed but for the one deactivated above |
2a8cd7edf409
bookmarks: fix handling of multiple bookmarks with one to be deactivated
Yuya Nishihara <yuya@tcha.org>
parents:
43544
diff
changeset
|
1052 if not changes: |
2a8cd7edf409
bookmarks: fix handling of multiple bookmarks with one to be deactivated
Yuya Nishihara <yuya@tcha.org>
parents:
43544
diff
changeset
|
1053 return |
2a8cd7edf409
bookmarks: fix handling of multiple bookmarks with one to be deactivated
Yuya Nishihara <yuya@tcha.org>
parents:
43544
diff
changeset
|
1054 |
43600
fe2e0d100187
bookmarks: use changectx instead of remembering hex of hidden revision
Yuya Nishihara <yuya@tcha.org>
parents:
43599
diff
changeset
|
1055 if ctx.hidden(): |
fe2e0d100187
bookmarks: use changectx instead of remembering hex of hidden revision
Yuya Nishihara <yuya@tcha.org>
parents:
43599
diff
changeset
|
1056 repo.ui.warn(_(b"bookmarking hidden changeset %s\n") % ctx.hex()[:12]) |
35712
a1a5c3842b6f
bookmarks: display the obsfate of hidden revision we create a bookmark on
Boris Feld <boris.feld@octobus.net>
parents:
35679
diff
changeset
|
1057 |
a1a5c3842b6f
bookmarks: display the obsfate of hidden revision we create a bookmark on
Boris Feld <boris.feld@octobus.net>
parents:
35679
diff
changeset
|
1058 if ctx.obsolete(): |
43600
fe2e0d100187
bookmarks: use changectx instead of remembering hex of hidden revision
Yuya Nishihara <yuya@tcha.org>
parents:
43599
diff
changeset
|
1059 msg = obsutil._getfilteredreason(repo, ctx.hex()[:12], ctx) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1060 repo.ui.warn(b"(%s)\n" % msg) |
35712
a1a5c3842b6f
bookmarks: display the obsfate of hidden revision we create a bookmark on
Boris Feld <boris.feld@octobus.net>
parents:
35679
diff
changeset
|
1061 |
33483
146c0371eadf
bookmark: use 'applychanges' for adding new bookmark
Boris Feld <boris.feld@octobus.net>
parents:
33482
diff
changeset
|
1062 marks.applychanges(repo, tr, changes) |
43601
a80d5ddecc2d
bookmarks: accept explicit -r 'wdir()' when adding new bookmarks (issue6218)
Yuya Nishihara <yuya@tcha.org>
parents:
43600
diff
changeset
|
1063 if activatenew and cur == marks[newact]: |
33007
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1064 activate(repo, newact) |
ee081f91b179
bookmarks: factor out adding a list of bookmarks logic from commands
Sean Farley <sean@farley.io>
parents:
33006
diff
changeset
|
1065 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:
33006
diff
changeset
|
1066 deactivate(repo) |
33010
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33009
diff
changeset
|
1067 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
1068 |
39746
25cc5616adc9
bookmarks: pass in formatter to printbookmarks() instead of opts (API)
Yuya Nishihara <yuya@tcha.org>
parents:
39624
diff
changeset
|
1069 def _printbookmarks(ui, repo, fm, bmarks): |
33011
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33010
diff
changeset
|
1070 """private method to print bookmarks |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33010
diff
changeset
|
1071 |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33010
diff
changeset
|
1072 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:
33010
diff
changeset
|
1073 prepend or postpend names) |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33010
diff
changeset
|
1074 """ |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33010
diff
changeset
|
1075 hexfn = fm.hexfunc |
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33010
diff
changeset
|
1076 if len(bmarks) == 0 and fm.isplain(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1077 ui.status(_(b"no bookmarks set\n")) |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43089
diff
changeset
|
1078 for bmark, (n, prefix, label) in sorted(pycompat.iteritems(bmarks)): |
33011
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33010
diff
changeset
|
1079 fm.startitem() |
39624
713085b45810
formatter: replace contexthint() with demand loading of ctx object
Yuya Nishihara <yuya@tcha.org>
parents:
39304
diff
changeset
|
1080 fm.context(repo=repo) |
33011
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33010
diff
changeset
|
1081 if not ui.quiet: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1082 fm.plain(b' %s ' % prefix, label=label) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1083 fm.write(b'bookmark', b'%s', bmark, label=label) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1084 pad = b" " * (25 - encoding.colwidth(bmark)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
1085 fm.condwrite( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
1086 not ui.quiet, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1087 b'rev node', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1088 pad + b' %d:%s', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
1089 repo.changelog.rev(n), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
1090 hexfn(n), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
1091 label=label, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
1092 ) |
33011
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33010
diff
changeset
|
1093 fm.data(active=(activebookmarklabel in label)) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1094 fm.plain(b'\n') |
33011
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33010
diff
changeset
|
1095 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
1096 |
39753
b05b4b91de3d
bookmarks: add explicit option to list bookmarks of the given names
Yuya Nishihara <yuya@tcha.org>
parents:
39746
diff
changeset
|
1097 def printbookmarks(ui, repo, fm, names=None): |
39746
25cc5616adc9
bookmarks: pass in formatter to printbookmarks() instead of opts (API)
Yuya Nishihara <yuya@tcha.org>
parents:
39624
diff
changeset
|
1098 """print bookmarks by the given formatter |
33010
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33009
diff
changeset
|
1099 |
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33009
diff
changeset
|
1100 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:
33009
diff
changeset
|
1101 """ |
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33009
diff
changeset
|
1102 marks = repo._bookmarks |
33011
8299eb9b08c7
bookmarks: factor method _printer out of for loop in printbookmarks
Sean Farley <sean@farley.io>
parents:
33010
diff
changeset
|
1103 bmarks = {} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
1104 for bmark in names or marks: |
39753
b05b4b91de3d
bookmarks: add explicit option to list bookmarks of the given names
Yuya Nishihara <yuya@tcha.org>
parents:
39746
diff
changeset
|
1105 if bmark not in marks: |
45913
9acbe30953e8
errors: raise InputError on bad bookmark argument
Martin von Zweigbergk <martinvonz@google.com>
parents:
44824
diff
changeset
|
1106 raise error.InputError(_(b"bookmark '%s' does not exist") % bmark) |
33010
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33009
diff
changeset
|
1107 active = repo._activebookmark |
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33009
diff
changeset
|
1108 if bmark == active: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1109 prefix, label = b'*', activebookmarklabel |
33010
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33009
diff
changeset
|
1110 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1111 prefix, label = b' ', b'' |
33010
f5f4c72de71a
bookmarks: factor out bookmark printing from commands
Sean Farley <sean@farley.io>
parents:
33009
diff
changeset
|
1112 |
39753
b05b4b91de3d
bookmarks: add explicit option to list bookmarks of the given names
Yuya Nishihara <yuya@tcha.org>
parents:
39746
diff
changeset
|
1113 bmarks[bmark] = (marks[bmark], prefix, label) |
39746
25cc5616adc9
bookmarks: pass in formatter to printbookmarks() instead of opts (API)
Yuya Nishihara <yuya@tcha.org>
parents:
39624
diff
changeset
|
1114 _printbookmarks(ui, repo, fm, bmarks) |
34708
ee5f0d047b41
bookmark: add a dedicated txnclose-bookmark hook
Boris Feld <boris.feld@octobus.net>
parents:
33518
diff
changeset
|
1115 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42978
diff
changeset
|
1116 |
34708
ee5f0d047b41
bookmark: add a dedicated txnclose-bookmark hook
Boris Feld <boris.feld@octobus.net>
parents:
33518
diff
changeset
|
1117 def preparehookargs(name, old, new): |
ee5f0d047b41
bookmark: add a dedicated txnclose-bookmark hook
Boris Feld <boris.feld@octobus.net>
parents:
33518
diff
changeset
|
1118 if new is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1119 new = b'' |
34708
ee5f0d047b41
bookmark: add a dedicated txnclose-bookmark hook
Boris Feld <boris.feld@octobus.net>
parents:
33518
diff
changeset
|
1120 if old is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1121 old = b'' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1122 return {b'bookmark': name, b'node': hex(new), b'oldnode': hex(old)} |