本文整理汇总了Python中dulwich.object_store.DiskObjectStore.add_object方法的典型用法代码示例。如果您正苦于以下问题:Python DiskObjectStore.add_object方法的具体用法?Python DiskObjectStore.add_object怎么用?Python DiskObjectStore.add_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dulwich.object_store.DiskObjectStore
的用法示例。
在下文中一共展示了DiskObjectStore.add_object方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_alternates
# 需要导入模块: from dulwich.object_store import DiskObjectStore [as 别名]
# 或者: from dulwich.object_store.DiskObjectStore import add_object [as 别名]
def test_alternates(self):
alternate_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, alternate_dir)
alternate_store = DiskObjectStore(alternate_dir)
b2 = make_object(Blob, data="yummy data")
alternate_store.add_object(b2)
store = DiskObjectStore(self.store_dir)
self.assertRaises(KeyError, store.__getitem__, b2.id)
store.add_alternate_path(alternate_dir)
self.assertEquals(b2, store[b2.id])
示例2: test_rel_alternative_path
# 需要导入模块: from dulwich.object_store import DiskObjectStore [as 别名]
# 或者: from dulwich.object_store.DiskObjectStore import add_object [as 别名]
def test_rel_alternative_path(self):
alternate_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, alternate_dir)
alternate_store = DiskObjectStore(alternate_dir)
b2 = make_object(Blob, data="yummy data")
alternate_store.add_object(b2)
store = DiskObjectStore(self.store_dir)
self.assertRaises(KeyError, store.__getitem__, b2.id)
store.add_alternate_path(os.path.relpath(alternate_dir, self.store_dir))
self.assertEqual(list(alternate_store), list(store.alternates[0]))
self.assertIn(b2.id, store)
self.assertEqual(b2, store[b2.id])
示例3: test_alternates
# 需要导入模块: from dulwich.object_store import DiskObjectStore [as 别名]
# 或者: from dulwich.object_store.DiskObjectStore import add_object [as 别名]
def test_alternates(self):
alternate_dir = tempfile.mkdtemp()
if not isinstance(alternate_dir, bytes):
alternate_dir = alternate_dir.encode(sys.getfilesystemencoding())
self.addCleanup(shutil.rmtree, alternate_dir)
alternate_store = DiskObjectStore(alternate_dir)
b2 = make_object(Blob, data=b"yummy data")
alternate_store.add_object(b2)
store = DiskObjectStore(self.store_dir)
self.assertRaises(KeyError, store.__getitem__, b2.id)
store.add_alternate_path(alternate_dir)
self.assertIn(b2.id, store)
self.assertEqual(b2, store[b2.id])
示例4: test_add_thin_pack
# 需要导入模块: from dulwich.object_store import DiskObjectStore [as 别名]
# 或者: from dulwich.object_store.DiskObjectStore import add_object [as 别名]
def test_add_thin_pack(self):
o = DiskObjectStore(self.store_dir)
blob = make_object(Blob, data='yummy data')
o.add_object(blob)
f = StringIO()
entries = build_pack(f, [
(REF_DELTA, (blob.id, 'more yummy data')),
], store=o)
pack = o.add_thin_pack(f.read, None)
packed_blob_sha = sha_to_hex(entries[0][3])
pack.check_length_and_checksum()
self.assertEqual(sorted([blob.id, packed_blob_sha]), list(pack))
self.assertTrue(o.contains_packed(packed_blob_sha))
self.assertTrue(o.contains_packed(blob.id))
self.assertEqual((Blob.type_num, 'more yummy data'),
o.get_raw(packed_blob_sha))
示例5: test_add_thin_pack
# 需要导入模块: from dulwich.object_store import DiskObjectStore [as 别名]
# 或者: from dulwich.object_store.DiskObjectStore import add_object [as 别名]
def test_add_thin_pack(self):
o = DiskObjectStore(self.store_dir)
blob = make_object(Blob, data='yummy data')
o.add_object(blob)
f = StringIO()
entries = build_pack(f, [
(REF_DELTA, (blob.id, 'more yummy data')),
], store=o)
pack = o.add_thin_pack(f.read, None)
try:
packed_blob_sha = sha_to_hex(entries[0][3])
pack.check_length_and_checksum()
self.assertEqual(sorted([blob.id, packed_blob_sha]), list(pack))
self.assertTrue(o.contains_packed(packed_blob_sha))
self.assertTrue(o.contains_packed(blob.id))
self.assertEqual((Blob.type_num, 'more yummy data'),
o.get_raw(packed_blob_sha))
finally:
# FIXME: DiskObjectStore should have close() which do the following:
for p in o._pack_cache or []:
p.close()
pack.close()
示例6: Repo
# 需要导入模块: from dulwich.object_store import DiskObjectStore [as 别名]
# 或者: from dulwich.object_store.DiskObjectStore import add_object [as 别名]
class Repo(object):
"""A local git repository.
:ivar refs: Dictionary with the refs in this repository
:ivar object_store: Dictionary-like object for accessing
the objects
"""
def __init__(self, root):
if os.path.isdir(os.path.join(root, ".git", OBJECTDIR)):
self.bare = False
self._controldir = os.path.join(root, ".git")
elif (os.path.isdir(os.path.join(root, OBJECTDIR)) and
os.path.isdir(os.path.join(root, REFSDIR))):
self.bare = True
self._controldir = root
else:
raise NotGitRepository(root)
self.path = root
self.refs = DiskRefsContainer(self.controldir())
self.object_store = DiskObjectStore(
os.path.join(self.controldir(), OBJECTDIR))
def controldir(self):
"""Return the path of the control directory."""
return self._controldir
def index_path(self):
"""Return path to the index file."""
return os.path.join(self.controldir(), INDEX_FILENAME)
def open_index(self):
"""Open the index for this repository."""
from dulwich.index import Index
return Index(self.index_path())
def has_index(self):
"""Check if an index is present."""
return os.path.exists(self.index_path())
def fetch(self, target, determine_wants=None, progress=None):
"""Fetch objects into another repository.
:param target: The target repository
:param determine_wants: Optional function to determine what refs to
fetch.
:param progress: Optional progress function
"""
target.object_store.add_objects(
self.fetch_objects(determine_wants, target.get_graph_walker(),
progress))
return self.get_refs()
def fetch_objects(self, determine_wants, graph_walker, progress):
"""Fetch the missing objects required for a set of revisions.
:param determine_wants: Function that takes a dictionary with heads
and returns the list of heads to fetch.
:param graph_walker: Object that can iterate over the list of revisions
to fetch and has an "ack" method that will be called to acknowledge
that a revision is present.
:param progress: Simple progress function that will be called with
updated progress strings.
:return: iterator over objects, with __len__ implemented
"""
wants = determine_wants(self.get_refs())
haves = self.object_store.find_common_revisions(graph_walker)
return self.object_store.iter_shas(
self.object_store.find_missing_objects(haves, wants, progress))
def get_graph_walker(self, heads=None):
if heads is None:
heads = self.refs.as_dict('refs/heads').values()
return self.object_store.get_graph_walker(heads)
def ref(self, name):
"""Return the SHA1 a ref is pointing to."""
try:
return self.refs.follow(name)
except KeyError:
return self.get_packed_refs()[name]
def get_refs(self):
"""Get dictionary with all refs."""
ret = {}
try:
if self.head():
ret['HEAD'] = self.head()
except KeyError:
pass
ret.update(self.refs.as_dict())
ret.update(self.get_packed_refs())
return ret
def get_packed_refs(self):
"""Get contents of the packed-refs file.
:return: Dictionary mapping ref names to SHA1s
:note: Will return an empty dictionary when no packed-refs file is
#.........这里部分代码省略.........