Patchwork D3807: convert: use progress helper

login
register
mail settings
Submitter phabricator
Date June 19, 2018, 12:45 a.m.
Message ID <differential-rev-PHID-DREV-5tfkcphfempwakop3c7e-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/32315/
State Superseded
Headers show

Comments

phabricator - June 19, 2018, 12:45 a.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3807

AFFECTED FILES
  hgext/convert/convcmd.py
  hgext/convert/subversion.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - June 19, 2018, 11:05 a.m.
pulkit accepted this revision.
pulkit added inline comments.

INLINE COMMENTS

> convcmd.py:524
>                  self.ui.note(_("source: %s\n") % recode(c))
> -                self.ui.progress(_('converting'), i, unit=_('revisions'),
> -                                 total=len(t))
> +                progress.update(i)
>                  self.copy(c)

This can be progress.increment().

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3807

To: martinvonz, #hg-reviewers, pulkit
Cc: pulkit, mercurial-devel

Patch

diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -750,9 +750,10 @@ 
             self.module = new_module
             self.reparent(self.module)
 
+        progress = self.ui.makeprogress(_('scanning paths'), unit=_('paths'),
+                                        total=len(paths))
         for i, (path, ent) in enumerate(paths):
-            self.ui.progress(_('scanning paths'), i, item=path,
-                             total=len(paths), unit=_('paths'))
+            progress.update(i, item=path)
             entrypath = self.getrelpath(path)
 
             kind = self._checkpath(entrypath, revnum)
@@ -838,7 +839,7 @@ 
                     copytopath = self.getrelpath(copytopath)
                     copies[self.recode(copytopath)] = self.recode(childpath)
 
-        self.ui.progress(_('scanning paths'), None)
+        progress.complete()
         changed.update(removed)
         return (list(changed), removed, copies)
 
diff --git a/hgext/convert/convcmd.py b/hgext/convert/convcmd.py
--- a/hgext/convert/convcmd.py
+++ b/hgext/convert/convcmd.py
@@ -143,13 +143,11 @@ 
     def __init__(self, ui, source, filecount):
         self.ui = ui
         self.source = source
-        self.filecount = filecount
-        self.retrieved = 0
+        self.progress = ui.makeprogress(_('getting files'), unit=_('files'),
+                                        total=filecount)
 
     def getfile(self, file, rev):
-        self.retrieved += 1
-        self.ui.progress(_('getting files'), self.retrieved,
-                         item=file, total=self.filecount, unit=_('files'))
+        self.progress.increment(item=file)
         return self.source.getfile(file, rev)
 
     def targetfilebelongstosource(self, targetfilename):
@@ -159,7 +157,7 @@ 
         return self.source.lookuprev(rev)
 
     def close(self):
-        self.ui.progress(_('getting files'), None)
+        self.progress.complete()
 
 class converter(object):
     def __init__(self, ui, source, dest, revmapfile, opts):
@@ -238,6 +236,8 @@ 
         known = set()
         parents = {}
         numcommits = self.source.numcommits()
+        progress = self.ui.makeprogress(_('scanning'), unit=_('revisions'),
+                                        total=numcommits)
         while visit:
             n = visit.pop(0)
             if n in known:
@@ -247,14 +247,13 @@ 
                 if m == SKIPREV or self.dest.hascommitfrommap(m):
                     continue
             known.add(n)
-            self.ui.progress(_('scanning'), len(known), unit=_('revisions'),
-                             total=numcommits)
+            progress.update(len(known))
             commit = self.cachecommit(n)
             parents[n] = []
             for p in commit.parents:
                 parents[n].append(p)
                 visit.append(p)
-        self.ui.progress(_('scanning'), None)
+        progress.complete()
 
         return parents
 
@@ -510,6 +509,8 @@ 
             c = None
 
             self.ui.status(_("converting...\n"))
+            progress = self.ui.makeprogress(_('converting'),
+                                            unit=_('revisions'), total=len(t))
             for i, c in enumerate(t):
                 num -= 1
                 desc = self.commitcache[c].desc
@@ -520,10 +521,9 @@ 
                 # uses is 'utf-8'
                 self.ui.status("%d %s\n" % (num, recode(desc)))
                 self.ui.note(_("source: %s\n") % recode(c))
-                self.ui.progress(_('converting'), i, unit=_('revisions'),
-                                 total=len(t))
+                progress.update(i)
                 self.copy(c)
-            self.ui.progress(_('converting'), None)
+            progress.complete()
 
             if not self.ui.configbool('convert', 'skiptags'):
                 tags = self.source.gettags()