Mercurial > hg-stable
changeset 35356:a29fe459fc49
remotenames: rename related file and storage dir to logexchange
This patch renames remotenames.py to logexchange.py, test-remotenames.t to
test-logexchange.t. Also this patch renames the directory in which the data is
stored from remotenames to logexchange. After this patch, data about bookmarks
and branches from a server we pull is stored in
`.hg/logexchange/(bookmarks|branches)` files.
Thanks to smf for the suggestion.
Differential Revision: https://phab.mercurial-scm.org/D1607
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Thu, 07 Dec 2017 00:26:45 +0530 |
parents | 9eb19b13e92a |
children | 576ba8194fa8 |
files | mercurial/exchange.py mercurial/hg.py mercurial/logexchange.py mercurial/remotenames.py tests/test-logexchange.t tests/test-remotenames.t |
diffstat | 6 files changed, 230 insertions(+), 230 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/exchange.py Thu Dec 07 21:56:18 2017 +0100 +++ b/mercurial/exchange.py Thu Dec 07 00:26:45 2017 +0530 @@ -24,11 +24,11 @@ discovery, error, lock as lockmod, + logexchange, obsolete, phases, pushkey, pycompat, - remotenames, scmutil, sslutil, streamclone, @@ -1366,7 +1366,7 @@ # storing remotenames if repo.ui.configbool('experimental', 'remotenames'): - remotenames.pullremotenames(repo, remote) + logexchange.pullremotenames(repo, remote) return pullop
--- a/mercurial/hg.py Thu Dec 07 21:56:18 2017 +0100 +++ b/mercurial/hg.py Thu Dec 07 00:26:45 2017 +0530 @@ -28,10 +28,10 @@ httppeer, localrepo, lock, + logexchange, merge as mergemod, node, phases, - remotenames, repoview, scmutil, sshpeer, @@ -691,7 +691,7 @@ destrepo.ui.setconfig('paths', 'default', defaulturl, 'clone') if ui.configbool('experimental', 'remotenames'): - remotenames.pullremotenames(destrepo, srcpeer) + logexchange.pullremotenames(destrepo, srcpeer) if update: if update is not True:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial/logexchange.py Thu Dec 07 00:26:45 2017 +0530 @@ -0,0 +1,118 @@ +# logexchange.py +# +# Copyright 2017 Augie Fackler <raf@durin42.com> +# Copyright 2017 Sean Farley <sean@farley.io> +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. + +from __future__ import absolute_import + +from .node import hex + +from . import ( + vfs as vfsmod, +) + +# directory name in .hg/ in which remotenames files will be present +remotenamedir = 'logexchange' + +def readremotenamefile(repo, filename): + """ + reads a file from .hg/logexchange/ directory and yields it's content + filename: the file to be read + yield a tuple (node, remotepath, name) + """ + + vfs = vfsmod.vfs(repo.vfs.join(remotenamedir)) + if not vfs.exists(filename): + return + f = vfs(filename) + lineno = 0 + for line in f: + line = line.strip() + if not line: + continue + # contains the version number + if lineno == 0: + lineno += 1 + try: + node, remote, rname = line.split('\0') + yield node, remote, rname + except ValueError: + pass + + f.close() + +def readremotenames(repo): + """ + read the details about the remotenames stored in .hg/logexchange/ and + yields a tuple (node, remotepath, name). It does not yields information + about whether an entry yielded is branch or bookmark. To get that + information, call the respective functions. + """ + + for bmentry in readremotenamefile(repo, 'bookmarks'): + yield bmentry + for branchentry in readremotenamefile(repo, 'branches'): + yield branchentry + +def writeremotenamefile(repo, remotepath, names, nametype): + vfs = vfsmod.vfs(repo.vfs.join(remotenamedir)) + f = vfs(nametype, 'w', atomictemp=True) + # write the storage version info on top of file + # version '0' represents the very initial version of the storage format + f.write('0\n\n') + + olddata = set(readremotenamefile(repo, nametype)) + # re-save the data from a different remote than this one. + for node, oldpath, rname in sorted(olddata): + if oldpath != remotepath: + f.write('%s\0%s\0%s\n' % (node, oldpath, rname)) + + for name, node in sorted(names.iteritems()): + if nametype == "branches": + for n in node: + f.write('%s\0%s\0%s\n' % (n, remotepath, name)) + elif nametype == "bookmarks": + if node: + f.write('%s\0%s\0%s\n' % (node, remotepath, name)) + + f.close() + +def saveremotenames(repo, remotepath, branches=None, bookmarks=None): + """ + save remotenames i.e. remotebookmarks and remotebranches in their + respective files under ".hg/logexchange/" directory. + """ + wlock = repo.wlock() + try: + if bookmarks: + writeremotenamefile(repo, remotepath, bookmarks, 'bookmarks') + if branches: + writeremotenamefile(repo, remotepath, branches, 'branches') + finally: + wlock.release() + +def pullremotenames(localrepo, remoterepo): + """ + pulls bookmarks and branches information of the remote repo during a + pull or clone operation. + localrepo is our local repository + remoterepo is the peer instance + """ + remotepath = remoterepo.url() + bookmarks = remoterepo.listkeys('bookmarks') + # on a push, we don't want to keep obsolete heads since + # they won't show up as heads on the next pull, so we + # remove them here otherwise we would require the user + # to issue a pull to refresh the storage + bmap = {} + repo = localrepo.unfiltered() + for branch, nodes in remoterepo.branchmap().iteritems(): + bmap[branch] = [] + for node in nodes: + if node in repo and not repo[node].obsolete(): + bmap[branch].append(hex(node)) + + saveremotenames(localrepo, remotepath, bmap, bookmarks)
--- a/mercurial/remotenames.py Thu Dec 07 21:56:18 2017 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +0,0 @@ -# remotenames.py -# -# Copyright 2017 Augie Fackler <raf@durin42.com> -# Copyright 2017 Sean Farley <sean@farley.io> -# -# This software may be used and distributed according to the terms of the -# GNU General Public License version 2 or any later version. - -from __future__ import absolute_import - -from .node import hex - -from . import ( - vfs as vfsmod, -) - -# directory name in .hg/ in which remotenames files will be present -remotenamedir = 'remotenames' - -def readremotenamefile(repo, filename): - """ - reads a file from .hg/remotenames/ directory and yields it's content - filename: the file to be read - yield a tuple (node, remotepath, name) - """ - - vfs = vfsmod.vfs(repo.vfs.join(remotenamedir)) - if not vfs.exists(filename): - return - f = vfs(filename) - lineno = 0 - for line in f: - line = line.strip() - if not line: - continue - # contains the version number - if lineno == 0: - lineno += 1 - try: - node, remote, rname = line.split('\0') - yield node, remote, rname - except ValueError: - pass - - f.close() - -def readremotenames(repo): - """ - read the details about the remotenames stored in .hg/remotenames/ and - yields a tuple (node, remotepath, name). It does not yields information - about whether an entry yielded is branch or bookmark. To get that - information, call the respective functions. - """ - - for bmentry in readremotenamefile(repo, 'bookmarks'): - yield bmentry - for branchentry in readremotenamefile(repo, 'branches'): - yield branchentry - -def writeremotenamefile(repo, remotepath, names, nametype): - vfs = vfsmod.vfs(repo.vfs.join(remotenamedir)) - f = vfs(nametype, 'w', atomictemp=True) - # write the storage version info on top of file - # version '0' represents the very initial version of the storage format - f.write('0\n\n') - - olddata = set(readremotenamefile(repo, nametype)) - # re-save the data from a different remote than this one. - for node, oldpath, rname in sorted(olddata): - if oldpath != remotepath: - f.write('%s\0%s\0%s\n' % (node, oldpath, rname)) - - for name, node in sorted(names.iteritems()): - if nametype == "branches": - for n in node: - f.write('%s\0%s\0%s\n' % (n, remotepath, name)) - elif nametype == "bookmarks": - if node: - f.write('%s\0%s\0%s\n' % (node, remotepath, name)) - - f.close() - -def saveremotenames(repo, remotepath, branches=None, bookmarks=None): - """ - save remotenames i.e. remotebookmarks and remotebranches in their - respective files under ".hg/remotenames/" directory. - """ - wlock = repo.wlock() - try: - if bookmarks: - writeremotenamefile(repo, remotepath, bookmarks, 'bookmarks') - if branches: - writeremotenamefile(repo, remotepath, branches, 'branches') - finally: - wlock.release() - -def pullremotenames(localrepo, remoterepo): - """ - pulls bookmarks and branches information of the remote repo during a - pull or clone operation. - localrepo is our local repository - remoterepo is the peer instance - """ - remotepath = remoterepo.url() - bookmarks = remoterepo.listkeys('bookmarks') - # on a push, we don't want to keep obsolete heads since - # they won't show up as heads on the next pull, so we - # remove them here otherwise we would require the user - # to issue a pull to refresh the storage - bmap = {} - repo = localrepo.unfiltered() - for branch, nodes in remoterepo.branchmap().iteritems(): - bmap[branch] = [] - for node in nodes: - if node in repo and not repo[node].obsolete(): - bmap[branch].append(hex(node)) - - saveremotenames(localrepo, remotepath, bmap, bookmarks)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-logexchange.t Thu Dec 07 00:26:45 2017 +0530 @@ -0,0 +1,108 @@ +Testing the functionality to pull remotenames +============================================= + + $ cat >> $HGRCPATH << EOF + > [alias] + > glog = log -G -T '{rev}:{node|short} {desc}' + > [experimental] + > remotenames = True + > EOF + +Making a server repo +-------------------- + + $ hg init server + $ cd server + $ for ch in a b c d e f g h; do + > echo "foo" >> $ch + > hg ci -Aqm "Added "$ch + > done + $ hg glog + @ 7:ec2426147f0e Added h + | + o 6:87d6d6676308 Added g + | + o 5:825660c69f0c Added f + | + o 4:aa98ab95a928 Added e + | + o 3:62615734edd5 Added d + | + o 2:28ad74487de9 Added c + | + o 1:29becc82797a Added b + | + o 0:18d04c59bb5d Added a + + $ hg bookmark -r 3 foo + $ hg bookmark -r 6 bar + $ hg up 4 + 0 files updated, 0 files merged, 3 files removed, 0 files unresolved + $ hg branch wat + marked working directory as branch wat + (branches are permanent and global, did you want a bookmark?) + $ echo foo >> bar + $ hg ci -Aqm "added bar" + +Making a client repo +-------------------- + + $ cd .. + + $ hg clone server client + updating to branch default + 8 files updated, 0 files merged, 0 files removed, 0 files unresolved + + $ cd client + $ cat .hg/logexchange/bookmarks + 0 + + 87d6d66763085b629e6d7ed56778c79827273022\x00file:$TESTTMP/server\x00bar (esc) + 62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00file:$TESTTMP/server\x00foo (esc) + + $ cat .hg/logexchange/branches + 0 + + ec2426147f0e39dbc9cef599b066be6035ce691d\x00file:$TESTTMP/server\x00default (esc) + 3e1487808078543b0af6d10dadf5d46943578db0\x00file:$TESTTMP/server\x00wat (esc) + +Making a new server +------------------- + + $ cd .. + $ hg init server2 + $ cd server2 + $ hg pull ../server/ + pulling from ../server/ + requesting all changes + adding changesets + adding manifests + adding file changes + added 9 changesets with 9 changes to 9 files (+1 heads) + adding remote bookmark bar + adding remote bookmark foo + new changesets 18d04c59bb5d:3e1487808078 + (run 'hg heads' to see heads) + +Pulling form the new server +--------------------------- + $ cd ../client/ + $ hg pull ../server2/ + pulling from ../server2/ + searching for changes + no changes found + $ cat .hg/logexchange/bookmarks + 0 + + 62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00file:$TESTTMP/server\x00foo (esc) + 87d6d66763085b629e6d7ed56778c79827273022\x00file:$TESTTMP/server\x00bar (esc) + 87d6d66763085b629e6d7ed56778c79827273022\x00file:$TESTTMP/server2\x00bar (esc) + 62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00file:$TESTTMP/server2\x00foo (esc) + + $ cat .hg/logexchange/branches + 0 + + 3e1487808078543b0af6d10dadf5d46943578db0\x00file:$TESTTMP/server\x00wat (esc) + ec2426147f0e39dbc9cef599b066be6035ce691d\x00file:$TESTTMP/server\x00default (esc) + ec2426147f0e39dbc9cef599b066be6035ce691d\x00file:$TESTTMP/server2\x00default (esc) + 3e1487808078543b0af6d10dadf5d46943578db0\x00file:$TESTTMP/server2\x00wat (esc)
--- a/tests/test-remotenames.t Thu Dec 07 21:56:18 2017 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -Testing the functionality to pull remotenames -============================================= - - $ cat >> $HGRCPATH << EOF - > [alias] - > glog = log -G -T '{rev}:{node|short} {desc}' - > [experimental] - > remotenames = True - > EOF - -Making a server repo --------------------- - - $ hg init server - $ cd server - $ for ch in a b c d e f g h; do - > echo "foo" >> $ch - > hg ci -Aqm "Added "$ch - > done - $ hg glog - @ 7:ec2426147f0e Added h - | - o 6:87d6d6676308 Added g - | - o 5:825660c69f0c Added f - | - o 4:aa98ab95a928 Added e - | - o 3:62615734edd5 Added d - | - o 2:28ad74487de9 Added c - | - o 1:29becc82797a Added b - | - o 0:18d04c59bb5d Added a - - $ hg bookmark -r 3 foo - $ hg bookmark -r 6 bar - $ hg up 4 - 0 files updated, 0 files merged, 3 files removed, 0 files unresolved - $ hg branch wat - marked working directory as branch wat - (branches are permanent and global, did you want a bookmark?) - $ echo foo >> bar - $ hg ci -Aqm "added bar" - -Making a client repo --------------------- - - $ cd .. - - $ hg clone server client - updating to branch default - 8 files updated, 0 files merged, 0 files removed, 0 files unresolved - - $ cd client - $ cat .hg/remotenames/bookmarks - 0 - - 87d6d66763085b629e6d7ed56778c79827273022\x00file:$TESTTMP/server\x00bar (esc) - 62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00file:$TESTTMP/server\x00foo (esc) - - $ cat .hg/remotenames/branches - 0 - - ec2426147f0e39dbc9cef599b066be6035ce691d\x00file:$TESTTMP/server\x00default (esc) - 3e1487808078543b0af6d10dadf5d46943578db0\x00file:$TESTTMP/server\x00wat (esc) - -Making a new server -------------------- - - $ cd .. - $ hg init server2 - $ cd server2 - $ hg pull ../server/ - pulling from ../server/ - requesting all changes - adding changesets - adding manifests - adding file changes - added 9 changesets with 9 changes to 9 files (+1 heads) - adding remote bookmark bar - adding remote bookmark foo - new changesets 18d04c59bb5d:3e1487808078 - (run 'hg heads' to see heads) - -Pulling form the new server ---------------------------- - $ cd ../client/ - $ hg pull ../server2/ - pulling from ../server2/ - searching for changes - no changes found - $ cat .hg/remotenames/bookmarks - 0 - - 62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00file:$TESTTMP/server\x00foo (esc) - 87d6d66763085b629e6d7ed56778c79827273022\x00file:$TESTTMP/server\x00bar (esc) - 87d6d66763085b629e6d7ed56778c79827273022\x00file:$TESTTMP/server2\x00bar (esc) - 62615734edd52f06b6fb9c2beb429e4fe30d57b8\x00file:$TESTTMP/server2\x00foo (esc) - - $ cat .hg/remotenames/branches - 0 - - 3e1487808078543b0af6d10dadf5d46943578db0\x00file:$TESTTMP/server\x00wat (esc) - ec2426147f0e39dbc9cef599b066be6035ce691d\x00file:$TESTTMP/server\x00default (esc) - ec2426147f0e39dbc9cef599b066be6035ce691d\x00file:$TESTTMP/server2\x00default (esc) - 3e1487808078543b0af6d10dadf5d46943578db0\x00file:$TESTTMP/server2\x00wat (esc)