def test_minimal_graph(repo_dir, version_list, file_name=None): """ Smoke test minimal_graph(). """ ui_ = ui.ui() if file_name is None: graph, repo, cache = test_update_real(repo_dir, version_list, True) open('/tmp/latest_graph.txt', 'wb').write(graph_to_string(graph)) else: repo = hg.repository(ui_, repo_dir) cache = BundleCache(repo, ui_, CACHE_DIR) cache.remove_files() graph = parse_graph(open(file_name, 'rb').read()) print "--- from file: %s ---" % file_name print graph_to_string(graph) version_map = build_version_table(graph, repo) # Incomplete, but better than nothing. # Verify that the chk bounds are the same after shrinking. chk_bounds = {} initial_edges = graph.get_top_key_edges() for edge in initial_edges: chk_bounds[graph.get_chk(edge)] = ( get_rollup_bounds(graph, repo, edge[0] + 1, edge[1], version_map)) print "CHK BOUNDS:" for value in chk_bounds: print value print " ", chk_bounds[value] print sizes = (512, 1024, 2048, 4096, 16 * 1024) for max_size in sizes: try: print "MAX:", max(version_map.values()) small = minimal_graph(graph, repo, version_map, max_size) print "--- size == %i" % max_size print graph_to_string(small) small.rep_invariant(repo, True) # Full check chks = chk_bounds.keys() path = small.get_top_key_edges() print "TOP KEY EDGES:" print path for edge in path: # MUST rebuild the version map because the indices changed. new_map = build_version_table(small, repo) bounds = get_rollup_bounds(small, repo, edge[0] + 1, edge[1], new_map) print "CHK:", small.get_chk(edge) print "BOUNDS: ", bounds assert chk_bounds[small.get_chk(edge)] == bounds print "DELETING: ", edge, small.get_chk(edge) chks.remove(small.get_chk(edge)) assert len(chks) == 0 except UpdateGraphException, err: print "IGNORED: ", err
def test_minimal_graph(repo_dir, version_list, file_name=None): """ Smoke test minimal_graph(). """ ui_ = ui.ui() if file_name is None: graph, repo, cache = test_update_real(repo_dir, version_list, True) open('/tmp/latest_graph.txt', 'wb').write(graph_to_string(graph)) else: repo = hg.repository(ui_, repo_dir) cache = BundleCache(repo, ui_, CACHE_DIR) cache.remove_files() graph = parse_graph(open(file_name, 'rb').read()) print "--- from file: %s ---" % file_name print graph_to_string(graph) version_map = build_version_table(graph, repo) # Incomplete, but better than nothing. # Verify that the chk bounds are the same after shrinking. chk_bounds = {} initial_edges = graph.get_top_key_edges() for edge in initial_edges: chk_bounds[graph.get_chk(edge)] = (get_rollup_bounds( graph, repo, edge[0] + 1, edge[1], version_map)) print "CHK BOUNDS:" for value in chk_bounds: print value print " ", chk_bounds[value] print sizes = (512, 1024, 2048, 4096, 16 * 1024) for max_size in sizes: try: print "MAX:", max(version_map.values()) small = minimal_graph(graph, repo, version_map, max_size) print "--- size == %i" % max_size print graph_to_string(small) small.rep_invariant(repo, True) # Full check chks = chk_bounds.keys() path = small.get_top_key_edges() print "TOP KEY EDGES:" print path for edge in path: # MUST rebuild the version map because the indices changed. new_map = build_version_table(small, repo) bounds = get_rollup_bounds(small, repo, edge[0] + 1, edge[1], new_map) print "CHK:", small.get_chk(edge) print "BOUNDS: ", bounds assert chk_bounds[small.get_chk(edge)] == bounds print "DELETING: ", edge, small.get_chk(edge) chks.remove(small.get_chk(edge)) assert len(chks) == 0 except UpdateGraphException, err: print "IGNORED: ", err
def setup(ui_, repo, params, stored_cfg): """ INTERNAL: Setup to run an Infocalypse extension command. """ # REDFLAG: choose another name. Confusion w/ fcp param # REDFLAG: add an hg param and get rid of this line. #params['VERBOSITY'] = 1 check_uri(ui_, params.get('INSERT_URI')) check_uri(ui_, params.get('REQUEST_URI')) if not is_writable(os.path.expanduser(stored_cfg.defaults['TMP_DIR'])): raise util.Abort("Can't write to temp dir: %s\n" % stored_cfg.defaults['TMP_DIR']) verbosity = params.get('VERBOSITY', 1) set_debug_vars(verbosity, params) callbacks = UICallbacks(ui_) callbacks.verbosity = verbosity if not repo is None: # BUG:? shouldn't this be reading TMP_DIR from stored_cfg cache = BundleCache(repo, ui_, params['TMP_DIR']) try: async_socket = PolledSocket(params['FCP_HOST'], params['FCP_PORT']) connection = FCPConnection(async_socket, True, callbacks.connection_state) except socket.error, err: # Not an IOError until 2.6. ui_.warn("Connection to FCP server [%s:%i] failed.\n" % (params['FCP_HOST'], params['FCP_PORT'])) raise err
def setup_sm(ui_, repo, runner, params): """ INTERNAL: Helper function which sets up an UpdateStateMachine instance. """ assert is_writable(os.path.expanduser(params['TMP_DIR'])) verbosity = params.get('VERBOSITY', 1) set_debug_vars(verbosity, params) callbacks = UICallbacks(ui_) callbacks.verbosity = verbosity # DCI: bundle cache needed for inserting? cache = BundleCache(repo, ui_, params['TMP_DIR']) # For Infocalypse repositories ctx = UpdateContext(None) ctx.repo = repo ctx.ui_ = ui_ ctx.bundle_cache = cache update_sm = UpdateStateMachine(runner, ctx) update_sm.params = params.copy() update_sm.transition_callback = callbacks.transition_callback update_sm.monitor_callback = callbacks.monitor_callback # Modify only after copy. update_sm.params['FREENET_BUILD'] = runner.connection.node_hello[1][ 'Build'] return update_sm
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)
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)
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)
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)
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', )))
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', )))