예제 #1
0
def subgraph(graph, repo, version_table, containing_paths):
    """ Return a subgraph which contains the vertices and
    edges in containing_paths. """
    graph.rep_invariant()
    small_graph = UpdateGraph()
    max_index = -1

    # Copy edges and indices.
    for path in containing_paths:
        for step in path:
            pair = step[:2]
            # REDFLAG: copies ALL redundant paths
            small_graph.edge_table[pair] = graph.edge_table[pair][:]
            for index in pair:
                if index not in small_graph.index_table:
                    # Don't need to deep copy because index info is
                    # immutable. (a tuple)
                    small_graph.index_table[index] = graph.index_table[index]
                max_index = max(max_index, index)

    small_graph.latest_index = max_index

    # Fix contiguousness.
    coalesce_indices(graph, small_graph, repo, version_table)

    # Invariants should be fixed.
    small_graph.rep_invariant()
    graph.rep_invariant()

    return small_graph
예제 #2
0
def subgraph(graph, repo, version_table, containing_paths):
    """ Return a subgraph which contains the vertices and
    edges in containing_paths. """
    graph.rep_invariant()
    small_graph = UpdateGraph()
    max_index = -1

    # Copy edges and indices.
    for path in containing_paths:
        for step in path:
            pair = step[:2]
            # REDFLAG: copies ALL redundant paths
            small_graph.edge_table[pair] = graph.edge_table[pair][:]
            for index in pair:
                if index not in small_graph.index_table:
                    # Don't need to deep copy because index info is
                    # immutable. (a tuple)
                    small_graph.index_table[index] = graph.index_table[index]
                max_index = max(max_index, index)

    small_graph.latest_index = max_index

    # Fix contiguousness.
    coalesce_indices(graph, small_graph, repo, version_table)

    # Invariants should be fixed.
    small_graph.rep_invariant()
    graph.rep_invariant()

    return small_graph
예제 #3
0
def parse_graph(text):
    """ Returns a graph parsed from text.
        text must be in the format used by graph_to_string().
        Lines starting with '#' are ignored.
    """

    graph = UpdateGraph()
    lines = text.split('\n')
    for line in lines:
        fields = line.split(':')
        if fields[0] == 'I':
            fields.pop(0)
            try:
                if len(fields) == 0:
                    raise ValueError("HACK")
                index = int(fields.pop(0))
            except ValueError:
                raise ValueError("Syntax error reading index")
            try:
                divider = fields.index('|')
            except ValueError:
                raise ValueError("Syntax error reading index %i" % index)
            parents = fields[:divider]
            heads = fields[divider + 1:]

            if index in graph.index_table:
                print "OVERWRITING INDEX: ", index
            if len(parents) < 1:
                raise ValueError("index %i has no parent revs" % index)
            if len(heads) < 1:
                raise ValueError("index %i has no head revs" % index)

            graph.index_table[index] = (tuple(parents), tuple(heads))
        elif fields[0] == 'E':
            #print fields
            if len(fields) < 5:
                raise ValueError("Exception parsing edge values.")
            index_pair = (int(fields[1]), int(fields[2]))
            length = int(fields[3])
            chk_list = []
            for chk in fields[4:]:
                chk_list.append(chk)
            graph.edge_table[index_pair] = tuple([
                length,
            ] + chk_list)
        #else:
        #    print "SKIPPED LINE:"
        #    print line
    indices = graph.index_table.keys()
    if len(indices) == 0:
        raise ValueError("No indices?")
    indices.sort()
    graph.latest_index = indices[-1]

    graph.rep_invariant()

    return graph
