当前位置: 首页>>代码示例>>Python>>正文


Python Commit.binsha方法代码示例

本文整理汇总了Python中git.Commit.binsha方法的典型用法代码示例。如果您正苦于以下问题:Python Commit.binsha方法的具体用法?Python Commit.binsha怎么用?Python Commit.binsha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在git.Commit的用法示例。


在下文中一共展示了Commit.binsha方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_commit_serialization

# 需要导入模块: from git import Commit [as 别名]
# 或者: from git.Commit import binsha [as 别名]
    def test_commit_serialization(self):
        assert_commit_serialization(self.gitrwrepo, self.gitrwrepo.head, True)

        rwrepo = self.gitrwrepo
        make_object = rwrepo.odb.store
        # direct serialization - deserialization can be tested afterwards
        # serialization is probably limited on IO
        hc = rwrepo.commit(rwrepo.head)

        nc = 5000
        st = time()
        for i in xrange(nc):
            cm = Commit(rwrepo, Commit.NULL_BIN_SHA, hc.tree,
                        hc.author, hc.authored_date, hc.author_tz_offset,
                        hc.committer, hc.committed_date, hc.committer_tz_offset,
                        str(i), parents=hc.parents, encoding=hc.encoding)

            stream = BytesIO()
            cm._serialize(stream)
            slen = stream.tell()
            stream.seek(0)

            cm.binsha = make_object(IStream(Commit.type, slen, stream)).binsha
        # END commit creation
        elapsed = time() - st

        print("Serialized %i commits to loose objects in %f s ( %f commits / s )"
              % (nc, elapsed, nc / elapsed), file=sys.stderr)
开发者ID:Javex,项目名称:GitPython,代码行数:30,代码来源:test_commit.py

示例2: assert_commit_serialization

# 需要导入模块: from git import Commit [as 别名]
# 或者: from git.Commit import binsha [as 别名]
def assert_commit_serialization(rwrepo, commit_id, print_performance_info=False):
    """traverse all commits in the history of commit identified by commit_id and check
    if the serialization works.
    :param print_performance_info: if True, we will show how fast we are"""
    ns = 0      # num serializations
    nds = 0     # num deserializations

    st = time.time()
    for cm in rwrepo.commit(commit_id).traverse():
        nds += 1

        # assert that we deserialize commits correctly, hence we get the same
        # sha on serialization
        stream = BytesIO()
        cm._serialize(stream)
        ns += 1
        streamlen = stream.tell()
        stream.seek(0)

        istream = rwrepo.odb.store(IStream(Commit.type, streamlen, stream))
        assert istream.hexsha == cm.hexsha.encode('ascii')

        nc = Commit(rwrepo, Commit.NULL_BIN_SHA, cm.tree,
                    cm.author, cm.authored_date, cm.author_tz_offset,
                    cm.committer, cm.committed_date, cm.committer_tz_offset,
                    cm.message, cm.parents, cm.encoding)

        assert nc.parents == cm.parents
        stream = BytesIO()
        nc._serialize(stream)
        ns += 1
        streamlen = stream.tell()
        stream.seek(0)

        # reuse istream
        istream.size = streamlen
        istream.stream = stream
        istream.binsha = None
        nc.binsha = rwrepo.odb.store(istream).binsha

        # if it worked, we have exactly the same contents !
        assert nc.hexsha == cm.hexsha
    # END check commits
    elapsed = time.time() - st

    if print_performance_info:
        print("Serialized %i and deserialized %i commits in %f s ( (%f, %f) commits / s"
              % (ns, nds, elapsed, ns / elapsed, nds / elapsed), file=sys.stderr)
开发者ID:yarikoptic,项目名称:GitPython,代码行数:50,代码来源:test_commit.py

示例3: newcommit

# 需要导入模块: from git import Commit [as 别名]
# 或者: from git.Commit import binsha [as 别名]
def newcommit(repo, message, date, name=None, email=None):
    """Creates a commit object with a custom date.
    :param repo: Repo object the commit should be part of
    :param tree: Tree object
    :param message: Commit message. It may be an empty string
                    if no message is provided.
    :param date: Date in seconds, as an Int
    :return: Commit object representing the new commit
    :note:
        Additional information about the committer and Author are taken from
        the git configuration
    """

    tree = repo.index.write_tree()
    try:
        parents = [repo.head.commit]
    except ValueError:
        parents = []

    # Committer and Author info
    cr = repo.config_reader()
    if name == None or email == None:
        actor = Actor.committer(cr)
    else:
        actor = Actor(name, email)

    committer = actor
    author = actor

    # Date
    # offset = altzone # 3600*offsethours
    offset = 0  # UTC

    author_time, author_offset = date, offset
    committer_time, committer_offset = date, offset

    # assume utf8 encoding
    enc_section, enc_option = Commit.conf_encoding.split('.')
    conf_encoding = cr.get_value(enc_section,
                                 enc_option,
                                 Commit.default_encoding)

    # Create New Commit
    new_commit = Commit(repo, Commit.NULL_BIN_SHA, tree,
                    author, author_time, author_offset,
                    committer, committer_time, committer_offset,
                    message, parents, conf_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

    # Advance HEAD to the new commit automatically.
    # need late import here, importing git at the very beginning throws.
    import git.refs
    try:
        repo.head.set_commit(new_commit, logmsg="commit: %s" % message)
    except ValueError:
        # head is not yet set to the ref our HEAD points to
        # Happens on first commit
        import git.refs
        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)
    # END handle empty repositories
    return new_commit
开发者ID:davoclavo,项目名称:drawntributions,代码行数:72,代码来源:gitutils.py


注:本文中的git.Commit.binsha方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。