コード例 #1
0
ファイル: infcmds.py プロジェクト: SeekingFor/infocalypse
def execute_create(ui_, repo, params, stored_cfg):
    """ Run the create command. """
    update_sm = None
    try:
        update_sm = setup(ui_, repo, params, stored_cfg)
        # REDFLAG: Do better.
        # This call is not necessary, but I do it to set
        # 'INVERTED_INSERT_URI'. Write code to fish that
        # out of INSERTING_URI instead.
        do_key_setup(ui_, update_sm, params, stored_cfg)

        ui_.status("%sInsert URI:\n%s\n" %
                   (is_redundant(params['INSERT_URI']), params['INSERT_URI']))
        #ui_.status("Current tip: %s\n" % hex_version(repo)[:12])

        update_sm.start_inserting(UpdateGraph(),
                                  params.get('TO_VERSIONS', ('tip', )),
                                  params['INSERT_URI'])

        run_until_quiescent(update_sm, params['POLL_SECS'])

        if update_sm.get_state(QUIESCENT).arrived_from(((FINISHING, ))):
            ui_.status("Inserted to:\n%s\n" % '\n'.join(
                update_sm.get_state(INSERTING_URI).get_request_uris()))
        else:
            ui_.status("Create failed.\n")

        handle_updating_config(repo, update_sm, params, stored_cfg)
    finally:
        cleanup(update_sm)
コード例 #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 test_update_real(repo_dir, version_list=None, full=False):
    """ Smoke test graph.update(). """
    ui_ = ui.ui()
    repo = hg.repository(ui_, repo_dir)
    cache = BundleCache(repo, ui_, CACHE_DIR)
    cache.remove_files()
    graph = UpdateGraph()
    if version_list is None:
        latest = repo['tip'].rev()
        version_list = [[
            ordinal,
        ] for ordinal in range(0, latest + 1)]

    chks = fake_chks()
    for vers in version_list:
        print "UPDATING TO: ", vers
        new_edges = graph.update(repo, ui, vers, cache)
        for edge in new_edges:
            length = graph.get_length(edge)
            graph.set_chk(edge[:2], edge[2], length, chks.next())

        # REDFLAG: should call minimal_graph for "real" behavior
        text = graph_to_string(graph)
        print "GRAPH_LEN: ", len(text)
        print text

    if full:
        print "UPDATING TO: latest heads"
        try:
            new_edges = graph.update(repo, ui, None, cache)
            for edge in new_edges:
                length = graph.get_length(edge)
                graph.set_chk(edge[:2], edge[2], length, chks.next())

            # REDFLAG: should call minimal_graph for "real" behavior
            text = graph_to_string(graph)
            print "GRAPH_LEN: ", len(text)
            print text
        except UpToDate:
            print "Already has the head revs."

    return (graph, repo, cache)
コード例 #5
0
ファイル: graphutil.py プロジェクト: ArneBab/infocalypse
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
コード例 #6
0
ファイル: test_graph.py プロジェクト: ArneBab/infocalypse
def test_update_real(repo_dir, version_list=None, full=False):
    """ Smoke test graph.update(). """
    ui_ = ui.ui()
    repo = hg.repository(ui_, repo_dir)
    cache = BundleCache(repo, ui_, CACHE_DIR)
    cache.remove_files()
    graph = UpdateGraph()
    if version_list is None:
        latest = repo['tip'].rev()
        version_list = [[ordinal, ] for ordinal in range(0, latest + 1)]

    chks = fake_chks()
    for vers in version_list:
        print "UPDATING TO: ", vers
        new_edges = graph.update(repo, ui, vers, cache)
        for edge in new_edges:
            length = graph.get_length(edge)
            graph.set_chk(edge[:2], edge[2], length, chks.next())

        # REDFLAG: should call minimal_graph for "real" behavior
        text = graph_to_string(graph)
        print "GRAPH_LEN: ", len(text)
        print text

    if full:
        print "UPDATING TO: latest heads"
        try:
            new_edges = graph.update(repo, ui, None, cache)
            for edge in new_edges:
                length = graph.get_length(edge)
                graph.set_chk(edge[:2], edge[2], length, chks.next())

            # REDFLAG: should call minimal_graph for "real" behavior
            text = graph_to_string(graph)
            print "GRAPH_LEN: ", len(text)
            print text
        except UpToDate:
            print "Already has the head revs."

    return (graph, repo, cache)
