Example #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
        # Needs delayed import as db.py import IndexFile as well
        import git.db.py.mem
        mdb = git.db.py.mem.PureMemoryDB()
        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
Example #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
Example #3
0
def commit_from_binsha(repo, binsha, org_commit, parents=None):
    tree = Tree.new(repo, bin_to_hex(binsha))

    env = os.environ

    offset = altz_to_utctz_str(org_commit.author_tz_offset)
    date = org_commit.authored_date
    env[Commit.env_author_date] = '{} {}'.format(date, offset)

    offset = altz_to_utctz_str(org_commit.committer_tz_offset)
    date = org_commit.committed_date
    env[Commit.env_committer_date] = '{} {}'.format(date, offset)

    return Commit.create_from_tree(repo, tree, org_commit.message, parents,
                                   head=True,
                                   author=org_commit.author,
                                   committer=org_commit.committer)
Example #4
0
File: util.py Project: euneon/kenja
def commit_from_binsha(repo, binsha, org_commit, parents=None):
    env = os.environ

    author_date = "%d %s" % (org_commit.authored_date, altz_to_utctz_str(org_commit.author_tz_offset))
    env[Commit.env_author_date] = author_date

    committer_date = "%d %s" % (org_commit.committed_date, altz_to_utctz_str(org_commit.committer_tz_offset))
    env[Commit.env_committer_date] = committer_date

    env[Actor.env_author_name] = org_commit.author.name.encode(org_commit.encoding)
    env[Actor.env_author_email] = org_commit.author.email or ""

    env[Actor.env_committer_name] = org_commit.committer.name.encode(org_commit.encoding)
    env[Actor.env_committer_email] = org_commit.committer.email or ""

    message = org_commit.message.encode(org_commit.encoding)

    tree = Tree.new(repo, bin_to_hex(binsha))

    return Commit.create_from_tree(repo, tree, message, parents, True)
Example #5
0
def commit_from_binsha(repo, binsha, org_commit, parents=None):
    message = org_commit.message.encode(org_commit.encoding)

    tree = Tree.new(repo, bin_to_hex(binsha))

    new_commit = Commit(repo, Commit.NULL_BIN_SHA, tree,
                        org_commit.author, org_commit.authored_date, org_commit.author_tz_offset,
                        org_commit.committer, org_commit.committed_date, org_commit.committer_tz_offset,
                        message, parents, org_commit.encoding)
    stream = StringIO()
    new_commit._serialize(stream)
    streamlen = stream.tell()
    stream.seek(0)
    istream = repo.odb.store(IStream(Commit.type, streamlen, stream))
    new_commit.binsha = istream.binsha

    try:
        repo.head.set_commit(new_commit, logmsg="commit: %s" % message)
    except ValueError:
        master = git.refs.Head.create(repo, repo.head.ref, new_commit, logmsg="commit (initial): %s" % message)
        repo.head.set_reference(master, logmsg='commit: Switching to %s' % master)

    return new_commit
Example #6
0
        children = []
        for parent in commit.parents:
            if parent.hexsha not in visited:
                children.append(parent.hexsha)

        if children:
            nodes.extend(children)
        else:
            nodes.pop()
            visited.add(node)
            post.append(node)

    return post


if __name__ == '__main__':
    repo = Repo.init('test_git')
    # (mode, binsha) = write_tree(repo.odb, 'temp')

    # (mode, binsha) = write_tree(repo.odb, 'temp/00')
    # (mode, binsha) = write_tree(repo.odb, 'temp/01')

    paths = ['temp/00', 'temp/01']
    names = ['a', 'b']

    (mode, binsha) = write_paths(repo.odb, paths, names)

    tree = Tree.new(repo, bin_to_hex(binsha))
    c = Commit.create_from_tree(repo, tree, 'test commit', None, True)