예제 #4
0
def parse_graph(text):
    """ Returns a graph parsed from text.
        text must be in the format used by graph_to_string().
        Lines starting with '#' are ignored.
    """

    graph = UpdateGraph()
    lines = text.split('\n')
    for line in lines:
        fields = line.split(':')
        if fields[0] == 'I':
            fields.pop(0)
            try:
                if len(fields) == 0:
                    raise ValueError("HACK")
                index = int(fields.pop(0))
            except ValueError:
                raise ValueError("Syntax error reading index")
            try:
                divider = fields.index('|')
            except ValueError:
                raise ValueError("Syntax error reading index %i" % index)
            parents = fields[:divider]
            heads = fields[divider + 1:]

            if index in graph.index_table:
                print "OVERWRITING INDEX: " , index
            if len(parents) < 1:
                raise ValueError("index %i has no parent revs" % index)
            if len(heads) < 1:
                raise ValueError("index %i has no head revs" % index)

            graph.index_table[index] = (tuple(parents), tuple(heads))
        elif fields[0] == 'E':
            #print fields
            if len(fields) < 5:
                raise ValueError("Exception parsing edge values.")
            index_pair = (int(fields[1]), int(fields[2]))
            length = int(fields[3])
            chk_list = []
            for chk in fields[4:]:
                chk_list.append(chk)
            graph.edge_table[index_pair] = tuple([length, ] + chk_list)
        #else:
        #    print "SKIPPED LINE:"
        #    print line
    indices = graph.index_table.keys()
    if len(indices) == 0:
        raise ValueError("No indices?")
    indices.sort()
    graph.latest_index = indices[-1]

    graph.rep_invariant()

    return graph
예제 #5
0
def parse_v100_graph(text):
    """ Returns a graph parsed from text in old format.
        text must be in the format used by graph_to_string().
        Lines starting with '#' are ignored.
    """

    graph = UpdateGraph()
    lines = text.split('\n')
    for line in lines:
        fields = line.split(':')
        if fields[0] == 'I':
            if len(fields) != 4:
                raise ValueError("Exception parsing index values.")
            index = int(fields[1])
            if index in graph.index_table:
                print "OVERWRITING INDEX: ", index
            if len(tuple(fields[2:])) != 2:
                raise ValueError("Error parsing index value: %i" % index)
            versions = tuple(fields[2:])
            graph.index_table[index] = ((versions[0], ), (versions[1], ))
        elif fields[0] == 'E':
            #print fields
            if len(fields) < 5:
                raise ValueError("Exception parsing edge values.")
            index_pair = (int(fields[1]), int(fields[2]))
            length = int(fields[3])
            chk_list = []
            for chk in fields[4:]:
                chk_list.append(chk)
            graph.edge_table[index_pair] = tuple([
                length,
            ] + chk_list)
        #else:
        #    print "SKIPPED LINE:"
        #    print line
    indices = graph.index_table.keys()
    if len(indices) == 0:
        raise ValueError("No indices?")
    indices.sort()
    graph.latest_index = indices[-1]

    graph.rep_invariant()

    return graph
예제 #6
0
def parse_v100_graph(text):
    """ Returns a graph parsed from text in old format.
        text must be in the format used by graph_to_string().
        Lines starting with '#' are ignored.
    """

    graph = UpdateGraph()
    lines = text.split('\n')
    for line in lines:
        fields = line.split(':')
        if fields[0] == 'I':
            if len(fields) != 4:
                raise ValueError("Exception parsing index values.")
            index = int(fields[1])
            if index in graph.index_table:
                print "OVERWRITING INDEX: " , index
            if len(tuple(fields[2:])) != 2:
                raise ValueError("Error parsing index value: %i" % index)
            versions = tuple(fields[2:])
            graph.index_table[index] = ((versions[0], ), (versions[1], ))
        elif fields[0] == 'E':
            #print fields
            if len(fields) < 5:
                raise ValueError("Exception parsing edge values.")
            index_pair = (int(fields[1]), int(fields[2]))
            length = int(fields[3])
            chk_list = []
            for chk in fields[4:]:
                chk_list.append(chk)
            graph.edge_table[index_pair] = tuple([length, ] + chk_list)
        #else:
        #    print "SKIPPED LINE:"
        #    print line
    indices = graph.index_table.keys()
    if len(indices) == 0:
        raise ValueError("No indices?")
    indices.sort()
    graph.latest_index = indices[-1]

    graph.rep_invariant()

    return graph
