sapling/eden/scm/edenscm/pushkey.py

68 lines
1.9 KiB
Python
Raw Normal View History

# Portions Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2.
2010-06-17 01:04:44 +04:00
# pushkey.py - dispatching for pushing and pulling keys
#
# Copyright 2010 Olivia Mackall <olivia@selenic.com>
2010-06-17 01:04:44 +04:00
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
2015-08-09 05:57:27 +03:00
from __future__ import absolute_import
from . import bookmarks, phases, util
from .pycompat import decodeutf8, encodeutf8
2010-06-17 01:04:44 +04:00
def _nslist(repo):
n = {}
for k in _namespaces:
n[k] = ""
return n
_namespaces = {
"namespaces": (lambda *x: False, _nslist),
"bookmarks": (bookmarks.pushbookmark, bookmarks.listbookmarks),
"phases": (phases.pushphase, phases.listphases),
}
2010-06-17 01:04:44 +04:00
def register(namespace, pushkey, listkeys):
_namespaces[namespace] = (pushkey, listkeys)
2010-06-17 01:04:44 +04:00
def _get(namespace):
return _namespaces.get(namespace, (lambda *x: False, lambda *x: {}))
2010-06-17 01:04:44 +04:00
def push(repo, namespace, key, old, new):
"""should succeed iff value was old"""
2010-06-17 01:04:44 +04:00
pk = _get(namespace)[0]
return pk(repo, key, old, new)
2010-06-17 01:04:44 +04:00
def list(repo, namespace):
"""return a dict"""
2010-06-17 01:04:44 +04:00
lk = _get(namespace)[1]
return lk(repo)
def encodekeys(keys):
"""encode the content of a pushkey namespace for exchange over the wire"""
return b"\n".join([b"%s\t%s" % (encodeutf8(k), encodeutf8(v)) for k, v in keys])
def decodekeys(data):
"""decode the content of a pushkey namespace from exchange over the wire"""
Preserve order of revisions after hg pullbackup Summary: This diff fixes hg pullbackup so it retrieves commits in the same order that there were pushed. This was caused by commits being stored in sets and dictionare which are by unorered types. These have been replaced by OrderedDict to mantain the order. **Description of the task:** Infinitepush is a mercurial extension that allows sharing commits easily. Among other things it also backs up all local commites that were made on devservers and laptops. That means that we always have up-to-date backup You can read more about it here - https://our.intern.facebook.com/intern/dex/mercurial-workflow/infinitepush/ . Backup is triggered whenever mercurial transaction is triggered i.e. during commit, rebase or any other operation that changes mercurial repo. `hg pullbackup` is the way to pull backed up commits. There is a problem. Let's say host A has this repo: ` o` ` |` ` o C1` ` | /` ` | C2` ` | /` ` o` So we have two draft commits: C1 and C2. C2 is probably an older commit. But if we restore it on another host we can get another output: ` o` ` |` ` o C2` ` | /` ` | C1` ` | /` ` o ` This happens because `hg sl` orders commits by it's revision number in revlog - https://www.mercurial-scm.org/wiki/Revlog . The point of the task is to make sure commits are ordered by their creation date. Link to comment: http://www.facebook.com/groups/scm/permalink/1504906422892306/?comment_id=1505017576214524&reply_comment_id=1506426179406997 Reviewed By: StanislavGlebik Differential Revision: D6884670 fbshipit-source-id: 3281dbc1e25e24662a4b6ba78b96b85d5bae78c9
2018-02-06 20:57:21 +03:00
# Note that the order is required in some cases. E.g. pullbackup needs to
# retrieve commits in the same order of creation to mantain the order of
# revision codes. See T24417531
result = util.sortdict()
for l in data.splitlines():
k, v = l.split(b"\t")
result[decodeutf8(k)] = decodeutf8(v)
return result