diff mercurial/cmdutil.py @ 3818: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 cb48cd27d3f4
children 000d122071b5
line wrap: on
line diff
--- 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.