Commit e79ad285 authored by Anton Shestakov's avatar Anton Shestakov
Browse files

templatekw: drop obsfatedata and related code

AFAIU, this function exists so that people could hack together a replacement
template for {obsfate} if they weren't satisfied with the default, but only on
older versions. It seems that 3d0f8918351b::d0f1e3d3ef4d was the series
introducing obsfate* functions that can show specific obsmarker properties, and
that was included in hg 4.4.

obsfatedata was already claimed to be removed in 35ffd7a4b339 and then more of
its usage was removed in 9882fed37ea9. There are no users in evolve and in core
hg, no tests and nothing else mentions obsfatedata.
parent d684c6d73374
......@@ -11,7 +11,6 @@
from . import (
error,
exthelper,
obshistory
)
from mercurial import (
......@@ -87,135 +86,6 @@ def _getusername(ui):
except error.Abort: # no easy way to avoid ui raising Abort here :-/
return None
def obsfatedefaulttempl(ui):
""" Returns a dict with the default templates for obs fate
"""
# Prepare templates
verbtempl = b'{verb}'
usertempl = b'{if(users, " by {join(users, ", ")}")}'
succtempl = b'{if(successors, " as ")}{successors}' # Bypass if limitation
datetempleq = b' (at {min_date|isodate})'
datetemplnoteq = b' (between {min_date|isodate} and {max_date|isodate})'
datetempl = b'{if(max_date, "{ifeq(min_date, max_date, "%s", "%s")}")}' % (datetempleq, datetemplnoteq)
optionalusertempl = usertempl
username = _getusername(ui)
if username is not None:
optionalusertempl = (b'{ifeq(join(users, "\0"), "%s", "", "%s")}'
% (username, usertempl))
# Assemble them
return {
b'obsfate_quiet': verbtempl + succtempl,
b'obsfate': verbtempl + succtempl + optionalusertempl,
b'obsfate_verbose': verbtempl + succtempl + usertempl + datetempl,
}
def obsfatedata(repo, ctx):
"""compute the raw data needed for computing obsfate
Returns a list of dict
"""
if not ctx.obsolete():
return None
successorssets, pathcache = closestsuccessors(repo, ctx.node())
# closestsuccessors returns an empty list for pruned revisions, remap it
# into a list containing en empty list for future processing
if successorssets == []:
successorssets = [[]]
succsmap = repo.obsstore.successors
fullsuccessorsets = [] # successor set + markers
for sset in successorssets:
if sset:
markers = obshistory.successorsetallmarkers(sset, pathcache)
fullsuccessorsets.append((sset, markers))
else:
# XXX we do not catch all prune markers (eg rewritten then pruned)
# (fix me later)
foundany = False
for mark in succsmap.get(ctx.node(), ()):
if not mark[1]:
foundany = True
fullsuccessorsets.append((sset, [mark]))
if not foundany:
fullsuccessorsets.append(([], []))
values = []
for sset, rawmarkers in fullsuccessorsets:
raw = obshistory.preparesuccessorset(sset, rawmarkers)
values.append(raw)
return values
if not util.safehasattr(templatekw, 'obsfateverb'): # <= hg-4.5
@eh.templatekeyword(b"obsfatedata")
def showobsfatedata(repo, ctx, **args):
# Get the needed obsfate data
values = obsfatedata(repo, ctx)
if values is None:
return templatekw.showlist(b"obsfatedata", [], args)
return _showobsfatedata(repo, ctx, values, **args)
def _showobsfatedata(repo, ctx, values, **args):
# Format each successorset successors list
for raw in values:
# As we can't do something like
# "{join(map(nodeshort, successors), ', '}" in template, manually
# create a correct textual representation
gen = b', '.join(n[:12] for n in raw[b'successors'])
makemap = lambda x: {b'successor': x}
joinfmt = lambda d: b"%s" % d[b'successor']
raw[b'successors'] = templatekw._hybrid(gen, raw[b'successors'], makemap,
joinfmt)
# And then format them
# Insert default obsfate templates
args[b'templ'].cache.update(obsfatedefaulttempl(repo.ui))
if repo.ui.quiet:
name = b"obsfate_quiet"
elif repo.ui.verbose:
name = b"obsfate_verbose"
elif repo.ui.debugflag:
name = b"obsfate_debug"
else:
name = b"obsfate"
# Format a single value
def fmt(d):
nargs = args.copy()
nargs.update(d[name])
templ = args[b'templ']
# HG 4.6
if hasattr(templ, "generate"):
return templ.generate(name, nargs)
else:
return args[b'templ'](name, **nargs)
# Generate a good enough string representation using templater
gen = []
for d in values:
chunk = fmt({name: d})
chunkstr = []
# Empty the generator
try:
while True:
chunkstr.append(next(chunk))
except StopIteration:
pass
gen.append(b"".join(chunkstr))
gen = b"; ".join(gen)
return templatekw._hybrid(gen, values, lambda x: {name: x}, fmt)
# copy from mercurial.obsolete with a small change to stop at first known changeset.
def directsuccessorssets(repo, initialnode, cache=None):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment