1

私はダルウィッチに基づいて機能するチェックアウト機能を持っています:

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ラインの代わりになるものはありますか?

4

2 に答える 2

0

build_index_from_tree() の内容をインライン化し、if ステートメントを追加して、パスで始まる entry.path を持たないエントリを除外します。

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)
于 2016-01-14T15:07:33.880 に答える
0

ジェルマーは以前にこれに答えたようです: http://www.aaronheld.com/post/using-python-dulwich-to-load-any-version-of-a-file-from-a-local-git -レポ

于 2016-01-14T15:03:03.590 に答える