mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 09:17:30 +03:00
3e0b781197
Summary: Drop stdoutbytes/stdinbytes. They make things unnecessarily complicated (especially for chg / Rust dispatch entry point). The new idea is IO are using bytes. Text are written in utf-8 (Python 3) or local encoding (Python 2). To make stdout behave reasonably on systems not using utf-8 locale (ex. Windows), we might add a Rust binding to Rust's stdout, which does the right thing: - When writing to stdout console, expect text to be utf-8 encoded and do proper decoding. - Wehn writing to stdout file, write the raw bytes without translation. Note Python's `sys.stdout.buffer` does not do translation when writing to stdout console like Rust's stdout. For now, my main motivation of this change is to fix chg on Python 3. Reviewed By: xavierd Differential Revision: D19702533 fbshipit-source-id: 74704c83e1b200ff66fb3a2d23d97ff21c7239c8
53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
# Copyright (c) Facebook, Inc. and its affiliates.
|
|
#
|
|
# This software may be used and distributed according to the terms of the
|
|
# GNU General Public License version 2.
|
|
|
|
# replay.py - types and utils for unbundle replays.
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from . import json
|
|
|
|
|
|
class ReplayData(object):
|
|
"""A structure to store and serialize/deserialize replay-related data
|
|
|
|
Replay is a process of re-application of an `unbundle`, captured on
|
|
the wire in some other system. Such re-application might have some
|
|
expectations, which we need to be able to verify, and some additional
|
|
data, which we may need to use. Currently, the following are stored:
|
|
`commitdates` - a map form the original hash to the commit date to
|
|
be used in a rebased commit. Must be in the format,
|
|
understood by `util.parsedate`.
|
|
- `ontobook` - a bookmark, used for pushrebase
|
|
- `rebasedhead`- an expected hash of the rebased head
|
|
"""
|
|
|
|
def __init__(self, commitdates, rebasedhead, ontobook):
|
|
self.commitdates = commitdates
|
|
self.rebasedhead = rebasedhead
|
|
self.ontobook = ontobook
|
|
|
|
def serialize(self):
|
|
res = {
|
|
"commitdates": self.commitdates,
|
|
"rebasedhead": self.rebasedhead,
|
|
"ontobook": self.ontobook,
|
|
}
|
|
return json.dumps(res).encode("utf-8")
|
|
|
|
@classmethod
|
|
def deserialize(cls, s):
|
|
d = json.loads(s.decode("utf-8"))
|
|
commitdates = d.get("commitdates", {})
|
|
rebasedhead = d.get("rebasedhead")
|
|
ontobook = d.get("ontobook")
|
|
return cls(commitdates, rebasedhead, ontobook)
|
|
|
|
def getcommitdate(self, ui, commithash, commitdate):
|
|
saveddate = self.commitdates.get(commithash)
|
|
if saveddate:
|
|
return (int(saveddate), commitdate[1])
|
|
return commitdate
|