Patchwork [1,of,4] hg: ensure the progress bar is completed when copying the store

login
register
mail settings
Submitter Matt Harbison
Date Sept. 1, 2018, 6:05 a.m.
Message ID <bcd44b97559a0150b988.1535781930@Envy>
Download mbox | patch
Permalink /patch/34229/
State Accepted
Headers show

Comments

Matt Harbison - Sept. 1, 2018, 6:05 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1535214404 14400
#      Sat Aug 25 12:26:44 2018 -0400
# Node ID bcd44b97559a0150b988f812ffc28be1f7f9d452
# Parent  a7e22dd31f540916e79fbf23ff9f1c5baf380c53
hg: ensure the progress bar is completed when copying the store

This is just a block indent under the context manager.
Augie Fackler - Sept. 1, 2018, 3 p.m.
queued, thanks

> On Sep 1, 2018, at 2:05 AM, Matt Harbison <mharbison72@gmail.com> wrote:
> 
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1535214404 14400
> #      Sat Aug 25 12:26:44 2018 -0400
> # Node ID bcd44b97559a0150b988f812ffc28be1f7f9d452
> # Parent  a7e22dd31f540916e79fbf23ff9f1c5baf380c53
> hg: ensure the progress bar is completed when copying the store
> 
> This is just a block indent under the context manager.
> 
> diff --git a/mercurial/hg.py b/mercurial/hg.py
> --- a/mercurial/hg.py
> +++ b/mercurial/hg.py
> @@ -381,31 +381,30 @@ def copystore(ui, srcrepo, destpath):
>     try:
>         hardlink = None
>         topic = _('linking') if hardlink else _('copying')
> -        progress = ui.makeprogress(topic)
> -        num = 0
> -        srcpublishing = srcrepo.publishing()
> -        srcvfs = vfsmod.vfs(srcrepo.sharedpath)
> -        dstvfs = vfsmod.vfs(destpath)
> -        for f in srcrepo.store.copylist():
> -            if srcpublishing and f.endswith('phaseroots'):
> -                continue
> -            dstbase = os.path.dirname(f)
> -            if dstbase and not dstvfs.exists(dstbase):
> -                dstvfs.mkdir(dstbase)
> -            if srcvfs.exists(f):
> -                if f.endswith('data'):
> -                    # 'dstbase' may be empty (e.g. revlog format 0)
> -                    lockfile = os.path.join(dstbase, "lock")
> -                    # lock to avoid premature writing to the target
> -                    destlock = lock.lock(dstvfs, lockfile)
> -                hardlink, n = util.copyfiles(srcvfs.join(f), dstvfs.join(f),
> -                                             hardlink, progress)
> -                num += n
> -        if hardlink:
> -            ui.debug("linked %d files\n" % num)
> -        else:
> -            ui.debug("copied %d files\n" % num)
> -        progress.complete()
> +        with ui.makeprogress(topic) as progress:
> +            num = 0
> +            srcpublishing = srcrepo.publishing()
> +            srcvfs = vfsmod.vfs(srcrepo.sharedpath)
> +            dstvfs = vfsmod.vfs(destpath)
> +            for f in srcrepo.store.copylist():
> +                if srcpublishing and f.endswith('phaseroots'):
> +                    continue
> +                dstbase = os.path.dirname(f)
> +                if dstbase and not dstvfs.exists(dstbase):
> +                    dstvfs.mkdir(dstbase)
> +                if srcvfs.exists(f):
> +                    if f.endswith('data'):
> +                        # 'dstbase' may be empty (e.g. revlog format 0)
> +                        lockfile = os.path.join(dstbase, "lock")
> +                        # lock to avoid premature writing to the target
> +                        destlock = lock.lock(dstvfs, lockfile)
> +                    hardlink, n = util.copyfiles(srcvfs.join(f), dstvfs.join(f),
> +                                                 hardlink, progress)
> +                    num += n
> +            if hardlink:
> +                ui.debug("linked %d files\n" % num)
> +            else:
> +                ui.debug("copied %d files\n" % num)
>         return destlock
>     except: # re-raises
>         release(destlock)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -381,31 +381,30 @@  def copystore(ui, srcrepo, destpath):
     try:
         hardlink = None
         topic = _('linking') if hardlink else _('copying')
-        progress = ui.makeprogress(topic)
-        num = 0
-        srcpublishing = srcrepo.publishing()
-        srcvfs = vfsmod.vfs(srcrepo.sharedpath)
-        dstvfs = vfsmod.vfs(destpath)
-        for f in srcrepo.store.copylist():
-            if srcpublishing and f.endswith('phaseroots'):
-                continue
-            dstbase = os.path.dirname(f)
-            if dstbase and not dstvfs.exists(dstbase):
-                dstvfs.mkdir(dstbase)
-            if srcvfs.exists(f):
-                if f.endswith('data'):
-                    # 'dstbase' may be empty (e.g. revlog format 0)
-                    lockfile = os.path.join(dstbase, "lock")
-                    # lock to avoid premature writing to the target
-                    destlock = lock.lock(dstvfs, lockfile)
-                hardlink, n = util.copyfiles(srcvfs.join(f), dstvfs.join(f),
-                                             hardlink, progress)
-                num += n
-        if hardlink:
-            ui.debug("linked %d files\n" % num)
-        else:
-            ui.debug("copied %d files\n" % num)
-        progress.complete()
+        with ui.makeprogress(topic) as progress:
+            num = 0
+            srcpublishing = srcrepo.publishing()
+            srcvfs = vfsmod.vfs(srcrepo.sharedpath)
+            dstvfs = vfsmod.vfs(destpath)
+            for f in srcrepo.store.copylist():
+                if srcpublishing and f.endswith('phaseroots'):
+                    continue
+                dstbase = os.path.dirname(f)
+                if dstbase and not dstvfs.exists(dstbase):
+                    dstvfs.mkdir(dstbase)
+                if srcvfs.exists(f):
+                    if f.endswith('data'):
+                        # 'dstbase' may be empty (e.g. revlog format 0)
+                        lockfile = os.path.join(dstbase, "lock")
+                        # lock to avoid premature writing to the target
+                        destlock = lock.lock(dstvfs, lockfile)
+                    hardlink, n = util.copyfiles(srcvfs.join(f), dstvfs.join(f),
+                                                 hardlink, progress)
+                    num += n
+            if hardlink:
+                ui.debug("linked %d files\n" % num)
+            else:
+                ui.debug("copied %d files\n" % num)
         return destlock
     except: # re-raises
         release(destlock)