# HG changeset patch # User Matt Mackall # Date 1165449489 21600 # Node ID 120be84f33de50f12eb8d65191ed825eb65085b6 # Parent fc5ba0ab7f454f3d055086a5b2a1101fe9dd6841 Add --date support to update and revert Add finddate to find the tipmost revision that matches a date spec Add --date option to update Add --date option to revert Don't pass backout's -d option to revert diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -554,6 +554,25 @@ def show_changeset(ui, repo, opts, buffe return t return changeset_printer(ui, repo, patch, br, buffered) +def finddate(ui, repo, date): + """Find the tipmost changeset that matches the given date spec""" + df = util.matchdate(date + " to " + date) + get = util.cachefunc(lambda r: repo.changectx(r).changeset()) + changeiter, matchfn = walkchangerevs(ui, repo, [], get, {'rev':None}) + results = {} + for st, rev, fns in changeiter: + if st == 'add': + d = get(rev)[2] + if df(d[0]): + results[rev] = d + elif st == 'iter': + if rev in results: + ui.status("Found revision %s from %s\n" % + (rev, util.datestr(results[rev]))) + return str(rev) + + raise util.Abort(_("revision matching date not found")) + def walkchangerevs(ui, repo, pats, change, opts): '''Iterate over files and the revs they changed in. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -222,6 +222,7 @@ def backout(ui, repo, rev, **opts): parent = p1 hg.clean(repo, node, show_stats=False) revert_opts = opts.copy() + revert_opts['date'] = None revert_opts['all'] = True revert_opts['rev'] = hex(parent) revert(ui, repo, **revert_opts) @@ -1596,7 +1597,7 @@ def manifest(ui, repo, rev=None): ui.write("%3s " % (m.execf(f) and "755" or "644")) ui.write("%s\n" % f) -def merge(ui, repo, node=None, force=None, branch=None): +def merge(ui, repo, node=None, force=None, branch=None, date=None): """Merge working directory with another revision Merge the contents of the current working directory and the @@ -1943,6 +1944,11 @@ def revert(ui, repo, *pats, **opts): If no arguments are given, no files are reverted. """ + if opts["date"]: + if opts["rev"]: + raise util.Abort(_("you can't specify a revision and a date")) + opts["rev"] = cmdutil.finddate(ui, repo, opts["date"]) + if not pats and not opts['all']: raise util.Abort(_('no files or directories specified; ' 'use --all to revert the whole repo')) @@ -2297,7 +2303,7 @@ def unbundle(ui, repo, fname, **opts): modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname) return postincoming(ui, repo, modheads, opts['update']) -def update(ui, repo, node=None, clean=False, branch=None): +def update(ui, repo, node=None, clean=False, branch=None, date=None): """update or merge working directory Update the working directory to the specified revision. @@ -2312,6 +2318,11 @@ def update(ui, repo, node=None, clean=Fa By default, update will refuse to run if doing so would require merging or discarding local changes. """ + if date: + if node: + raise util.Abort(_("you can't specify a revision and a date")) + node = cmdutil.finddate(ui, repo, date) + node = _lookup(repo, node, branch) if clean: return hg.clean(repo, node) @@ -2676,6 +2687,7 @@ table = { "^revert": (revert, [('a', 'all', None, _('revert all changes when no arguments given')), + ('d', 'date', '', _('tipmost revision matching date')), ('r', 'rev', '', _('revision to revert to')), ('', 'no-backup', None, _('do not save backup copies of files')), ] + walkopts + dryrunopts, @@ -2746,7 +2758,8 @@ table = { (update, [('b', 'branch', '', _('checkout the head of a specific branch (DEPRECATED)')), - ('C', 'clean', None, _('overwrite locally modified files'))], + ('C', 'clean', None, _('overwrite locally modified files')), + ('d', 'date', '', _('tipmost revision matching date'))], _('hg update [-C] [REV]')), "verify": (verify, [], _('hg verify')), "version": (version_, [], _('hg version')),