Beispiel #1
0
    def write_tree(self):
        """Writes this index to a corresponding Tree object into the repository's
        object database and return it.

        :return: Tree object representing this index
        :note: The tree will be written even if one or more objects the tree refers to
            does not yet exist in the object database. This could happen if you added
            Entries to the index directly.
        :raise ValueError: if there are no entries in the cache
        :raise UnmergedEntriesError: """
        # we obtain no lock as we just flush our contents to disk as tree
        # If we are a new index, the entries access will load our data accordingly
        mdb = MemoryDB()
        entries = self._entries_sorted()
        binsha, tree_items = write_tree_from_cache(entries, mdb,
                                                   slice(0, len(entries)))

        # copy changed trees only
        mdb.stream_copy(mdb.sha_iter(), self.repo.odb)

        # note: additional deserialization could be saved if write_tree_from_cache
        # would return sorted tree entries
        root_tree = Tree(self.repo, binsha, path='')
        root_tree._cache = tree_items
        return root_tree
Beispiel #2
0
	def write_tree(self):
		"""Writes this index to a corresponding Tree object into the repository's
		object database and return it.
		
		:return: Tree object representing this index
		:note: The tree will be written even if one or more objects the tree refers to 
			does not yet exist in the object database. This could happen if you added
			Entries to the index directly.
		:raise ValueError: if there are no entries in the cache
		:raise UnmergedEntriesError: """
		# we obtain no lock as we just flush our contents to disk as tree
		# If we are a new index, the entries access will load our data accordingly
		mdb = MemoryDB()
		entries = self._entries_sorted()
		binsha, tree_items = write_tree_from_cache(entries, mdb, slice(0, len(entries)))
		
		# copy changed trees only
		mdb.stream_copy(mdb.sha_iter(), self.repo.odb)
		
		
		# note: additional deserialization could be saved if write_tree_from_cache
		# would return sorted tree entries
		root_tree = Tree(self.repo, binsha, path='')
		root_tree._cache = tree_items
		return root_tree
Beispiel #3
0
    def test_writing(self, path):
        mdb = MemoryDB()

        # write data
        self._assert_object_writing_simple(mdb)

        # test stream copy
        ldb = LooseObjectDB(path)
        assert ldb.size() == 0
        num_streams_copied = mdb.stream_copy(mdb.sha_iter(), ldb)
        assert num_streams_copied == mdb.size()

        assert ldb.size() == mdb.size()
        for sha in mdb.sha_iter():
            assert ldb.has_object(sha)
            assert ldb.stream(sha).read() == mdb.stream(sha).read()
Beispiel #4
0
	def test_writing(self, path):
		mdb = MemoryDB()
		
		# write data
		self._assert_object_writing_simple(mdb)
		
		# test stream copy
		ldb = LooseObjectDB(path)
		assert ldb.size() == 0
		num_streams_copied = mdb.stream_copy(mdb.sha_iter(), ldb)
		assert num_streams_copied == mdb.size()
		
		assert ldb.size() == mdb.size()
		for sha in mdb.sha_iter():
			assert ldb.has_object(sha)
			assert ldb.stream(sha).read() == mdb.stream(sha).read()