# HG changeset patch # User Matt Mackall # Date 2010-10-07 23:24:29 # Node ID 0ae35296fbf4d486ea4228bfd93c03a844ee9fb8 # Parent 2063d36b406e45473e1687dafc315bc3a4f152ea revsets: introduce revsingle helper revsingle returns a context for the last revision of the supplied revspec diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -111,6 +111,15 @@ def loglimit(opts): limit = None return limit +def revsingle(repo, revspec, default=None): + if not revspec: + return repo[default] + + l = revrange(repo, [revspec]) + if len(l) < 1: + raise util.Abort("empty revision set") + return repo[l[-1]] + def revpair(repo, revs): if not revs: return repo.dirstate.parents()[0], None diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -634,7 +634,7 @@ def cat(ui, repo, file1, *pats, **opts): Returns 0 on success. """ - ctx = repo[opts.get('rev')] + ctx = cmdutil.revsingle(repo, opts.get('rev')) err = 1 m = cmdutil.match(repo, (file1,) + pats, opts) for abs in ctx.walk(m):