[DISCUSS] revert/progress: adding units (files) and switching straggler to gerund (scanning)

timeless timeless at gmail.com
Thu Oct 14 03:15:10 CDT 2010


I have a patch (below) which adds progress for revert.

This requires a longer explanation than the other patches I've sent
this morning....

Updating and Reverting aren't really the same. When you update, you
don't really care what you're updating, you know where you're going,
and it's supposed to be absolutely safe.

When you do a revert (especially with mozilla-central or a similar
large repository), you actually want to be reminded about which files
you're reverting (it's easy to mess up). Also, because it takes so
long to do, it's useful to see where it's wasting its time. At least
that's my experience.

# HG changeset patch
# User timeless <timeless at gmail.com>
# Date 1279869598 -10800
# Node ID 531eec4d858686ea73d5e63f32f8059cad754e54
# Parent  c6df71115ac6fb5c9416dc1d435ad2a1731fe94e
revert/progress: adding units (files) and switching straggler to
gerund (scanning)

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3074,8 +3074,13 @@ def revert(ui, repo, *pats, **opts):

         m = cmdutil.match(repo, pats, opts)
         m.bad = lambda x, y: False
+        count = 0
+        ui.progress(_('discovering'), 0)
         for abs in repo.walk(m):
+            count += 1
+            ui.progress(_('discovering'), count)
             names[abs] = m.rel(abs), m.exact(abs)
+        ui.progress(_('discovering'), None)

         # walk target manifest.

@@ -3090,12 +3095,20 @@ def revert(ui, repo, *pats, **opts):

         m = cmdutil.match(repo, pats, opts)
         m.bad = badfn
+        total = count
+        count = 0
+        ui.progress(_('comparing'), count, total)
         for abs in repo[node].walk(m):
+            count += 1
+            ui.progress(_('comparing'), count, total)
             if abs not in names:
                 names[abs] = m.rel(abs), m.exact(abs)
+        ui.progress(_('comparing'), None)

         m = cmdutil.matchfiles(repo, names)
+        ui.progress(_('scanning'), 0)
         changes = repo.status(match=m)[:4]
+        ui.progress(_('scanning'), None)
         modified, added, removed, deleted = map(set, changes)

         # if f is a rename, also revert the source
@@ -3129,6 +3142,8 @@ def revert(ui, repo, *pats, **opts):
             (deleted, revert, remove, False, False),
             )

+        count = 0
+        total = len(names.items())
         for abs, (rel, exact) in sorted(names.items()):
             mfentry = mf.get(abs)
             target = repo.wjoin(abs)
@@ -3146,6 +3161,9 @@ def revert(ui, repo, *pats, **opts):
                     if not isinstance(msg, basestring):
                         msg = msg(abs)
                     ui.status(msg % rel)
+
+            count += 1
+            ui.progress(_('classifying'), count, total=total)
             for table, hitlist, misslist, backuphit, backupmiss in disptable:
                 if abs not in table:
                     continue
@@ -3180,6 +3198,7 @@ def revert(ui, repo, *pats, **opts):
                             handle(revert, False)
                     else:
                         handle(remove, False)
+        ui.progress(_('classifying'), None)

         if not opts.get('dry_run'):
             def checkout(f):
@@ -3187,7 +3206,11 @@ def revert(ui, repo, *pats, **opts):
                 repo.wwrite(f, fc.data(), fc.flags())

             audit_path = util.path_auditor(repo.root)
+            count = 0
+            total = len(remove[0])
             for f in remove[0]:
+                count += 1
+                ui.progress(_('removing'), count, total=total, unit=_('files'))
                 if repo.dirstate[f] == 'a':
                     repo.dirstate.forget(f)
                     continue
@@ -3197,6 +3220,7 @@ def revert(ui, repo, *pats, **opts):
                 except OSError:
                     pass
                 repo.dirstate.remove(f)
+            ui.progress(_('removing'), None)

             normal = None
             if node == parent:
@@ -3207,21 +3231,37 @@ def revert(ui, repo, *pats, **opts):
                     normal = repo.dirstate.normallookup
                 else:
                     normal = repo.dirstate.normal
+            count = 0
+            total = len(revert[0])
             for f in revert[0]:
+                count += 1
+                ui.progress(_('reverting'), count, total=total,
unit=_('files'))
                 checkout(f)
                 if normal:
                     normal(f)
-
+            ui.progress(_('reverting'), None)
+
+            count = 0
+            total = len(add[0])
             for f in add[0]:
+                count += 1
+                ui.progress(_('adding'), count, total=total, unit=_('files'))
                 checkout(f)
                 repo.dirstate.add(f)
+            ui.progress(_('adding'), None)

             normal = repo.dirstate.normallookup
             if node == parent and p2 == nullid:
                 normal = repo.dirstate.normal
+
+            count = 0
+            total = len(undelete[0])
             for f in undelete[0]:
+                count += 1
+                ui.progress(_('undeleting'), count, total=total,
unit=_('files'))
                 checkout(f)
                 normal(f)
+            ui.progress(_('undeleting'), None)

     finally:
         wlock.release()


More information about the Mercurial-devel mailing list