snapshot: add version info to snapshot metadata

Reviewed By: markbt

Differential Revision: D16941087

fbshipit-source-id: 10d1857060dafcda2005a14d731758a2221ad7fd
This commit is contained in:
Aleksei Kulikov 2019-08-22 09:29:42 -07:00 committed by Facebook Github Bot
parent adbe2b2b32
commit 216bd69c29
3 changed files with 25 additions and 21 deletions

View File

@ -92,6 +92,8 @@ class snapshotmetadata(object):
Main class that contains snapshot metadata representation.
"""
VERSION = "1"
def __init__(self, repo, oid=None):
self.repo = repo
self.oid = oid
@ -104,25 +106,27 @@ class snapshotmetadata(object):
return not (self.deleted or self.unknown)
def serialize(self):
metadata = defaultdict(dict)
metadata["deleted"] = {d.path: d.serialize() for d in self.deleted}
metadata["unknown"] = {u.path: u.serialize() for u in self.unknown}
metadata["localvfsfiles"] = {f.path: f.serialize() for f in self.localvfsfiles}
files = {}
files["deleted"] = {d.path: d.serialize() for d in self.deleted}
files["unknown"] = {u.path: u.serialize() for u in self.unknown}
files["localvfsfiles"] = {f.path: f.serialize() for f in self.localvfsfiles}
metadata = {"files": files, "version": snapshotmetadata.VERSION}
return json.dumps(metadata)
def deserialize(self, json_string):
try:
metadata = json.loads(json_string)
files = metadata["files"]
self.deleted = [
filelfswrapper(path) for path in sorted(metadata["deleted"].keys())
filelfswrapper(path) for path in sorted(files["deleted"].keys())
]
self.unknown = [
filelfswrapper.deserialize(path, data)
for path, data in sorted(metadata["unknown"].items())
for path, data in sorted(files["unknown"].items())
]
self.localvfsfiles = [
filelfswrapper.deserialize(path, data)
for path, data in sorted(metadata["localvfsfiles"].items())
for path, data in sorted(files["localvfsfiles"].items())
]
except ValueError:
raise error.Abort(_("invalid metadata json: %s\n") % json_string)

View File

@ -186,7 +186,7 @@
# Create the snapshot
$ OID="$(hg debugsnapshot | cut -f2 -d' ')"
$ echo "$OID"
34c81e40f10e2df58967bde74f60a35080812037
aaa7692160b6c5c0e4c13787d9343cf89fc2311a
# hg status/diff are unchanged
$ test "$BEFORESTATUS" = "$(hg status --verbose)"
@ -195,9 +195,9 @@
# Check the metadata id and its contents
$ MANIFESTOID="$(hg log --hidden -r \"$OID\" -T '{extras % \"{extra}\n\"}' | grep snapshotmetadataid | cut -d'=' -f2)"
$ echo "$MANIFESTOID"
94d0daf8fadba1a239eca4ddb5cc1a71728097928543dfb02b8be399ae6fcb56
6b32f5f5726caf1b66d313cdd847ad5b4266f14a3480b2acf64a0a173ac14548
$ cat .hg/store/lfs/objects/"${MANIFESTOID:0:2}"/"${MANIFESTOID:2}"
{"deleted": {"foofile": null}, "localvfsfiles": {"merge/fc4ffdcb8ed23cecd44a0e11d23af83b445179b4": {"oid": "0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813f", "size": "2"}, "merge/state": {"oid": "fdfea51dfeeae94bd846473c7bef891823af465d33f48e92ed2556bde6b346cb", "size": "166"}, "merge/state2": {"oid": "0e421047ebcf7d0cada48ddd801304725de33da3c4048ccb258041946cd0e81d", "size": "361"}}, "unknown": {"mergefile.orig": {"oid": "0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813f", "size": "2"}, "untrackedfile": {"oid": "b05b74c474c1706953bed876a19f146b371ddf51a36474fe0c094922385cc479", "size": "5"}}} (no-eol)
{"files": {"deleted": {"foofile": null}, "localvfsfiles": {"merge/fc4ffdcb8ed23cecd44a0e11d23af83b445179b4": {"oid": "0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813f", "size": "2"}, "merge/state": {"oid": "fdfea51dfeeae94bd846473c7bef891823af465d33f48e92ed2556bde6b346cb", "size": "166"}, "merge/state2": {"oid": "0e421047ebcf7d0cada48ddd801304725de33da3c4048ccb258041946cd0e81d", "size": "361"}}, "unknown": {"mergefile.orig": {"oid": "0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813f", "size": "2"}, "untrackedfile": {"oid": "b05b74c474c1706953bed876a19f146b371ddf51a36474fe0c094922385cc479", "size": "5"}}}, "version": "1"} (no-eol)
# Move back to BASEREV
$ hg update -q --clean "$BASEREV" && rm bazfile
@ -225,7 +225,7 @@
[255]
# Check out on the snapshot -- positive tests
$ hg debugcheckoutsnapshot "$OID"
will checkout on 34c81e40f10e2df58967bde74f60a35080812037
will checkout on aaa7692160b6c5c0e4c13787d9343cf89fc2311a
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
checkout complete
$ test "$BEFORESTATUS" = "$(hg status --verbose)"
@ -239,13 +239,13 @@
.hg/merge/state
.hg/merge/state2
$ hg debugsnapshot --clean
snapshot 34c81e40f10e2df58967bde74f60a35080812037 created
snapshot aaa7692160b6c5c0e4c13787d9343cf89fc2311a created
3 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg status --verbose
$ test -d .hg/merge
[1]
$ hg debugcheckoutsnapshot "$OID"
will checkout on 34c81e40f10e2df58967bde74f60a35080812037
will checkout on aaa7692160b6c5c0e4c13787d9343cf89fc2311a
checkout complete
@ -260,7 +260,7 @@
[255]
$ hg debugcheckoutsnapshot --force "$OID"
will checkout on 34c81e40f10e2df58967bde74f60a35080812037
will checkout on aaa7692160b6c5c0e4c13787d9343cf89fc2311a
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
checkout complete

View File

@ -30,19 +30,19 @@
$ rm existingfile
$ OID="$(hg debugcreatesnapshotmetadata | cut -f3 -d' ')"
$ echo "$OID"
70750cb86e5458ef4c1f6630694943a27bde9f67e838701dc660d92360b290be
f62f9175588ac550bc215b56b441de94f6b3c859023f971453057342614db332
# Check that the blobstore is populated
$ find .hg/store/lfs/objects | sort
.hg/store/lfs/objects
.hg/store/lfs/objects/70
.hg/store/lfs/objects/70/750cb86e5458ef4c1f6630694943a27bde9f67e838701dc660d92360b290be
.hg/store/lfs/objects/7d
.hg/store/lfs/objects/7d/865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730
.hg/store/lfs/objects/f6
.hg/store/lfs/objects/f6/2f9175588ac550bc215b56b441de94f6b3c859023f971453057342614db332
# Check the contents of the metadata file
$ cat .hg/store/lfs/objects/"${OID:0:2}"/"${OID:2}"
{"deleted": {"existingfile": null}, "localvfsfiles": {}, "unknown": {"untrackedfile": {"oid": "7d865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730", "size": "4"}}} (no-eol)
{"files": {"deleted": {"existingfile": null}, "localvfsfiles": {}, "unknown": {"untrackedfile": {"oid": "7d865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730", "size": "4"}}}, "version": "1"} (no-eol)
# Check that the untracked file is stored in lfs
$ cat .hg/store/lfs/objects/7d/865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730
@ -65,13 +65,13 @@
# Check the remote storage
$ find $TESTTMP/lfsremote | sort
$TESTTMP/lfsremote
$TESTTMP/lfsremote/70
$TESTTMP/lfsremote/70/750cb86e5458ef4c1f6630694943a27bde9f67e838701dc660d92360b290be
$TESTTMP/lfsremote/7d
$TESTTMP/lfsremote/7d/865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730
$TESTTMP/lfsremote/f6
$TESTTMP/lfsremote/f6/2f9175588ac550bc215b56b441de94f6b3c859023f971453057342614db332
$ cat $TESTTMP/lfsremote/"${OID:0:2}"/"${OID:2}"
{"deleted": {"existingfile": null}, "localvfsfiles": {}, "unknown": {"untrackedfile": {"oid": "7d865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730", "size": "4"}}} (no-eol)
{"files": {"deleted": {"existingfile": null}, "localvfsfiles": {}, "unknown": {"untrackedfile": {"oid": "7d865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730", "size": "4"}}}, "version": "1"} (no-eol)
$ cat $TESTTMP/lfsremote/7d/865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730
bar