def merge_deps(old, new):
    """
    Merge two dependency lists.  The lists are partially ordered, with
    all dependents coming after the items they depend on, but otherwise
    order doesn't matter.  The merged list preserves the partial ordering.
    So if old and new both include the item "c", then all items that come
    before "c" in old and new will come before "c" in the result, and all
    items that come after "c" in old and new will come after "c" in the
    result.
    """
    if new is None:
        return old

    result = []
    for item in new:
        try:
            index = old.index(item)
            #print(item,"found in",old,"at",index,"giving",old[:index])
            result.extend(old[:index])
            old = old[index+1:]
        except ValueError:
            #print(item, "not found in", old)
            pass
        result.append(item)
        #print("after", item, "old", old, "result", result)
    result.extend(old)
    return result