예제 #7
0
def test_rollup():
    """ Smoke test get_rollup_bounds(). """
    repo, ui_ = setup_rollup_test_repo(TST_REPO_DIR)
    dump_changesets(repo)
    cache = BundleCache(repo, ui_, CACHE_DIR)
    cache.remove_files()
    graph = UpdateGraph()

    chks = fake_chks()
    # 0 Single changeset
    edges = graph.update(repo, ui_, ['716c293192c7', ], cache)
    set_chks(graph, edges, chks)
    # 1 Multiple changesets
    edges = graph.update(repo, ui_, ['076aec9f34c9', ], cache)
    set_chks(graph, edges, chks)
    # 2 Multiple heads, single base
    edges = graph.update(repo, ui_, ['62a72a238ffc', '4409936ef21f'], cache)
    set_chks(graph, edges, chks)
    # 3 Multiple bases, single head
    edges = graph.update(repo, ui_, ['a2c749d99d54', ], cache)
    set_chks(graph, edges, chks)
    # 4
    edges = graph.update(repo, ui_, ['f6248cd464e3', ], cache)
    set_chks(graph, edges, chks)
    # 5
    edges = graph.update(repo, ui_, ['fd1e6832820b', ], cache)
    set_chks(graph, edges, chks)
    # 6
    edges = graph.update(repo, ui_, ['7429bf7b11f5', ], cache)
    set_chks(graph, edges, chks)
    # 7
    edges = graph.update(repo, ui_, ['fcc2e90dbf0d', ], cache)
    set_chks(graph, edges, chks)
    # 8
    edges = graph.update(repo, ui_, ['03c047d036ca', ], cache)
    set_chks(graph, edges, chks)

    # 9
    edges = graph.update(repo, ui_, ['2f6c65f64ce5', ], cache)
    set_chks(graph, edges, chks)

    print
    print graph_to_string(graph)
    version_map = build_version_table(graph, repo)

    dump_version_map(version_map)
    assert version_map == EXPECTED_VERSION_MAP

    graph.rep_invariant(repo, True) # Verify contiguousness.

    print "From earliest..."
    for index in range(0, graph.latest_index + 1):
        parents, heads = get_rollup_bounds(graph, repo, 0, index, version_map)
        print "(%i->%i): %s" % (0, index, versions_str(heads))
        print "       ", versions_str(parents)


    print "To latest..."
    for index in range(0, graph.latest_index + 1):
        parents, heads = get_rollup_bounds(graph, repo, index,
                                           graph.latest_index,
                                           version_map)
        print "(%i->%i): %s" % (index, graph.latest_index, versions_str(heads))
        print "       ", versions_str(parents)


    # Empty
    try:
        get_rollup_bounds(graph, repo, FIRST_INDEX, FIRST_INDEX,
                          version_map)
    except AssertionError:
        # Asserted as expected for to_index == FIRST_INDEX
        print "Got expected assertion."

    # Rollup of one changeset index.
    result = get_rollup_bounds(graph, repo, 0, 0, version_map)
    check_result(result, (('000000000000', ), ('716c293192c7',)))

    # Rollup of multiple changeset index.
    result = get_rollup_bounds(graph, repo, 1, 1, version_map)
    check_result(result, (('716c293192c7', ), ('076aec9f34c9',)))

    # Rollup of with multiple heads.
    result = get_rollup_bounds(graph, repo, 1, 2, version_map)
    check_result(result, (('716c293192c7', ), ('4409936ef21f','62a72a238ffc')))

    # Rollup of with multiple bases.
    result = get_rollup_bounds(graph, repo, 3, 4, version_map)
    check_result(result, (('4409936ef21f', '62a72a238ffc', ),
                          ('f6248cd464e3',)))

    # Rollup with head pulled in from earlier base.
    result = get_rollup_bounds(graph, repo, 3, 8, version_map)
    print result
    check_result(result, (('4409936ef21f', '62a72a238ffc', ),
                          ('03c047d036ca', '7429bf7b11f5')))

    # Rollup after remerge to a single head.
    result = get_rollup_bounds(graph, repo, 0, 9, version_map)
    print result
    check_result(result, (('000000000000', ), ('2f6c65f64ce5', )))
