mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 01:07:15 +03:00
snapshot: keep a list of snapshots in .hg/store/snapshotlist
Reviewed By: markbt Differential Revision: D17226709 fbshipit-source-id: fefa31227f77295793ccaa3448f4488274f70848
This commit is contained in:
parent
0f9b49b65e
commit
b7ee506bfa
@ -20,6 +20,7 @@ from edenscm.mercurial import (
|
||||
from edenscm.mercurial.i18n import _
|
||||
|
||||
from .metadata import snapshotmetadata
|
||||
from .snapshotlist import snapshotlist
|
||||
|
||||
|
||||
cmdtable = {}
|
||||
@ -81,6 +82,8 @@ def snapshotcreate(ui, repo, *args, **opts):
|
||||
if not node:
|
||||
ui.status(_("nothing changed\n"))
|
||||
return
|
||||
with repo.transaction("update-snapshot-list") as tr:
|
||||
snapshotlist(repo).add([node], tr)
|
||||
ui.status(_("snapshot %s created\n") % (repo[node].hex()))
|
||||
if visibility.enabled(repo):
|
||||
visibility.remove(repo, [node])
|
||||
|
49
edenscm/hgext/snapshot/snapshotlist.py
Normal file
49
edenscm/hgext/snapshot/snapshotlist.py
Normal file
@ -0,0 +1,49 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# snapshotlist.py
|
||||
#
|
||||
# Copyright 2019 Facebook, Inc.
|
||||
#
|
||||
# This software may be used and distributed according to the terms of the
|
||||
# GNU General Public License version 2 or any later version.
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import errno
|
||||
|
||||
from edenscm.mercurial import error, node
|
||||
|
||||
|
||||
# Supported file format version.
|
||||
# Version 1 is:
|
||||
# * A single line containing "v1"
|
||||
# * A list of node hashes for each snapshot, one per line.
|
||||
FORMAT_VERSION = "v1"
|
||||
|
||||
|
||||
class snapshotlist(object):
|
||||
"""list of local snapshots
|
||||
"""
|
||||
|
||||
def __init__(self, repo):
|
||||
self.vfs = repo.svfs
|
||||
try:
|
||||
lines = self.vfs("snapshotlist").readlines()
|
||||
if not lines or lines[0].strip() != FORMAT_VERSION:
|
||||
raise error.Abort("invalid snapshots file format")
|
||||
self.snapshots = {node.bin(snapshot.strip()) for snapshot in lines[1:]}
|
||||
except IOError as err:
|
||||
if err.errno != errno.ENOENT:
|
||||
raise
|
||||
self.snapshots = set()
|
||||
|
||||
def _write(self, fp):
|
||||
fp.write("%s\n" % FORMAT_VERSION)
|
||||
for s in sorted(self.snapshots):
|
||||
fp.write("%s\n" % (node.hex(s),))
|
||||
|
||||
def add(self, newnodes, tr):
|
||||
newnodes = self.snapshots.union(newnodes)
|
||||
if self.snapshots != newnodes:
|
||||
self.snapshots = newnodes
|
||||
tr.addfilegenerator("snapshots", ("snapshotlist",), self._write)
|
@ -255,6 +255,13 @@
|
||||
$ cat .hg/store/snapshots/objects/"${METADATAID:0:2}"/"${METADATAID:2}"
|
||||
{"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)
|
||||
|
||||
# Check the list of snapshots
|
||||
$ cat .hg/store/snapshotlist
|
||||
v1
|
||||
37c08567761738ed25fa7a8d497dc14de9dfa969
|
||||
aaa7692160b6c5c0e4c13787d9343cf89fc2311a
|
||||
c6f3170138389ab1cc8dd2d43fc275e5add2e1a2
|
||||
|
||||
# Move back to BASEREV
|
||||
$ hg update -q --clean "$BASEREV" && rm bazfile
|
||||
$ rm mergefile.orig
|
||||
|
Loading…
Reference in New Issue
Block a user