本文整理汇总了Python中dulwich.server.ProtocolGraphWalker._handle_shallow_request方法的典型用法代码示例。如果您正苦于以下问题:Python ProtocolGraphWalker._handle_shallow_request方法的具体用法?Python ProtocolGraphWalker._handle_shallow_request怎么用?Python ProtocolGraphWalker._handle_shallow_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dulwich.server.ProtocolGraphWalker
的用法示例。
在下文中一共展示了ProtocolGraphWalker._handle_shallow_request方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProtocolGraphWalkerTestCase
# 需要导入模块: from dulwich.server import ProtocolGraphWalker [as 别名]
# 或者: from dulwich.server.ProtocolGraphWalker import _handle_shallow_request [as 别名]
#.........这里部分代码省略.........
None,
])
heads = {
b'refs/heads/ref1': ONE,
b'refs/heads/ref2': TWO,
b'refs/heads/ref3': THREE,
}
self._repo.refs._update(heads)
self.assertEqual([ONE, TWO], self._walker.determine_wants(heads))
self._walker.advertise_refs = True
self.assertEqual([], self._walker.determine_wants(heads))
self._walker.advertise_refs = False
self._walker.proto.set_output([b'want ' + FOUR + b' multi_ack', None])
self.assertRaises(GitProtocolError, self._walker.determine_wants, heads)
self._walker.proto.set_output([None])
self.assertEqual([], self._walker.determine_wants(heads))
self._walker.proto.set_output([b'want ' + ONE + b' multi_ack', b'foo', None])
self.assertRaises(GitProtocolError, self._walker.determine_wants, heads)
self._walker.proto.set_output([b'want ' + FOUR + b' multi_ack', None])
self.assertRaises(GitProtocolError, self._walker.determine_wants, heads)
def test_determine_wants_advertisement(self):
self._walker.proto.set_output([None])
# advertise branch tips plus tag
heads = {
b'refs/heads/ref4': FOUR,
b'refs/heads/ref5': FIVE,
b'refs/heads/tag6': SIX,
}
self._repo.refs._update(heads)
self._repo.refs._update_peeled(heads)
self._repo.refs._update_peeled({b'refs/heads/tag6': FIVE})
self._walker.determine_wants(heads)
lines = []
while True:
line = self._walker.proto.get_received_line()
if line is None:
break
# strip capabilities list if present
if b'\x00' in line:
line = line[:line.index(b'\x00')]
lines.append(line.rstrip())
self.assertEqual([
FOUR + b' refs/heads/ref4',
FIVE + b' refs/heads/ref5',
FIVE + b' refs/heads/tag6^{}',
SIX + b' refs/heads/tag6',
], sorted(lines))
# ensure peeled tag was advertised immediately following tag
for i, line in enumerate(lines):
if line.endswith(b' refs/heads/tag6'):
self.assertEqual(FIVE + b' refs/heads/tag6^{}', lines[i+1])
# TODO: test commit time cutoff
def _handle_shallow_request(self, lines, heads):
self._walker.proto.set_output(lines + [None])
self._walker._handle_shallow_request(heads)
def assertReceived(self, expected):
self.assertEqual(
expected, list(iter(self._walker.proto.get_received_line, None)))
def test_handle_shallow_request_no_client_shallows(self):
self._handle_shallow_request([b'deepen 2\n'], [FOUR, FIVE])
self.assertEqual(set([TWO, THREE]), self._walker.shallow)
self.assertReceived([
b'shallow ' + TWO,
b'shallow ' + THREE,
])
def test_handle_shallow_request_no_new_shallows(self):
lines = [
b'shallow ' + TWO + b'\n',
b'shallow ' + THREE + b'\n',
b'deepen 2\n',
]
self._handle_shallow_request(lines, [FOUR, FIVE])
self.assertEqual(set([TWO, THREE]), self._walker.shallow)
self.assertReceived([])
def test_handle_shallow_request_unshallows(self):
lines = [
b'shallow ' + TWO + b'\n',
b'deepen 3\n',
]
self._handle_shallow_request(lines, [FOUR, FIVE])
self.assertEqual(set([ONE]), self._walker.shallow)
self.assertReceived([
b'shallow ' + ONE,
b'unshallow ' + TWO,
# THREE is unshallow but was is not shallow in the client
])
示例2: ProtocolGraphWalkerTestCase
# 需要导入模块: from dulwich.server import ProtocolGraphWalker [as 别名]
# 或者: from dulwich.server.ProtocolGraphWalker import _handle_shallow_request [as 别名]
#.........这里部分代码省略.........
allowed = ("want", "done", None)
self.assertEqual(("want", ONE), _split_proto_line("want %s\n" % ONE, allowed))
self.assertEqual(("want", TWO), _split_proto_line("want %s\n" % TWO, allowed))
self.assertRaises(GitProtocolError, _split_proto_line, "want xxxx\n", allowed)
self.assertRaises(UnexpectedCommandError, _split_proto_line, "have %s\n" % THREE, allowed)
self.assertRaises(GitProtocolError, _split_proto_line, "foo %s\n" % FOUR, allowed)
self.assertRaises(GitProtocolError, _split_proto_line, "bar", allowed)
self.assertEqual(("done", None), _split_proto_line("done\n", allowed))
self.assertEqual((None, None), _split_proto_line("", allowed))
def test_determine_wants(self):
self._walker.proto.set_output([None])
self.assertEqual([], self._walker.determine_wants({}))
self.assertEqual(None, self._walker.proto.get_received_line())
self._walker.proto.set_output(["want %s multi_ack" % ONE, "want %s" % TWO, None])
heads = {"refs/heads/ref1": ONE, "refs/heads/ref2": TWO, "refs/heads/ref3": THREE}
self._repo.refs._update(heads)
self.assertEqual([ONE, TWO], self._walker.determine_wants(heads))
self._walker.advertise_refs = True
self.assertEqual([], self._walker.determine_wants(heads))
self._walker.advertise_refs = False
self._walker.proto.set_output(["want %s multi_ack" % FOUR, None])
self.assertRaises(GitProtocolError, self._walker.determine_wants, heads)
self._walker.proto.set_output([None])
self.assertEqual([], self._walker.determine_wants(heads))
self._walker.proto.set_output(["want %s multi_ack" % ONE, "foo", None])
self.assertRaises(GitProtocolError, self._walker.determine_wants, heads)
self._walker.proto.set_output(["want %s multi_ack" % FOUR, None])
self.assertRaises(GitProtocolError, self._walker.determine_wants, heads)
def test_determine_wants_advertisement(self):
self._walker.proto.set_output([None])
# advertise branch tips plus tag
heads = {"refs/heads/ref4": FOUR, "refs/heads/ref5": FIVE, "refs/heads/tag6": SIX}
self._repo.refs._update(heads)
self._repo.refs._update_peeled(heads)
self._repo.refs._update_peeled({"refs/heads/tag6": FIVE})
self._walker.determine_wants(heads)
lines = []
while True:
line = self._walker.proto.get_received_line()
if line is None:
break
# strip capabilities list if present
if "\x00" in line:
line = line[: line.index("\x00")]
lines.append(line.rstrip())
self.assertEqual(
[
"%s refs/heads/ref4" % FOUR,
"%s refs/heads/ref5" % FIVE,
"%s refs/heads/tag6^{}" % FIVE,
"%s refs/heads/tag6" % SIX,
],
sorted(lines),
)
# ensure peeled tag was advertised immediately following tag
for i, line in enumerate(lines):
if line.endswith(" refs/heads/tag6"):
self.assertEqual("%s refs/heads/tag6^{}" % FIVE, lines[i + 1])
# TODO: test commit time cutoff
def _handle_shallow_request(self, lines, heads):
self._walker.proto.set_output(lines + [None])
self._walker._handle_shallow_request(heads)
def assertReceived(self, expected):
self.assertEquals(expected, list(iter(self._walker.proto.get_received_line, None)))
def test_handle_shallow_request_no_client_shallows(self):
self._handle_shallow_request(["deepen 1\n"], [FOUR, FIVE])
self.assertEquals(set([TWO, THREE]), self._walker.shallow)
self.assertReceived(["shallow %s" % TWO, "shallow %s" % THREE])
def test_handle_shallow_request_no_new_shallows(self):
lines = ["shallow %s\n" % TWO, "shallow %s\n" % THREE, "deepen 1\n"]
self._handle_shallow_request(lines, [FOUR, FIVE])
self.assertEquals(set([TWO, THREE]), self._walker.shallow)
self.assertReceived([])
def test_handle_shallow_request_unshallows(self):
lines = ["shallow %s\n" % TWO, "deepen 2\n"]
self._handle_shallow_request(lines, [FOUR, FIVE])
self.assertEquals(set([ONE]), self._walker.shallow)
self.assertReceived(
[
"shallow %s" % ONE,
"unshallow %s" % TWO,
# THREE is unshallow but was is not shallow in the client
]
)