首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用dulwich签出特定的文件或目录

如何使用dulwich签出特定的文件或目录
EN

Stack Overflow用户
提问于 2016-01-14 12:18:52
回答 2查看 264关注 0票数 1

我有一个基于dulwich的工作结账功能:

代码语言:javascript
复制
def checkout(repo, ref=None):
    if ref is None:
        ref = repo.head()
    index = repo.index_path()
    tree_id = repo[ref].tree
    build_index_from_tree(repo.path, index, repo.object_store, tree_id)
    return [repo.object_store.iter_tree_contents(tree_id)]

但是我如何修改它以签出一个单独的文件或目录呢?

有什么东西可以取代build_index_from_tree线吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-01-14 15:07:33

内联build_index_from_tree()的内容,然后添加一个if语句,以筛选出没有以路径开头的entry.path的任何条目:

代码语言:javascript
复制
if subpath[-1] != "/":
    subpath += "/"

if not isinstance(root_path, bytes):
    root_path = root_path.encode(sys.getfilesystemencoding())

for entry in object_store.iter_tree_contents(tree_id):
    if not validate_path(entry.path, validate_path_element_default):
        continue
    # new lines added here:
    if not entry.path.startswith(subpath):
        continue
    full_path = _tree_to_fs_path(root_path, entry.path[len(subpath):])

    if not os.path.exists(os.path.dirname(full_path)):
        os.makedirs(os.path.dirname(full_path))

    obj = object_store[entry.sha]
    build_file_from_blob(obj, entry.mode, full_path)
票数 0
EN

Stack Overflow用户

发布于 2016-01-14 15:03:03

看起来杰尔默之前可能回答过这个问题:http://www.aaronheld.com/post/using-python-dulwich-to-load-any-version-of-a-file-from-a-local-git-repo

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34789452

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档