Mercurial > hg-stable
changeset 3814:120be84f33de
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
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 06 Dec 2006 17:58:09 -0600 |
parents | fc5ba0ab7f45 |
children | e3ba19ec8c48 |
files | mercurial/cmdutil.py mercurial/commands.py |
diffstat | 2 files changed, 35 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Wed Dec 06 15:29:17 2006 -0600 +++ b/mercurial/cmdutil.py Wed Dec 06 17:58:09 2006 -0600 @@ -554,6 +554,25 @@ 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.
--- a/mercurial/commands.py Wed Dec 06 15:29:17 2006 -0600 +++ b/mercurial/commands.py Wed Dec 06 17:58:09 2006 -0600 @@ -222,6 +222,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ "^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 @@ (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')),