compact a tree by marking its non-leafs as missing, and return a list of revs to delete
557305
function compactTree(metadata) {
  var revs = [];
  traverseRevTree(metadata.rev_tree, function (isLeaf, pos,
                                               revHash, ctx, opts) {
    if (opts.status === 'available' && !isLeaf) {
      revs.push(pos + '-' + revHash);
      opts.status = 'missing';
    }
  });
  return revs;
}
700658
def _safe_rmtree(dir_: str):
    """"""
    try:
        rmtree(dir_)
    except OSError:
        logging.warning('\t\t Skipping %s due to OSError', dir_)
    else:
        logging.debug('\t\t Deleted %s', dir_)
777484
def subtree_leaf_positions(subtree):
    """"""
    relative_leaf_positions = subtree.treepositions('leaves')
    subtree_root_pos = subtree.treeposition()
    absolute_leaf_positions = []
    for rel_leaf_pos in relative_leaf_positions:
        absolute_leaf_positions.append( subtree_root_pos + rel_leaf_pos)
    return absolute_leaf_positions
155032
public List<InternalDocumentRevision> leafRevisions(boolean excludeDeleted) {
        List<InternalDocumentRevision> res = new ArrayList<InternalDocumentRevision>();
        for(DocumentRevisionNode obj : leafs()) {
            InternalDocumentRevision revision = obj.getData();
            if (!excludeDeleted || !revision.isDeleted()){
                res.add(revision);
            }
        }
        return res;
    }
529908
def _reatach(self):
        """"""
        for item, p, idx in self._detached:
            # The item may have been deleted.
            if self.treeview.exists(item) and self.treeview.exists(p):
                self.treeview.move(item, p, idx)
        self._detached = []
1267694
def get_tree_from_sha(self, ref):
        '''
        
        '''
        try:
            return self.repo.revparse_single(ref).tree
        except (KeyError, TypeError, ValueError, AttributeError):
            return None
1241521
def _eliminate_leafs(self, graph):
        
        result = []
        idset = set([id(x) for x in graph])
        for n in graph:
            refset = set([id(x) for x in get_referents(n)])
            if refset.intersection(idset):
                result.append(n)
        return result
329557
function SMALLER(tree, n, m) {
		return tree[n].fc < tree[m].fc || (tree[n].fc === tree[m].fc && depth[n] <= depth[m]);
	}
13978
def cleanup(self):
        
        if not self.pending_children:
            return

        nclist = [(n, find_cycle([n], set())) for n in self.pending_children]

        genuine_cycles = [
            node for node,cycle in nclist
                     if cycle or node.get_state() != NODE_EXECUTED
        ]
        if not genuine_cycles:
            # All of the "cycles" found were single nodes in EXECUTED state,
            # which is to say, they really weren't cycles.  Just return.
            return

        desc = 'Found dependency cycle(s):\n'
        for node, cycle in nclist:
            if cycle:
                desc = desc + "  " + " -> ".join(map(str, cycle)) + "\n"
            else:
                desc = desc + \
                    "  Internal Error: no cycle found for node %s (%s) in state %s\n" %  \
                    (node, repr(node), StateString[node.get_state()])

        raise SCons.Errors.UserError(desc)
125455
def get_leaves(self):
        """"""
        ret_set = set()
        for val in self.values():
            if isinstance(val, self.__class__):
                ret_set |= val.get_leaves()
            elif isinstance(val, dict):
                ret_set |= set(val.values())
            elif isinstance(val, list):
                ret_set |= set(val)
            elif isinstance(val, set):
                ret_set |= val
            else:
                ret_set.add(val)
        return ret_set
1034424
def _purge_unreachable(self, key):
        
        dels = []
        for p in self:
            if dominates(key, p):
                dels.append(p)
        for k in dels:
            _, idxs = find_in_tree(self.root, k, perfect=True)
            del_by_idx(self.root, idxs)
150372
def collapse_nodes(self, min_dist=1e-6, min_support=0):
        
        nself = self.copy()
        for node in nself.treenode.traverse():
            if not node.is_leaf():
                if (node.dist <= min_dist) | (node.support < min_support):
                    node.delete()
        nself._coords.update()
        return nself
162217
def all_leaves(self, graph=None):
        
        if graph is None:
            graph = self.graph
        return [key for key in graph if not graph[key]]
715881
def _cleanup(lst):
    '''
    
    '''
    clean = []
    for ele in lst:
        if ele and isinstance(ele, dict):
            clean.append(ele)
    return clean
736638
def prepare(self, left_tree, right_tree):
        """"""
        # We don't want to diff comments:
        self._remove_comments(left_tree)
        self._remove_comments(right_tree)

        self.placeholderer.do_tree(left_tree)
        self.placeholderer.do_tree(right_tree)
591565
def compact(paths):
    """"""

    sep = os.path.sep
    short_paths = set()
    for path in sorted(paths, key=len):
        should_skip = any(
            path.startswith(shortpath.rstrip("*")) and
            path[len(shortpath.rstrip("*").rstrip(sep))] == sep
            for shortpath in short_paths
        )
        if not should_skip:
            short_paths.add(path)
    return short_paths
767381
function traverseRevTree(revs, callback) {
  var toVisit = revs.slice();

  var node;
  while ((node = toVisit.pop())) {
    var pos = node.pos;
    var tree = node.ids;
    var branches = tree[2];
    var newCtx =
      callback(branches.length === 0, pos, tree[0], node.ctx, tree[1]);
    for (var i = 0, len = branches.length; i < len; i++) {
      toVisit.push({pos: pos + 1, ids: branches[i], ctx: newCtx});
    }
  }
}