def walk_trees(store, tree_ids, prune_identical=False):
    """Recursively walk all the entries of N trees.

    Iteration is depth-first pre-order, as in e.g. os.walk.

    :param store: An ObjectStore for looking up objects.
    :param trees: iterable of SHAs for N trees
    :param prune_identical: If True, identical subtrees will not be walked.
    :return: Iterator over tuple contsining N TreeEntry objects for each of entries
        in the trees and their subtrees recursively. If an entry exists in one
        tree but not the other, the other entry will have all attributes set
        to None. If neither entry's path is None, they are guaranteed to
        match.
    """
    # This could be fairly easily generalized to >2 trees if we find a use
    # case.
    modes = [tree_id and stat.S_IFDIR or None for tree_id in tree_ids]
    todo = [[TreeEntry(b'', mode, tree_id) for mode, tree_id in zip(modes, tree_ids)]]

    while todo:
        entries = todo.pop()
        is_trees = [_is_tree(entry) for entry in entries]

        if prune_identical and all(is_trees) and all_eq(entries):
            continue

        trees = [is_tree and store[entry.sha] or None for is_tree, entry in zip(is_trees, entries)]

        path = first_nonempty([entry.path for entry in entries])
        todo.extend(reversed(_merge_entries(path, trees)))
        yield tuple(entries)
Recursively walk all the entries of N trees.

    Iteration is depth-first pre-order, as in e.g. os.walk.

    :param store: An ObjectStore for looking up objects.
    :param trees: iterable of SHAs for N trees
    :param prune_identical: If True, identical subtrees will not be walked.
    :return: Iterator over tuple contsining N TreeEntry objects for each of entries
        in the trees and their subtrees recursively. If an entry exists in one
        tree but not the other, the other entry will have all attributes set
        to None. If neither entry's path is None, they are guaranteed to
        match.
    
lib/git/git-merge.py