mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 17:27:53 +03:00
remotenames: split bookmarks and branches into their own namespaces
This commit is contained in:
parent
dab281a640
commit
b6d0adcc5e
118
remotenames.py
118
remotenames.py
@ -14,8 +14,10 @@ from mercurial import util
|
||||
from mercurial.node import hex
|
||||
from hgext import schemes
|
||||
|
||||
_remotenames = {}
|
||||
_remotetypes = {}
|
||||
_remotenames = {
|
||||
"bookmarks": {},
|
||||
"branches": {},
|
||||
}
|
||||
|
||||
def expush(orig, repo, remote, *args, **kwargs):
|
||||
# hack for pushing that turns off the dynamic blockerhook
|
||||
@ -64,18 +66,21 @@ def blockerhook(orig, repo, *args, **kwargs):
|
||||
blockers = orig(repo)
|
||||
|
||||
# protect un-hiding changesets behind a config knob
|
||||
noname = 'remotenames' not in repo.names
|
||||
nohide = not repo.ui.configbool('remotenames', 'unhide')
|
||||
hackpush = util.safehasattr(repo, '_hackremotenamepush')
|
||||
if noname or nohide or (hackpush and repo._hackremotenamepush):
|
||||
if nohide or (hackpush and repo._hackremotenamepush):
|
||||
return blockers
|
||||
|
||||
# add remotenames to blockers
|
||||
# add remotenames to blockers by looping over all names in our own cache
|
||||
cl = repo.changelog
|
||||
ns = repo.names["remotenames"]
|
||||
for name in ns.listnames(repo):
|
||||
blockers.update(cl.rev(node) for node in
|
||||
ns.nodes(repo, name))
|
||||
for remotename in _remotenames.keys():
|
||||
rname = 'remote' + remotename
|
||||
try:
|
||||
ns = repo.names[rname]
|
||||
except KeyError:
|
||||
continue
|
||||
for name in ns.listnames(repo):
|
||||
blockers.update(cl.rev(node) for node in ns.nodes(repo, name))
|
||||
|
||||
return blockers
|
||||
|
||||
@ -89,13 +94,25 @@ def reposetup(ui, repo):
|
||||
|
||||
loadremotenames(repo)
|
||||
|
||||
ns = namespaces.namespace
|
||||
n = ns("remotenames", "remotename",
|
||||
lambda rp: _remotenames.keys(),
|
||||
lambda rp, name: namespaces.tolist(_remotenames.get(name)),
|
||||
lambda rp, node: [name for name, n in _remotenames.iteritems()
|
||||
if n == node])
|
||||
repo.names.addnamespace(n)
|
||||
# cache this so we don't iterate over new values
|
||||
items = list(repo.names.iteritems())
|
||||
for nsname, ns in items:
|
||||
d = _remotenames.get(nsname)
|
||||
if not d:
|
||||
continue
|
||||
|
||||
rname = 'remote' + nsname
|
||||
rtmpl = 'remote' + ns.templatename
|
||||
names = lambda rp, d=d: d.keys()
|
||||
namemap = lambda rp, name, d=d: namespaces.tolist(d.get(name))
|
||||
nodemap = lambda rp, node, d=d: [name for name, n in
|
||||
d.iteritems() if n == node]
|
||||
|
||||
n = namespaces.namespace(rname, templatename=rtmpl,
|
||||
logname=ns.templatename, colorname=rtmpl,
|
||||
listnames=names, namemap=namemap,
|
||||
nodemap=nodemap)
|
||||
repo.names.addnamespace(n)
|
||||
|
||||
def activepath(ui, remote):
|
||||
realpath = ''
|
||||
@ -189,6 +206,9 @@ def readremotenames(repo):
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
nametype = None
|
||||
remote, rname = None, None
|
||||
|
||||
node, name = line.split(' ', 1)
|
||||
|
||||
# check for nametype being written into the file format
|
||||
@ -231,8 +251,7 @@ def loadremotenames(repo):
|
||||
|
||||
# only mark as remote if the head changeset isn't marked closed
|
||||
if not ctx.extra().get('close'):
|
||||
_remotenames[name] = ctx.node()
|
||||
_remotetypes[name] = nametype
|
||||
_remotenames[nametype][name] = ctx.node()
|
||||
|
||||
def saveremotenames(repo, remote, branches, bookmarks):
|
||||
# read in all data first before opening file to write
|
||||
@ -261,10 +280,15 @@ def saveremotenames(repo, remote, branches, bookmarks):
|
||||
|
||||
def upstream_revs(filt, repo, subset, x):
|
||||
upstream_tips = set()
|
||||
ns = repo.names["remotenames"]
|
||||
for name in ns.listnames(repo):
|
||||
if filt(name):
|
||||
upstream_tips.update(ns.nodes(repo, name))
|
||||
for remotename in _remotenames.keys():
|
||||
rname = 'remote' + remotename
|
||||
try:
|
||||
ns = repo.names[rname]
|
||||
except KeyError:
|
||||
continue
|
||||
for name in ns.listnames(repo):
|
||||
if filt(name):
|
||||
upstream_tips.update(ns.nodes(repo, name))
|
||||
|
||||
if not upstream_tips:
|
||||
return revset.baseset([])
|
||||
@ -299,9 +323,15 @@ def remotenamesrevset(repo, subset, x):
|
||||
revset.getargs(x, 0, 0, "remotenames takes no arguments")
|
||||
remoterevs = set()
|
||||
cl = repo.changelog
|
||||
ns = repo.names["remotenames"]
|
||||
for name in ns.listnames(repo):
|
||||
remoterevs.update(ns.nodes(repo, name))
|
||||
for remotename in _remotenames.keys():
|
||||
rname = 'remote' + remotename
|
||||
try:
|
||||
ns = repo.names[rname]
|
||||
except KeyError:
|
||||
continue
|
||||
for name in ns.listnames(repo):
|
||||
remoterevs.update(ns.nodes(repo, name))
|
||||
|
||||
return revset.baseset(sorted(cl.rev(n) for n in remoterevs))
|
||||
|
||||
revset.symbols.update({'upstream': upstream,
|
||||
@ -312,34 +342,6 @@ revset.symbols.update({'upstream': upstream,
|
||||
# templates
|
||||
###########
|
||||
|
||||
def remotebookmarkskw(**args):
|
||||
""":remotebookmarks: List of strings. List of remote bookmarks associated with
|
||||
the changeset.
|
||||
|
||||
"""
|
||||
repo, ctx = args['repo'], args['ctx']
|
||||
|
||||
remotebooks = [name for name in
|
||||
repo.names['remotenames'].names(repo, ctx.node())
|
||||
if _remotetypes[name] == 'bookmarks']
|
||||
|
||||
return templatekw.showlist('remotebookmark', remotebooks,
|
||||
plural='remotebookmarks', **args)
|
||||
|
||||
def remotebrancheskw(**args):
|
||||
""":remotebranches: List of strings. List of remote branches associated with
|
||||
the changeset.
|
||||
|
||||
"""
|
||||
repo, ctx = args['repo'], args['ctx']
|
||||
|
||||
remotebranches = [name for name in
|
||||
repo.names['remotenames'].names(repo, ctx.node())
|
||||
if _remotetypes[name] == 'branches']
|
||||
|
||||
return templatekw.showlist('remotebranch', remotebranches,
|
||||
plural='remotebranches', **args)
|
||||
|
||||
def remotenameskw(**args):
|
||||
""":remotenames: List of strings. List of remote names associated with the
|
||||
changeset. If remotenames.suppressbranches is True then branch names will
|
||||
@ -348,19 +350,13 @@ def remotenameskw(**args):
|
||||
"""
|
||||
repo, ctx = args['repo'], args['ctx']
|
||||
|
||||
remotenames = [name for name in
|
||||
repo.names['remotenames'].names(repo, ctx.node())
|
||||
if _remotetypes[name] == 'bookmarks']
|
||||
remotenames = repo.names['remotebookmarks'].names(repo, ctx.node())
|
||||
|
||||
suppress = repo.ui.configbool('remotenames', 'suppressbranches', False)
|
||||
if not remotenames or not suppress:
|
||||
remotenames += [name for name in
|
||||
repo.names['remotenames'].names(repo, ctx.node())
|
||||
if _remotetypes[name] == 'branches']
|
||||
remotenames += repo.names['remotebranches'].names(repo, ctx.node())
|
||||
|
||||
return templatekw.showlist('remotename', remotenames,
|
||||
plural='remotenames', **args)
|
||||
|
||||
templatekw.keywords['remotebookmarks'] = remotebookmarkskw
|
||||
templatekw.keywords['remotebranches'] = remotebrancheskw
|
||||
templatekw.keywords['remotenames'] = remotenameskw
|
||||
|
@ -93,7 +93,7 @@
|
||||
|
||||
changeset: 4:a43aa1e4a27c
|
||||
branch: stable
|
||||
remotename: beta/stable
|
||||
branch: beta/stable
|
||||
parent: 2:5b35a0d5bd4d
|
||||
parent: 3:5ae9f075bc64
|
||||
user: test
|
||||
@ -101,7 +101,7 @@
|
||||
summary: merged
|
||||
|
||||
changeset: 3:5ae9f075bc64
|
||||
remotename: beta
|
||||
branch: beta
|
||||
parent: 1:2b9c7234e035
|
||||
user: test
|
||||
date: Thu Jan 01 00:00:00 1970 +0000
|
||||
@ -109,13 +109,13 @@
|
||||
|
||||
changeset: 2:5b35a0d5bd4d
|
||||
branch: stable
|
||||
remotename: default/stable
|
||||
branch: default/stable
|
||||
user: test
|
||||
date: Thu Jan 01 00:00:00 1970 +0000
|
||||
summary: 2
|
||||
|
||||
changeset: 1:2b9c7234e035
|
||||
remotename: default/default
|
||||
branch: default/default
|
||||
user: test
|
||||
date: Thu Jan 01 00:00:00 1970 +0000
|
||||
summary: 1
|
||||
|
@ -94,7 +94,7 @@ graph shows tags for the branch heads of each path
|
||||
| |
|
||||
o | changeset: 4:8948da77173b
|
||||
|\| branch: stable
|
||||
| | remotename: beta/stable
|
||||
| | branch: beta/stable
|
||||
| | parent: 2:95cb4ab9fe1d
|
||||
| | parent: 3:78f83396d79e
|
||||
| | user: test
|
||||
@ -103,8 +103,8 @@ graph shows tags for the branch heads of each path
|
||||
| |
|
||||
| o changeset: 3:78f83396d79e
|
||||
| | bookmark: babar
|
||||
| | remotename: beta/babar
|
||||
| | remotename: beta/default
|
||||
| | bookmark: beta/babar
|
||||
| | branch: beta/default
|
||||
| | parent: 1:7c3bad9141dc
|
||||
| | user: test
|
||||
| | date: Thu Jan 01 00:00:00 1970 +0000
|
||||
@ -112,13 +112,13 @@ graph shows tags for the branch heads of each path
|
||||
| |
|
||||
o | changeset: 2:95cb4ab9fe1d
|
||||
|/ branch: stable
|
||||
| remotename: alpha/stable
|
||||
| branch: alpha/stable
|
||||
| user: test
|
||||
| date: Thu Jan 01 00:00:00 1970 +0000
|
||||
| summary: add c
|
||||
|
|
||||
o changeset: 1:7c3bad9141dc
|
||||
| remotename: alpha/default
|
||||
| branch: alpha/default
|
||||
| user: test
|
||||
| date: Thu Jan 01 00:00:00 1970 +0000
|
||||
| summary: add b
|
||||
@ -196,7 +196,7 @@ but configured, it'll do the expected thing:
|
||||
| |
|
||||
o | changeset: 4:8948da77173b
|
||||
|\| branch: stable
|
||||
| | remotename: beta/stable
|
||||
| | branch: beta/stable
|
||||
| | parent: 2:95cb4ab9fe1d
|
||||
| | parent: 3:78f83396d79e
|
||||
| | user: test
|
||||
@ -205,8 +205,8 @@ but configured, it'll do the expected thing:
|
||||
| |
|
||||
| o changeset: 3:78f83396d79e
|
||||
| | bookmark: babar
|
||||
| | remotename: beta/babar
|
||||
| | remotename: beta/default
|
||||
| | bookmark: beta/babar
|
||||
| | branch: beta/default
|
||||
| | parent: 1:7c3bad9141dc
|
||||
| | user: test
|
||||
| | date: Thu Jan 01 00:00:00 1970 +0000
|
||||
@ -215,7 +215,7 @@ but configured, it'll do the expected thing:
|
||||
$ hg log --limit 2 --graph -r 'heads(upstream())'
|
||||
o changeset: 2:95cb4ab9fe1d
|
||||
| branch: stable
|
||||
| remotename: alpha/stable
|
||||
| branch: alpha/stable
|
||||
| user: test
|
||||
| date: Thu Jan 01 00:00:00 1970 +0000
|
||||
| summary: add c
|
||||
|
Loading…
Reference in New Issue
Block a user