Mercurial > hg
comparison mercurial/logexchange.py @ 43077:687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Done with
python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py')
black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**')
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6972
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:48:39 -0400 |
parents | 2372284d9457 |
children | d783f945a701 |
comparison
equal
deleted
inserted
replaced
43076:2372284d9457 | 43077:687b865b95ad |
---|---|
14 util, | 14 util, |
15 vfs as vfsmod, | 15 vfs as vfsmod, |
16 ) | 16 ) |
17 | 17 |
18 # directory name in .hg/ in which remotenames files will be present | 18 # directory name in .hg/ in which remotenames files will be present |
19 remotenamedir = 'logexchange' | 19 remotenamedir = b'logexchange' |
20 | 20 |
21 | 21 |
22 def readremotenamefile(repo, filename): | 22 def readremotenamefile(repo, filename): |
23 """ | 23 """ |
24 reads a file from .hg/logexchange/ directory and yields it's content | 24 reads a file from .hg/logexchange/ directory and yields it's content |
37 continue | 37 continue |
38 # contains the version number | 38 # contains the version number |
39 if lineno == 0: | 39 if lineno == 0: |
40 lineno += 1 | 40 lineno += 1 |
41 try: | 41 try: |
42 node, remote, rname = line.split('\0') | 42 node, remote, rname = line.split(b'\0') |
43 yield node, remote, rname | 43 yield node, remote, rname |
44 except ValueError: | 44 except ValueError: |
45 pass | 45 pass |
46 | 46 |
47 f.close() | 47 f.close() |
53 yields a tuple (node, remotepath, name). It does not yields information | 53 yields a tuple (node, remotepath, name). It does not yields information |
54 about whether an entry yielded is branch or bookmark. To get that | 54 about whether an entry yielded is branch or bookmark. To get that |
55 information, call the respective functions. | 55 information, call the respective functions. |
56 """ | 56 """ |
57 | 57 |
58 for bmentry in readremotenamefile(repo, 'bookmarks'): | 58 for bmentry in readremotenamefile(repo, b'bookmarks'): |
59 yield bmentry | 59 yield bmentry |
60 for branchentry in readremotenamefile(repo, 'branches'): | 60 for branchentry in readremotenamefile(repo, b'branches'): |
61 yield branchentry | 61 yield branchentry |
62 | 62 |
63 | 63 |
64 def writeremotenamefile(repo, remotepath, names, nametype): | 64 def writeremotenamefile(repo, remotepath, names, nametype): |
65 vfs = vfsmod.vfs(repo.vfs.join(remotenamedir)) | 65 vfs = vfsmod.vfs(repo.vfs.join(remotenamedir)) |
66 f = vfs(nametype, 'w', atomictemp=True) | 66 f = vfs(nametype, b'w', atomictemp=True) |
67 # write the storage version info on top of file | 67 # write the storage version info on top of file |
68 # version '0' represents the very initial version of the storage format | 68 # version '0' represents the very initial version of the storage format |
69 f.write('0\n\n') | 69 f.write(b'0\n\n') |
70 | 70 |
71 olddata = set(readremotenamefile(repo, nametype)) | 71 olddata = set(readremotenamefile(repo, nametype)) |
72 # re-save the data from a different remote than this one. | 72 # re-save the data from a different remote than this one. |
73 for node, oldpath, rname in sorted(olddata): | 73 for node, oldpath, rname in sorted(olddata): |
74 if oldpath != remotepath: | 74 if oldpath != remotepath: |
75 f.write('%s\0%s\0%s\n' % (node, oldpath, rname)) | 75 f.write(b'%s\0%s\0%s\n' % (node, oldpath, rname)) |
76 | 76 |
77 for name, node in sorted(names.iteritems()): | 77 for name, node in sorted(names.iteritems()): |
78 if nametype == "branches": | 78 if nametype == b"branches": |
79 for n in node: | 79 for n in node: |
80 f.write('%s\0%s\0%s\n' % (n, remotepath, name)) | 80 f.write(b'%s\0%s\0%s\n' % (n, remotepath, name)) |
81 elif nametype == "bookmarks": | 81 elif nametype == b"bookmarks": |
82 if node: | 82 if node: |
83 f.write('%s\0%s\0%s\n' % (node, remotepath, name)) | 83 f.write(b'%s\0%s\0%s\n' % (node, remotepath, name)) |
84 | 84 |
85 f.close() | 85 f.close() |
86 | 86 |
87 | 87 |
88 def saveremotenames(repo, remotepath, branches=None, bookmarks=None): | 88 def saveremotenames(repo, remotepath, branches=None, bookmarks=None): |
91 respective files under ".hg/logexchange/" directory. | 91 respective files under ".hg/logexchange/" directory. |
92 """ | 92 """ |
93 wlock = repo.wlock() | 93 wlock = repo.wlock() |
94 try: | 94 try: |
95 if bookmarks: | 95 if bookmarks: |
96 writeremotenamefile(repo, remotepath, bookmarks, 'bookmarks') | 96 writeremotenamefile(repo, remotepath, bookmarks, b'bookmarks') |
97 if branches: | 97 if branches: |
98 writeremotenamefile(repo, remotepath, branches, 'branches') | 98 writeremotenamefile(repo, remotepath, branches, b'branches') |
99 finally: | 99 finally: |
100 wlock.release() | 100 wlock.release() |
101 | 101 |
102 | 102 |
103 def activepath(repo, remote): | 103 def activepath(repo, remote): |
112 rpath = util.pconvert(remote._repo.root) | 112 rpath = util.pconvert(remote._repo.root) |
113 elif not isinstance(remote, bytes): | 113 elif not isinstance(remote, bytes): |
114 rpath = remote._url | 114 rpath = remote._url |
115 | 115 |
116 # represent the remotepath with user defined path name if exists | 116 # represent the remotepath with user defined path name if exists |
117 for path, url in repo.ui.configitems('paths'): | 117 for path, url in repo.ui.configitems(b'paths'): |
118 # remove auth info from user defined url | 118 # remove auth info from user defined url |
119 noauthurl = util.removeauth(url) | 119 noauthurl = util.removeauth(url) |
120 | 120 |
121 # Standardize on unix style paths, otherwise some {remotenames} end up | 121 # Standardize on unix style paths, otherwise some {remotenames} end up |
122 # being an absolute path on Windows. | 122 # being an absolute path on Windows. |
138 """ | 138 """ |
139 remotepath = activepath(localrepo, remoterepo) | 139 remotepath = activepath(localrepo, remoterepo) |
140 | 140 |
141 with remoterepo.commandexecutor() as e: | 141 with remoterepo.commandexecutor() as e: |
142 bookmarks = e.callcommand( | 142 bookmarks = e.callcommand( |
143 'listkeys', {'namespace': 'bookmarks',} | 143 b'listkeys', {b'namespace': b'bookmarks',} |
144 ).result() | 144 ).result() |
145 | 145 |
146 # on a push, we don't want to keep obsolete heads since | 146 # on a push, we don't want to keep obsolete heads since |
147 # they won't show up as heads on the next pull, so we | 147 # they won't show up as heads on the next pull, so we |
148 # remove them here otherwise we would require the user | 148 # remove them here otherwise we would require the user |
149 # to issue a pull to refresh the storage | 149 # to issue a pull to refresh the storage |
150 bmap = {} | 150 bmap = {} |
151 repo = localrepo.unfiltered() | 151 repo = localrepo.unfiltered() |
152 | 152 |
153 with remoterepo.commandexecutor() as e: | 153 with remoterepo.commandexecutor() as e: |
154 branchmap = e.callcommand('branchmap', {}).result() | 154 branchmap = e.callcommand(b'branchmap', {}).result() |
155 | 155 |
156 for branch, nodes in branchmap.iteritems(): | 156 for branch, nodes in branchmap.iteritems(): |
157 bmap[branch] = [] | 157 bmap[branch] = [] |
158 for node in nodes: | 158 for node in nodes: |
159 if node in repo and not repo[node].obsolete(): | 159 if node in repo and not repo[node].obsolete(): |