Patchwork [4,of,4,V2] lfs: restore the local blob store after a repo upgrade

login
register
mail settings
Submitter Matt Harbison
Date Dec. 10, 2017, 1:57 a.m.
Message ID <d435feccadfa39d45fef.1512871031@Envy>
Download mbox | patch
Permalink /patch/26158/
State Accepted
Headers show

Comments

Matt Harbison - Dec. 10, 2017, 1:57 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1512710310 18000
#      Fri Dec 08 00:18:30 2017 -0500
# Node ID d435feccadfa39d45fefc162ebda0efac2e2ba7c
# Parent  f060232e47d7e6f480c102e091e444d5f79de889
lfs: restore the local blob store after a repo upgrade

This also ends up testing the local extension wrapping for dstrepo during
upgrade, which was fixed in 06987c6971be.
Augie Fackler - Dec. 10, 2017, 2:36 a.m.
On Sat, Dec 09, 2017 at 08:57:11PM -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1512710310 18000
> #      Fri Dec 08 00:18:30 2017 -0500
> # Node ID d435feccadfa39d45fefc162ebda0efac2e2ba7c
> # Parent  f060232e47d7e6f480c102e091e444d5f79de889
> lfs: restore the local blob store after a repo upgrade

queued, thanks
Yuya Nishihara - Dec. 12, 2017, 2:23 p.m.
On Sat, 09 Dec 2017 20:57:11 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1512710310 18000
> #      Fri Dec 08 00:18:30 2017 -0500
> # Node ID d435feccadfa39d45fefc162ebda0efac2e2ba7c
> # Parent  f060232e47d7e6f480c102e091e444d5f79de889
> lfs: restore the local blob store after a repo upgrade

> +def upgradefinishdatamigration(orig, ui, srcrepo, dstrepo, requirements):
> +    orig(ui, srcrepo, dstrepo, requirements)
> +
> +    srclfsvfs = srcrepo.svfs.lfslocalblobstore.vfs
> +    dstlfsvfs = dstrepo.svfs.lfslocalblobstore.vfs
> +
> +    for dirpath, dirs, files in srclfsvfs.walk():
> +        for oid in files:
> +            srcrepo.ui.write(_('copying lfs blob %s\n') % oid)
               ^^^^^^^^^^
Nit: perhaps it's better to use 'ui' passed by argument, not srcrepo's.

Patch

diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py
--- a/hgext/lfs/__init__.py
+++ b/hgext/lfs/__init__.py
@@ -140,6 +140,9 @@ 
 
     wrapfunction(scmutil, 'wrapconvertsink', wrapper.convertsink)
 
+    wrapfunction(upgrade, '_finishdatamigration',
+                 wrapper.upgradefinishdatamigration)
+
     wrapfunction(upgrade, 'preservedrequirements',
                  wrapper.upgraderequirements)
 
diff --git a/hgext/lfs/wrapper.py b/hgext/lfs/wrapper.py
--- a/hgext/lfs/wrapper.py
+++ b/hgext/lfs/wrapper.py
@@ -19,6 +19,8 @@ 
     util,
 )
 
+from ..largefiles import lfutil
+
 from . import (
     blobstore,
     pointer,
@@ -303,6 +305,17 @@ 
     remoteblob = repo.svfs.lfsremoteblobstore
     remoteblob.writebatch(pointers, repo.svfs.lfslocalblobstore)
 
+def upgradefinishdatamigration(orig, ui, srcrepo, dstrepo, requirements):
+    orig(ui, srcrepo, dstrepo, requirements)
+
+    srclfsvfs = srcrepo.svfs.lfslocalblobstore.vfs
+    dstlfsvfs = dstrepo.svfs.lfslocalblobstore.vfs
+
+    for dirpath, dirs, files in srclfsvfs.walk():
+        for oid in files:
+            srcrepo.ui.write(_('copying lfs blob %s\n') % oid)
+            lfutil.link(srclfsvfs.join(oid), dstlfsvfs.join(oid))
+
 def upgraderequirements(orig, repo):
     reqs = orig(repo)
     if 'lfs' in repo.requirements:
diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -548,6 +548,7 @@ 
   finished migrating 2 changelog revisions; change in size: 0 bytes
   finished migrating 6 total revisions; total change in store size: 0 bytes
   copying phaseroots
+  copying lfs blob d0beab232adff5ba365880366ad30b1edb85c4c5372442b5d2fe27adc96d653f
   data fully migrated to temporary repository
   marking source repository as being upgraded; clients will be unable to read from repository
   starting in-place swap of repository data
@@ -561,11 +562,8 @@ 
 
   $ grep lfs .hg/requires
   lfs
-TODO: restore the local lfs store.  For now, objects are copied from the user
-cache as needed.
   $ find .hg/store/lfs -type f
-  find: `.hg/store/lfs': $ENOENT$
-  [1]
+  .hg/store/lfs/objects/d0/beab232adff5ba365880366ad30b1edb85c4c5372442b5d2fe27adc96d653f
   $ hg verify
   checking changesets
   checking manifests