mirror of
https://github.com/facebook/sapling.git
synced 2024-10-16 11:52:02 +03:00
6660438ea2
Summary: Adds the initial skeleton of the `commitcloud` extension to Mercurial, which will synchronise heads and bookmarks (and later, obsmarkers) with commit cloud. Current limitations: - only supports a stub version of the service that uses local files - requires manual pushbackup to send commits to the server via infinitepush - doesn't do anything with obsmarkers Differential Revision: D7167715 fbshipit-source-id: 53443f3fb8dff0fe52257d7b20fc601dbe10c883
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
# Copyright 2018 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 json
|
|
|
|
from .. import shareutil
|
|
|
|
class SyncState(object):
|
|
"""
|
|
Stores the local record of what state was stored in the cloud at the
|
|
last sync.
|
|
"""
|
|
filename = 'commitcloudstate'
|
|
|
|
def __init__(self, repo):
|
|
repo = shareutil.getsrcrepo(repo)
|
|
self.repo = repo
|
|
if repo.vfs.exists(self.filename):
|
|
with repo.vfs.open(self.filename, 'r') as f:
|
|
data = json.load(f)
|
|
self.version = data['version']
|
|
self.heads = [h.encode() for h in data['heads']]
|
|
self.bookmarks = {n.encode('utf-8'): v.encode()
|
|
for n, v in data['bookmarks'].items()}
|
|
else:
|
|
self.version = 0
|
|
self.heads = []
|
|
self.bookmarks = {}
|
|
|
|
def update(self, newversion, newheads, newbookmarks):
|
|
data = {
|
|
'version': newversion,
|
|
'heads': newheads,
|
|
'bookmarks': newbookmarks,
|
|
}
|
|
with self.repo.wlock():
|
|
with self.repo.vfs.open(self.filename, 'w', atomictemp=True) as f:
|
|
json.dump(data, f)
|
|
self.version = newversion
|
|
self.heads = newheads
|
|
self.bookmarks = newbookmarks
|