예제 #8
0
def test_rollup():
    """ Smoke test get_rollup_bounds(). """
    repo, ui_ = setup_rollup_test_repo(TST_REPO_DIR)
    dump_changesets(repo)
    cache = BundleCache(repo, ui_, CACHE_DIR)
    cache.remove_files()
    graph = UpdateGraph()

    chks = fake_chks()
    # 0 Single changeset
    edges = graph.update(repo, ui_, [
        '716c293192c7',
    ], cache)
    set_chks(graph, edges, chks)
    # 1 Multiple changesets
    edges = graph.update(repo, ui_, [
        '076aec9f34c9',
    ], cache)
    set_chks(graph, edges, chks)
    # 2 Multiple heads, single base
    edges = graph.update(repo, ui_, ['62a72a238ffc', '4409936ef21f'], cache)
    set_chks(graph, edges, chks)
    # 3 Multiple bases, single head
    edges = graph.update(repo, ui_, [
        'a2c749d99d54',
    ], cache)
    set_chks(graph, edges, chks)
    # 4
    edges = graph.update(repo, ui_, [
        'f6248cd464e3',
    ], cache)
    set_chks(graph, edges, chks)
    # 5
    edges = graph.update(repo, ui_, [
        'fd1e6832820b',
    ], cache)
    set_chks(graph, edges, chks)
    # 6
    edges = graph.update(repo, ui_, [
        '7429bf7b11f5',
    ], cache)
    set_chks(graph, edges, chks)
    # 7
    edges = graph.update(repo, ui_, [
        'fcc2e90dbf0d',
    ], cache)
    set_chks(graph, edges, chks)
    # 8
    edges = graph.update(repo, ui_, [
        '03c047d036ca',
    ], cache)
    set_chks(graph, edges, chks)

    # 9
    edges = graph.update(repo, ui_, [
        '2f6c65f64ce5',
    ], cache)
    set_chks(graph, edges, chks)

    print
    print graph_to_string(graph)
    version_map = build_version_table(graph, repo)

    dump_version_map(version_map)
    assert version_map == EXPECTED_VERSION_MAP

    graph.rep_invariant(repo, True)  # Verify contiguousness.

    print "From earliest..."
    for index in range(0, graph.latest_index + 1):
        parents, heads = get_rollup_bounds(graph, repo, 0, index, version_map)
        print "(%i->%i): %s" % (0, index, versions_str(heads))
        print "       ", versions_str(parents)

    print "To latest..."
    for index in range(0, graph.latest_index + 1):
        parents, heads = get_rollup_bounds(graph, repo, index,
                                           graph.latest_index, version_map)
        print "(%i->%i): %s" % (index, graph.latest_index, versions_str(heads))
        print "       ", versions_str(parents)

    # Empty
    try:
        get_rollup_bounds(graph, repo, FIRST_INDEX, FIRST_INDEX, version_map)
    except AssertionError:
        # Asserted as expected for to_index == FIRST_INDEX
        print "Got expected assertion."

    # Rollup of one changeset index.
    result = get_rollup_bounds(graph, repo, 0, 0, version_map)
    check_result(result, (('000000000000', ), ('716c293192c7', )))

    # Rollup of multiple changeset index.
    result = get_rollup_bounds(graph, repo, 1, 1, version_map)
    check_result(result, (('716c293192c7', ), ('076aec9f34c9', )))

    # Rollup of with multiple heads.
    result = get_rollup_bounds(graph, repo, 1, 2, version_map)
    check_result(result,
                 (('716c293192c7', ), ('4409936ef21f', '62a72a238ffc')))

    # Rollup of with multiple bases.
    result = get_rollup_bounds(graph, repo, 3, 4, version_map)
    check_result(result, ((
        '4409936ef21f',
        '62a72a238ffc',
    ), ('f6248cd464e3', )))

    # Rollup with head pulled in from earlier base.
    result = get_rollup_bounds(graph, repo, 3, 8, version_map)
    print result
    check_result(result, ((
        '4409936ef21f',
        '62a72a238ffc',
    ), ('03c047d036ca', '7429bf7b11f5')))

    # Rollup after remerge to a single head.
    result = get_rollup_bounds(graph, repo, 0, 9, version_map)
    print result
    check_result(result, (('000000000000', ), ('2f6c65f64ce5', )))