git.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:pomu 作者: Hummer12007 项目源码 文件源码
def parse_tree(blob, path=b''):
    """Parses a git tree"""
    res = []
    leng, _, tree = blob.partition(b'\0')
    if path is str:
        path = path.encode('utf-8')
    if not tree:
        return Result.Err('Invalid tree')
    while len(tree) > 0:
        mode, _, tree = tree.partition(b' ')
        name, _, tree = tree.partition(b'\0')
        sha = b16encode(tree[0:20]).decode('utf-8').lower()
        tree = tree[20:]
        if not name or not sha:
            return Result.Err()
        is_dir = mode[0:1] != b'1'
        res.append((is_dir, sha, path + b'/' + name))
    return Result.Ok(res)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号