mirror of
https://github.com/facebook/sapling.git
synced 2025-01-07 14:10:42 +03:00
snapshot: add debug command to checkout on snapshot manifest
Summary: It would really help to be able to checkout the manifests, restoring all the data from them. Deleting the missing files, creating the unknown files, adding mergestate info to svfs (not available yet :) ). Reviewed By: mitrandir77 Differential Revision: D16668312 fbshipit-source-id: 62af8a1fb11541c162f7b5ceb8d6d058cad9a319
This commit is contained in:
parent
6a6c0fea7a
commit
6b7127c966
@ -19,7 +19,7 @@ TODO(alexeyqu): finish docs
|
||||
import hashlib
|
||||
from collections import defaultdict
|
||||
|
||||
from edenscm.mercurial import error, extensions, json, registrar
|
||||
from edenscm.mercurial import cmdutil, error, extensions, json, registrar, scmutil
|
||||
from edenscm.mercurial.i18n import _
|
||||
|
||||
|
||||
@ -54,7 +54,7 @@ def debugcreatesnapshotmanifest(ui, repo, *args, **opts):
|
||||
Loads untracked files and the created manifest into local lfsstore.
|
||||
Outputs the oid of the created manifest file.
|
||||
|
||||
This is a debug command => it lacks security and is unsuitable for prod.
|
||||
Be careful, snapshot manifest internal structure may change.
|
||||
"""
|
||||
if lfs is None:
|
||||
raise error.Abort(_("lfs is not initialised"))
|
||||
@ -87,7 +87,7 @@ def debuguploadsnapshotmanifest(ui, repo, *args, **opts):
|
||||
Uploads manifest and all related blobs to remote lfs.
|
||||
Takes in an oid of the desired manifest in the local lfs.
|
||||
|
||||
This is a debug command => it lacks security and is unsuitable for prod.
|
||||
This command does not validate contents of the snapshot manifest.
|
||||
"""
|
||||
if lfs is None:
|
||||
raise error.Abort(_("lfs not initialised"))
|
||||
@ -113,3 +113,39 @@ def debuguploadsnapshotmanifest(ui, repo, *args, **opts):
|
||||
pointers.append(lfs.pointer.gitlfspointer(oid=oid, size=pointer["size"]))
|
||||
lfs.wrapper.uploadblobs(repo, pointers)
|
||||
ui.status(_("upload complete\n"))
|
||||
|
||||
|
||||
@command("debugcheckoutsnapshot", [], _("OID"), inferrepo=True)
|
||||
def debugcheckoutsnapshot(ui, repo, *args, **opts):
|
||||
"""
|
||||
Checks out the working copy to the snapshot state, given its manifest oid.
|
||||
Downloads the snapshot manifest from remote lfs if needed.
|
||||
Takes in an oid of the manifest.
|
||||
|
||||
This command does not validate contents of the snapshot manifest.
|
||||
"""
|
||||
|
||||
def checkloadblobbyoid(repo, oid):
|
||||
store = repo.svfs.lfslocalblobstore
|
||||
if not store.has(oid):
|
||||
p = lfs.pointer.gitlfspointer(oid=oid)
|
||||
repo.svfs.lfsremoteblobstore.readbatch([p], store)
|
||||
return store.read(oid)
|
||||
|
||||
if lfs is None:
|
||||
raise error.Abort(_("lfs not initialised"))
|
||||
if not args or len(args) != 1:
|
||||
raise error.Abort(_("you must specify a manifest oid"))
|
||||
manifestoid = args[0]
|
||||
# TODO(alexeyqu): special manifest class
|
||||
snapshotmanifest = json.loads(checkloadblobbyoid(repo, manifestoid))
|
||||
# deleting files that should be missing
|
||||
ui.note(_("will delete %s") % ",".join(snapshotmanifest["deleted"]))
|
||||
m = scmutil.match(repo[None], snapshotmanifest["deleted"])
|
||||
cmdutil.remove(ui, repo, m, "", after=False, force=False)
|
||||
# populating the untracked files
|
||||
for filename, pointer in snapshotmanifest["unknown"].items():
|
||||
ui.note(_("will add %s") % filename)
|
||||
data = checkloadblobbyoid(repo, pointer["oid"])
|
||||
repo.wvfs.write(filename, data)
|
||||
ui.status(_("snapshot checkout complete\n"))
|
||||
|
@ -1,6 +1,7 @@
|
||||
# Initial setup
|
||||
$ setconfig extensions.lfs=
|
||||
$ setconfig extensions.snapshot=
|
||||
$ setconfig extensions.treemanifest=!
|
||||
|
||||
# Prepare server and client repos.
|
||||
$ hg init server
|
||||
@ -10,6 +11,13 @@
|
||||
# Add a file to the store
|
||||
$ echo "foo" > existingfile
|
||||
$ hg commit -Aqm "add some file"
|
||||
$ hg push
|
||||
pushing to $TESTTMP/server
|
||||
searching for changes
|
||||
adding changesets
|
||||
adding manifests
|
||||
adding file changes
|
||||
added 1 changesets with 1 changes to 1 files
|
||||
|
||||
# No need to create snapshot now
|
||||
$ hg debugcreatesnapshotmanifest
|
||||
@ -64,3 +72,21 @@
|
||||
|
||||
$ cat $TESTTMP/lfsremote/7d/865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730
|
||||
bar
|
||||
|
||||
# Checkout the manifest
|
||||
$ cd ../
|
||||
$ hg clone -q server client2
|
||||
$ cd client2
|
||||
$ hg update
|
||||
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
|
||||
$ ls
|
||||
existingfile
|
||||
|
||||
$ hg debugcheckoutsnapshot "$OID"
|
||||
snapshot checkout complete
|
||||
|
||||
$ ls
|
||||
untrackedfile
|
||||
|
||||
$ cat untrackedfile
|
||||
bar
|
||||
|
Loading…
Reference in New Issue
Block a user