Mercurial > hg
comparison mercurial/logexchange.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 876494fd967d |
children | 687b865b95ad |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
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 = 'logexchange' |
20 | |
20 | 21 |
21 def readremotenamefile(repo, filename): | 22 def readremotenamefile(repo, filename): |
22 """ | 23 """ |
23 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 |
24 filename: the file to be read | 25 filename: the file to be read |
43 except ValueError: | 44 except ValueError: |
44 pass | 45 pass |
45 | 46 |
46 f.close() | 47 f.close() |
47 | 48 |
49 | |
48 def readremotenames(repo): | 50 def readremotenames(repo): |
49 """ | 51 """ |
50 read the details about the remotenames stored in .hg/logexchange/ and | 52 read the details about the remotenames stored in .hg/logexchange/ and |
51 yields a tuple (node, remotepath, name). It does not yields information | 53 yields a tuple (node, remotepath, name). It does not yields information |
52 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 | 57 |
56 for bmentry in readremotenamefile(repo, 'bookmarks'): | 58 for bmentry in readremotenamefile(repo, 'bookmarks'): |
57 yield bmentry | 59 yield bmentry |
58 for branchentry in readremotenamefile(repo, 'branches'): | 60 for branchentry in readremotenamefile(repo, 'branches'): |
59 yield branchentry | 61 yield branchentry |
62 | |
60 | 63 |
61 def writeremotenamefile(repo, remotepath, names, nametype): | 64 def writeremotenamefile(repo, remotepath, names, nametype): |
62 vfs = vfsmod.vfs(repo.vfs.join(remotenamedir)) | 65 vfs = vfsmod.vfs(repo.vfs.join(remotenamedir)) |
63 f = vfs(nametype, 'w', atomictemp=True) | 66 f = vfs(nametype, 'w', atomictemp=True) |
64 # write the storage version info on top of file | 67 # write the storage version info on top of file |
79 if node: | 82 if node: |
80 f.write('%s\0%s\0%s\n' % (node, remotepath, name)) | 83 f.write('%s\0%s\0%s\n' % (node, remotepath, name)) |
81 | 84 |
82 f.close() | 85 f.close() |
83 | 86 |
87 | |
84 def saveremotenames(repo, remotepath, branches=None, bookmarks=None): | 88 def saveremotenames(repo, remotepath, branches=None, bookmarks=None): |
85 """ | 89 """ |
86 save remotenames i.e. remotebookmarks and remotebranches in their | 90 save remotenames i.e. remotebookmarks and remotebranches in their |
87 respective files under ".hg/logexchange/" directory. | 91 respective files under ".hg/logexchange/" directory. |
88 """ | 92 """ |
92 writeremotenamefile(repo, remotepath, bookmarks, 'bookmarks') | 96 writeremotenamefile(repo, remotepath, bookmarks, 'bookmarks') |
93 if branches: | 97 if branches: |
94 writeremotenamefile(repo, remotepath, branches, 'branches') | 98 writeremotenamefile(repo, remotepath, branches, 'branches') |
95 finally: | 99 finally: |
96 wlock.release() | 100 wlock.release() |
101 | |
97 | 102 |
98 def activepath(repo, remote): | 103 def activepath(repo, remote): |
99 """returns remote path""" | 104 """returns remote path""" |
100 # is the remote a local peer | 105 # is the remote a local peer |
101 local = remote.local() | 106 local = remote.local() |
121 rpath = path | 126 rpath = path |
122 break | 127 break |
123 | 128 |
124 return rpath | 129 return rpath |
125 | 130 |
131 | |
126 def pullremotenames(localrepo, remoterepo): | 132 def pullremotenames(localrepo, remoterepo): |
127 """ | 133 """ |
128 pulls bookmarks and branches information of the remote repo during a | 134 pulls bookmarks and branches information of the remote repo during a |
129 pull or clone operation. | 135 pull or clone operation. |
130 localrepo is our local repository | 136 localrepo is our local repository |
131 remoterepo is the peer instance | 137 remoterepo is the peer instance |
132 """ | 138 """ |
133 remotepath = activepath(localrepo, remoterepo) | 139 remotepath = activepath(localrepo, remoterepo) |
134 | 140 |
135 with remoterepo.commandexecutor() as e: | 141 with remoterepo.commandexecutor() as e: |
136 bookmarks = e.callcommand('listkeys', { | 142 bookmarks = e.callcommand( |
137 'namespace': 'bookmarks', | 143 'listkeys', {'namespace': 'bookmarks',} |
138 }).result() | 144 ).result() |
139 | 145 |
140 # 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 |
141 # 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 |
142 # remove them here otherwise we would require the user | 148 # remove them here otherwise we would require the user |
143 # to issue a pull to refresh the storage | 149 # to issue a pull to refresh the storage |