本文整理汇总了Python中dulwich.repo.MemoryRepo类的典型用法代码示例。如果您正苦于以下问题:Python MemoryRepo类的具体用法?Python MemoryRepo怎么用?Python MemoryRepo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MemoryRepo类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
super(ProtocolGraphWalkerEmptyTestCase, self).setUp()
self._repo = MemoryRepo.init_bare([], {})
backend = DictBackend({b'/': self._repo})
self._walker = ProtocolGraphWalker(
TestUploadPackHandler(backend, [b'/', b'host=lolcats'], TestProto()),
self._repo.object_store, self._repo.get_peeled)
示例2: setUp
def setUp(self):
super(GitImportProcessorTests, self).setUp()
self.repo = MemoryRepo()
try:
from dulwich.fastexport import GitImportProcessor
except ImportError:
raise SkipTest("python-fastimport not available")
self.processor = GitImportProcessor(self.repo)
示例3: _test_backend
def _test_backend(objects, refs=None, named_files=None):
if not refs:
refs = {}
if not named_files:
named_files = {}
repo = MemoryRepo.init_bare(objects, refs)
for path, contents in named_files.iteritems():
repo._put_named_file(path, contents)
return DictBackend({'/': repo})
示例4: test_commit_config_identity_in_memoryrepo
def test_commit_config_identity_in_memoryrepo(self):
# commit falls back to the users' identity if it wasn't specified
r = MemoryRepo.init_bare([], {})
c = r.get_config()
c.set(("user",), "name", "Jelmer")
c.set(("user",), "email", "[email protected]")
commit_sha = r.do_commit("message", tree=objects.Tree().id)
self.assertEqual("Jelmer <[email protected]>", r[commit_sha].author)
self.assertEqual("Jelmer <[email protected]>", r[commit_sha].committer)
示例5: test_receive_pack
def test_receive_pack(self):
commit = make_commit(id=ONE, parents=[], commit_time=111)
self.backend.repos["/"] = MemoryRepo.init_bare([commit], {"refs/heads/master": commit.id})
outf = BytesIO()
exitcode = self.serve_command(ReceivePackHandler, ["/"], BytesIO("0000"), outf)
outlines = outf.getvalue().splitlines()
self.assertEqual(2, len(outlines))
self.assertEqual("1111111111111111111111111111111111111111 refs/heads/master", outlines[0][4:].split("\x00")[0])
self.assertEqual("0000", outlines[-1])
self.assertEqual(0, exitcode)
示例6: test_bad_repo_path
def test_bad_repo_path(self):
repo = MemoryRepo.init_bare([], {})
backend = DictBackend({b'/': repo})
self.assertRaises(NotGitRepository,
lambda: backend.open_repository('/ups'))
示例7: test_nonexistant
def test_nonexistant(self):
repo = MemoryRepo.init_bare([], {})
backend = DictBackend({b'/': repo})
self.assertRaises(NotGitRepository,
backend.open_repository, "/does/not/exist/unless/foo")
示例8: test_create_memory
def test_create_memory(self):
repo = MemoryRepo.init_bare([], {})
self._check_repo_contents(repo, True)
示例9: setUp
def setUp(self):
super(UploadPackHandlerTestCase, self).setUp()
self._repo = MemoryRepo.init_bare([], {})
backend = DictBackend({'/': self._repo})
self._handler = UploadPackHandler(
backend, ['/', 'host=lolcathost'], TestProto())
示例10: setup
def setup(self):
self.teardown()
index = RamStorage().create_index(DateRevisionHybrid())
repo = MemoryRepo()
store = repo.object_store
sample_page_rst_blob, sample_page_with_attachments_rst_blob = (
Blob.from_string(_SAMPLE_PAGE_RST),
Blob.from_string(_SAMPLE_PAGE_WITH_ATTACHMENTS_RST),
)
store.add_object(sample_page_rst_blob)
store.add_object(sample_page_with_attachments_rst_blob)
sample_page_tree = Tree()
sample_page_tree.add('page.rst', 0100644, sample_page_rst_blob.id)
store.add_object(sample_page_tree)
sample_page_with_attachments_tree = Tree()
sample_page_with_attachments_tree.add(
'page.rst', 0100644, sample_page_with_attachments_rst_blob.id
)
store.add_object(sample_page_with_attachments_tree)
pages_tree = Tree()
pages_tree.add('sample-page', 0100755, sample_page_tree.id)
pages_tree.add(
'sample-page-with-attachments',
0100755,
sample_page_with_attachments_tree.id,
)
store.add_object(pages_tree)
root_tree = Tree()
root_tree.add('page', 0100755, pages_tree.id)
store.add_object(root_tree)
c = Commit()
c.tree = root_tree.id
c.message = 'initial commit'
c.committer = 'test committer <[email protected]>'
c.author = 'test author <[email protected]>'
c.commit_time = 1174773719
c.author_time = 1174773719
c.commit_timezone = 0
c.author_timezone = 0
store.add_object(c)
repo.refs['refs/heads/master'] = c.id
repo.refs['HEAD'] = c.id
build_hybrid_index(
index=index,
repo=repo,
ref='HEAD',
)
searcher = index.searcher()
self.index = index
self.searcher = searcher
self.api = GitPages(repo, searcher)
self.repo = repo
self.root_tree = root_tree
self.pages_tree = pages_tree
self.sample_page_tree = sample_page_tree
self.sample_page_rst_blob = sample_page_rst_blob
示例11: test_set_description
def test_set_description(self):
r = MemoryRepo.init_bare([], {})
description = b"Some description"
r.set_description(description)
self.assertEqual(description, r.get_description())
示例12: GitImportProcessorTests
class GitImportProcessorTests(TestCase):
"""Tests for the GitImportProcessor tests."""
def setUp(self):
super(GitImportProcessorTests, self).setUp()
self.repo = MemoryRepo()
try:
from dulwich.fastexport import GitImportProcessor
except ImportError:
raise SkipTest("python-fastimport not available")
self.processor = GitImportProcessor(self.repo)
def test_reset_handler(self):
from fastimport import commands
[c1] = build_commit_graph(self.repo.object_store, [[1]])
cmd = commands.ResetCommand(b"refs/heads/foo", c1.id)
self.processor.reset_handler(cmd)
self.assertEqual(c1.id, self.repo.get_refs()[b"refs/heads/foo"])
def test_commit_handler(self):
from fastimport import commands
cmd = commands.CommitCommand(b"refs/heads/foo", b"mrkr",
(b"Jelmer", b"[email protected]", 432432432.0, 3600),
(b"Jelmer", b"[email protected]", 432432432.0, 3600),
b"FOO", None, [], [])
self.processor.commit_handler(cmd)
commit = self.repo[self.processor.last_commit]
self.assertEqual(b"Jelmer <[email protected]>", commit.author)
self.assertEqual(b"Jelmer <[email protected]>", commit.committer)
self.assertEqual(b"FOO", commit.message)
self.assertEqual([], commit.parents)
self.assertEqual(432432432.0, commit.commit_time)
self.assertEqual(432432432.0, commit.author_time)
self.assertEqual(3600, commit.commit_timezone)
self.assertEqual(3600, commit.author_timezone)
self.assertEqual(commit, self.repo[b"refs/heads/foo"])
def test_import_stream(self):
markers = self.processor.import_stream(BytesIO(b"""blob
mark :1
data 11
text for a
commit refs/heads/master
mark :2
committer Joe Foo <[email protected]> 1288287382 +0000
data 20
<The commit message>
M 100644 :1 a
"""))
self.assertEqual(2, len(markers))
self.assertTrue(isinstance(self.repo[markers[b"1"]], Blob))
self.assertTrue(isinstance(self.repo[markers[b"2"]], Commit))
def test_file_add(self):
from fastimport import commands
cmd = commands.BlobCommand(b"23", b"data")
self.processor.blob_handler(cmd)
cmd = commands.CommitCommand(b"refs/heads/foo", b"mrkr",
(b"Jelmer", b"[email protected]", 432432432.0, 3600),
(b"Jelmer", b"[email protected]", 432432432.0, 3600),
b"FOO", None, [], [commands.FileModifyCommand(b"path", 0o100644, b":23", None)])
self.processor.commit_handler(cmd)
commit = self.repo[self.processor.last_commit]
self.assertEqual([
(b'path', 0o100644, b'6320cd248dd8aeaab759d5871f8781b5c0505172')],
self.repo[commit.tree].items())
def simple_commit(self):
from fastimport import commands
cmd = commands.BlobCommand(b"23", b"data")
self.processor.blob_handler(cmd)
cmd = commands.CommitCommand(b"refs/heads/foo", b"mrkr",
(b"Jelmer", b"[email protected]", 432432432.0, 3600),
(b"Jelmer", b"[email protected]", 432432432.0, 3600),
b"FOO", None, [], [commands.FileModifyCommand(b"path", 0o100644, b":23", None)])
self.processor.commit_handler(cmd)
commit = self.repo[self.processor.last_commit]
return commit
def make_file_commit(self, file_cmds):
"""Create a trivial commit with the specified file commands.
:param file_cmds: File commands to run.
:return: The created commit object
"""
from fastimport import commands
cmd = commands.CommitCommand(b"refs/heads/foo", b"mrkr",
(b"Jelmer", b"[email protected]", 432432432.0, 3600),
(b"Jelmer", b"[email protected]", 432432432.0, 3600),
b"FOO", None, [], file_cmds)
self.processor.commit_handler(cmd)
return self.repo[self.processor.last_commit]
def test_file_copy(self):
from fastimport import commands
self.simple_commit()
commit = self.make_file_commit([commands.FileCopyCommand(b"path", b"new_path")])
self.assertEqual([
#.........这里部分代码省略.........
示例13: MemoryRepo
#!/usr/bin/python
# This script creates a clone of a remote repository in local memory,
# then adds a single file and pushes the result back.
#
# Example usage:
# python examples/memoryrepo.py git+ssh://github.com/jelmer/testrepo
import stat
import sys
from dulwich import porcelain
from dulwich.objects import Blob
from dulwich.repo import MemoryRepo
local_repo = MemoryRepo()
local_repo.refs.set_symbolic_ref(b'HEAD', b'refs/heads/master')
print(local_repo.refs.as_dict())
porcelain.fetch(local_repo, sys.argv[1])
local_repo['refs/heads/master'] = local_repo['refs/remotes/origin/master']
last_tree = local_repo[local_repo['HEAD'].tree]
new_blob = Blob.from_string(b'Some contents')
local_repo.object_store.add_object(new_blob)
last_tree.add(b'test', stat.S_IFREG, new_blob.id)
local_repo.object_store.add_object(last_tree)
local_repo.do_commit(
message=b'Add a file called \'test\'',
ref=b'refs/heads/master',
tree=last_tree.id)