[PATCH 2 of 4] lfs: preserve the 'lfs' requirement across repository upgrades

Matt Harbison mharbison72 at gmail.com
Fri Dec 8 00:47:04 EST 2017


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1512704191 18000
#      Thu Dec 07 22:36:31 2017 -0500
# Node ID bde45ffbd15011a829c4bf4b29c864ed864ccab6
# Parent  e82fc66d706633cdf7344f682dcc223d16e01c72
lfs: preserve the 'lfs' requirement across repository upgrades

This is the same treatment that largefiles recently got, but uncovers an issue
where the local lfs store is lost.

diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py
--- a/hgext/lfs/__init__.py
+++ b/hgext/lfs/__init__.py
@@ -46,6 +46,7 @@
     registrar,
     revlog,
     scmutil,
+    upgrade,
     vfs as vfsmod,
 )
 
@@ -161,6 +162,9 @@
 
     wrapfunction(hg, 'clone', wrapper.hgclone)
     wrapfunction(hg, 'postshare', wrapper.hgpostshare)
+    wrapfunction(upgrade, 'preservedrequirements', wrapper.upgraderequirements)
+    wrapfunction(upgrade, 'supporteddestrequirements',
+                 wrapper.upgraderequirements)
 
     # Make bundle choose changegroup3 instead of changegroup2. This affects
     # "hg bundle" command. Note: it does not cover all bundle formats like
diff --git a/hgext/lfs/wrapper.py b/hgext/lfs/wrapper.py
--- a/hgext/lfs/wrapper.py
+++ b/hgext/lfs/wrapper.py
@@ -233,6 +233,12 @@
         with destrepo.vfs('hgrc', 'a', text=True) as fp:
             fp.write('\n[extensions]\nlfs=\n')
 
+def upgraderequirements(orig, repo):
+    reqs = orig(repo)
+    if 'lfs' in repo.requirements:
+        reqs.add('lfs')
+    return reqs
+
 def _canskipupload(repo):
     # if remotestore is a null store, upload is a no-op and can be skipped
     return isinstance(repo.svfs.lfsremoteblobstore, blobstore._nullremote)
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
@@ -411,3 +411,67 @@
   largefiles
   revlogv1
   store
+
+  $ cat << EOF >> .hg/hgrc
+  > [extensions]
+  > lfs =
+  > [lfs]
+  > threshold = 10
+  > EOF
+  $ echo '123456789012345' > lfs.bin
+  $ hg ci -Am 'lfs.bin'
+  adding lfs.bin
+  $ grep lfs .hg/requires
+  lfs
+  $ find .hg/store/lfs -type f
+  .hg/store/lfs/objects/d0/beab232adff5ba365880366ad30b1edb85c4c5372442b5d2fe27adc96d653f
+
+  $ hg debugupgraderepo --run
+  upgrade will perform the following actions:
+  
+  requirements
+     preserved: dotencode, fncache, generaldelta, largefiles, lfs, revlogv1, store
+  
+  beginning upgrade...
+  repository locked and read-only
+  creating temporary repository to stage migrated data: $TESTTMP/largefilesrepo/.hg/upgrade.* (glob)
+  (it is safe to interrupt this process any time before data migration completes)
+  migrating 6 total revisions (2 in filelogs, 2 in manifests, 2 in changelog)
+  migrating 417 bytes in store; 467 bytes tracked data
+  migrating 2 filelogs containing 2 revisions (168 bytes in store; 182 bytes tracked data)
+  finished migrating 2 filelog revisions across 2 filelogs; change in size: 0 bytes
+  migrating 1 manifests containing 2 revisions (113 bytes in store; 151 bytes tracked data)
+  finished migrating 2 manifest revisions across 1 manifests; change in size: 0 bytes
+  migrating changelog containing 2 revisions (136 bytes in store; 134 bytes tracked data)
+  finished migrating 2 changelog revisions; change in size: 0 bytes
+  finished migrating 6 total revisions; total change in store size: 0 bytes
+  copying phaseroots
+  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
+  replaced files will be backed up at $TESTTMP/largefilesrepo/.hg/upgradebackup.* (glob)
+  replacing store...
+  store replacement complete; repository was inconsistent for *s (glob)
+  finalizing requirements file and making repository readable again
+  removing temporary repository $TESTTMP/largefilesrepo/.hg/upgrade.* (glob)
+  copy of old repository backed up at $TESTTMP/largefilesrepo/.hg/upgradebackup.* (glob)
+  the old repository will not be deleted; remove it to free up disk space once the upgraded repository is verified
+
+  $ 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 verify
+  checking changesets
+  checking manifests
+  crosschecking files in changesets and manifests
+  checking files
+  2 files, 2 changesets, 2 total revisions
+  $ hg debugdata lfs.bin 0
+  version https://git-lfs.github.com/spec/v1
+  oid sha256:d0beab232adff5ba365880366ad30b1edb85c4c5372442b5d2fe27adc96d653f
+  size 16
+  x-is-binary 0


More information about the Mercurial-devel mailing list