author | Matt Harbison <matt_harbison@yahoo.com> |
Thu, 05 Jan 2023 17:31:11 -0500 | |
changeset 49857 | ab32fd8412a7 |
parent 48875 | 6000f5b25c9b |
child 51863 | f4733654f144 |
permissions | -rw-r--r-- |
11367 | 1 |
# pushkey.py - dispatching for pushing and pulling keys |
2 |
# |
|
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents:
43077
diff
changeset
|
3 |
# Copyright 2010 Olivia Mackall <olivia@selenic.com> |
11367 | 4 |
# |
5 |
# This software may be used and distributed according to the terms of the |
|
6 |
# GNU General Public License version 2 or any later version. |
|
7 |
||
25969
7b200566e474
pushkey: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22953
diff
changeset
|
8 |
|
7b200566e474
pushkey: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22953
diff
changeset
|
9 |
from . import ( |
7b200566e474
pushkey: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22953
diff
changeset
|
10 |
bookmarks, |
7b200566e474
pushkey: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22953
diff
changeset
|
11 |
encoding, |
7b200566e474
pushkey: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22953
diff
changeset
|
12 |
obsolete, |
7b200566e474
pushkey: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22953
diff
changeset
|
13 |
phases, |
7b200566e474
pushkey: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
22953
diff
changeset
|
14 |
) |
13353
689bf32b3bbd
bookmarks: move pushkey functions into core
Matt Mackall <mpm@selenic.com>
parents:
11367
diff
changeset
|
15 |
|
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
25969
diff
changeset
|
16 |
|
11367 | 17 |
def _nslist(repo): |
18 |
n = {} |
|
19 |
for k in _namespaces: |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
20 |
n[k] = b"" |
22953
b1d694d3975e
obsolete: add exchange option
Durham Goode <durham@fb.com>
parents:
21661
diff
changeset
|
21 |
if not obsolete.isenabled(repo, obsolete.exchangeopt): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
22 |
n.pop(b'obsolete') |
11367 | 23 |
return n |
24 |
||
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
25969
diff
changeset
|
25 |
|
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
25969
diff
changeset
|
26 |
_namespaces = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
27 |
b"namespaces": (lambda *x: False, _nslist), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
28 |
b"bookmarks": (bookmarks.pushbookmark, bookmarks.listbookmarks), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
29 |
b"phases": (phases.pushphase, phases.listphases), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
30 |
b"obsolete": (obsolete.pushmarker, obsolete.listmarkers), |
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
25969
diff
changeset
|
31 |
} |
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
25969
diff
changeset
|
32 |
|
11367 | 33 |
|
34 |
def register(namespace, pushkey, listkeys): |
|
35 |
_namespaces[namespace] = (pushkey, listkeys) |
|
36 |
||
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
25969
diff
changeset
|
37 |
|
11367 | 38 |
def _get(namespace): |
39 |
return _namespaces.get(namespace, (lambda *x: False, lambda *x: {})) |
|
40 |
||
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
25969
diff
changeset
|
41 |
|
11367 | 42 |
def push(repo, namespace, key, old, new): |
43 |
'''should succeed iff value was old''' |
|
44 |
pk = _get(namespace)[0] |
|
45 |
return pk(repo, key, old, new) |
|
46 |
||
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
25969
diff
changeset
|
47 |
|
11367 | 48 |
def list(repo, namespace): |
49 |
'''return a dict''' |
|
50 |
lk = _get(namespace)[1] |
|
51 |
return lk(repo) |
|
52 |
||
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
25969
diff
changeset
|
53 |
|
21661
2f52a16f2bee
pushkey: add an ``encode`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21659
diff
changeset
|
54 |
encode = encoding.fromlocal |
2f52a16f2bee
pushkey: add an ``encode`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21659
diff
changeset
|
55 |
|
21659
a319842539f5
pushkey: add a ``decode`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21652
diff
changeset
|
56 |
decode = encoding.tolocal |
a319842539f5
pushkey: add a ``decode`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21652
diff
changeset
|
57 |
|
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
25969
diff
changeset
|
58 |
|
21650
a2c7ae21e8f4
pushkey: introduce an ``encodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
17298
diff
changeset
|
59 |
def encodekeys(keys): |
a2c7ae21e8f4
pushkey: introduce an ``encodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
17298
diff
changeset
|
60 |
"""encode the content of a pushkey namespace for exchange over the wire""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
61 |
return b'\n'.join([b'%s\t%s' % (encode(k), encode(v)) for k, v in keys]) |
21652
ed6e61eaebc0
pushkey: introduce an ``decodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21650
diff
changeset
|
62 |
|
43075
57875cf423c9
style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents:
25969
diff
changeset
|
63 |
|
21652
ed6e61eaebc0
pushkey: introduce an ``decodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21650
diff
changeset
|
64 |
def decodekeys(data): |
ed6e61eaebc0
pushkey: introduce an ``decodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21650
diff
changeset
|
65 |
"""decode the content of a pushkey namespace from exchange over the wire""" |
ed6e61eaebc0
pushkey: introduce an ``decodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21650
diff
changeset
|
66 |
result = {} |
ed6e61eaebc0
pushkey: introduce an ``decodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21650
diff
changeset
|
67 |
for l in data.splitlines(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43075
diff
changeset
|
68 |
k, v = l.split(b'\t') |
21659
a319842539f5
pushkey: add a ``decode`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21652
diff
changeset
|
69 |
result[decode(k)] = decode(v) |
21652
ed6e61eaebc0
pushkey: introduce an ``decodekeys`` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21650
diff
changeset
|
70 |
return result |