コード例 #7
0
ファイル: graphutil.py プロジェクト: ArneBab/infocalypse
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
コード例 #8
0
ファイル: test_graph.py プロジェクト: ArneBab/infocalypse
def test_presentation():
    """ Smoke test graph_to_string and parse_graph. """
    graph = UpdateGraph()
    print "EMPTY:"
    print graph_to_string(graph)
    print "Adding index: ", graph.add_index([VER_1, ], [VER_2, ])
    print "Adding index: ", graph.add_index([VER_2, ], [VER_3, VER_4])
    print "Adding index: ", graph.add_index([VER_3, VER_2], [VER_5, ])
    chks = fake_chks()
    graph.add_edge((-1, 0), (100, chks.next()))
    graph.add_edge((1, 2), (200, chks.next()))
    graph.add_edge((-1, 2), (500, chks.next()))
    text = graph_to_string(graph)
    print
    print text
    print
    graph1 = parse_graph(text)
    print
    text1 = graph_to_string(graph1)
    print "Round trip:"
    print text1
    assert text == text1
コード例 #9
0
def test_update(repo_dir):
    """ OBSOLETE? """
    ui_ = ui.ui()
    repo = hg.repository(ui_, repo_dir)
    cache = BundleCache(repo, ui_, CACHE_DIR)
    cache.remove_files()
    graph = UpdateGraph()
    graph.update(repo, ui, [1, 2], cache)
    print graph_to_string(graph)
    print
    print
    graph.update(repo, ui, [3, 4], cache)

    print graph_to_string(graph)
    print
    print
    graph.update(repo, ui, [
        6,
    ], cache)

    print graph_to_string(graph)
コード例 #10
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
コード例 #11
0
ファイル: test_graph.py プロジェクト: ArneBab/infocalypse
def test_update(repo_dir):
    """ OBSOLETE? """
    ui_ = ui.ui()
    repo = hg.repository(ui_, repo_dir)
    cache = BundleCache(repo, ui_, CACHE_DIR)
    cache.remove_files()
    graph = UpdateGraph()
    graph.update(repo, ui, [1, 2], cache)
    print graph_to_string(graph)
    print
    print
    graph.update(repo, ui, [3, 4], cache)

    print graph_to_string(graph)
    print
    print
    graph.update(repo, ui, [6, ], cache)

    print graph_to_string(graph)
コード例 #12
0
ファイル: graphutil.py プロジェクト: ArneBab/infocalypse
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
コード例 #13
0
ファイル: test_graph.py プロジェクト: ArneBab/infocalypse
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', )))
コード例 #14
0
def test_presentation():
    """ Smoke test graph_to_string and parse_graph. """
    graph = UpdateGraph()
    print "EMPTY:"
    print graph_to_string(graph)
    print "Adding index: ", graph.add_index([
        VER_1,
    ], [
        VER_2,
    ])
    print "Adding index: ", graph.add_index([
        VER_2,
    ], [VER_3, VER_4])
    print "Adding index: ", graph.add_index([VER_3, VER_2], [
        VER_5,
    ])
    chks = fake_chks()
    graph.add_edge((-1, 0), (100, chks.next()))
    graph.add_edge((1, 2), (200, chks.next()))
    graph.add_edge((-1, 2), (500, chks.next()))
    text = graph_to_string(graph)
    print
    print text
    print
    graph1 = parse_graph(text)
    print
    text1 = graph_to_string(graph1)
    print "Round trip:"
    print text1
    assert text == text1
コード例 #15
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', )))