in eden/scm/edenscm/mercurial/commands/debug.py [0:0]
def debugrevspec(ui, repo, expr, **opts):
"""parse and apply a revision specification
Use -p/--show-stage option to print the parsed tree at the given stages.
Use -p all to print tree at every stage.
Use --no-show-revs option with -s or -p to print only the set
representation or the parsed tree respectively.
Use --verify-optimized to compare the optimized result with the unoptimized
one. Returns 1 if the optimized result differs.
"""
aliases = ui.configitems("revsetalias")
stages = [
("parsed", lambda tree: tree),
("expanded", lambda tree: revsetlang.expandaliases(tree, aliases, ui.warn)),
("concatenated", revsetlang.foldconcat),
("analyzed", revsetlang.analyze),
("optimized", revsetlang.optimize),
]
if opts["no_optimized"]:
stages = stages[:-1]
if opts["verify_optimized"] and opts["no_optimized"]:
raise error.Abort(_("cannot use --verify-optimized with " "--no-optimized"))
stagenames = set(n for n, f in stages)
showalways = set()
showchanged = set()
if ui.verbose and not opts["show_stage"]:
# show parsed tree by --verbose (deprecated)
showalways.add("parsed")
showchanged.update(["expanded", "concatenated"])
if opts["optimize"]:
showalways.add("optimized")
if opts["show_stage"] and opts["optimize"]:
raise error.Abort(_("cannot use --optimize with --show-stage"))
if opts["show_stage"] == ["all"]:
showalways.update(stagenames)
else:
for n in opts["show_stage"]:
if n not in stagenames:
raise error.Abort(_("invalid stage name: %s") % n)
showalways.update(opts["show_stage"])
treebystage = {}
printedtree = None
tree = revsetlang.parse(expr, lookup=repo.__contains__)
for n, f in stages:
treebystage[n] = tree = f(tree)
if n in showalways or (n in showchanged and tree != printedtree):
if opts["show_stage"] or n != "parsed":
ui.write(_x("* %s:\n") % n)
ui.write(revsetlang.prettyformat(tree), "\n")
printedtree = tree
if opts["verify_optimized"]:
arevs = revset.makematcher(treebystage["analyzed"])(repo)
brevs = revset.makematcher(treebystage["optimized"])(repo)
if opts["show_set"] or (opts["show_set"] is None and ui.verbose):
ui.write(_x("* analyzed set:\n"), smartset.prettyformat(arevs), "\n")
ui.write(_x("* optimized set:\n"), smartset.prettyformat(brevs), "\n")
arevs = list(arevs)
brevs = list(brevs)
if arevs == brevs:
return 0
ui.write(_x("--- analyzed\n"), label="diff.file_a")
ui.write(_x("+++ optimized\n"), label="diff.file_b")
sm = difflib.SequenceMatcher(None, arevs, brevs)
for tag, alo, ahi, blo, bhi in sm.get_opcodes():
if tag in ("delete", "replace"):
for c in arevs[alo:ahi]:
ui.write("-%s\n" % c, label="diff.deleted")
if tag in ("insert", "replace"):
for c in brevs[blo:bhi]:
ui.write("+%s\n" % c, label="diff.inserted")
if tag == "equal":
for c in arevs[alo:ahi]:
ui.write(" %s\n" % c)
return 1
func = revset.makematcher(tree)
revs = func(repo)
if opts["show_set"] or (opts["show_set"] is None and ui.verbose):
ui.write(_x("* set:\n"), smartset.prettyformat(revs), "\n")
if not opts["show_revs"]:
return
for c in revs:
ui.write("%s\n" % c)