# # # patch "asciik.cc" # from [126edae521da35da59efa72dae7a63f6dd2d4f7f] # to [28b20f53816beee894500a47e22faabe0085a9be] # ============================================================ --- asciik.cc 126edae521da35da59efa72dae7a63f6dd2d4f7f +++ asciik.cc 28b20f53816beee894500a47e22faabe0085a9be @@ -1,3 +1,4 @@ +// Copyright (C) 2006 Nathaniel Smith // Copyright (C) 2007 Lapo Luchini // Copyright (C) 2007 Gabriele Dini Ciacci // @@ -139,13 +140,6 @@ static revision_id ghost; // valid but e static revision_id ghost; // valid but empty revision_id to be used as ghost value -//p def links_cross(links): -//p crosses = set() -//p for i, j in links: -//p if i != j: -//p for coord in xrange(2 * min(i, j) + 1, 2 * max(i, j)): -//p crosses.add(coord) -//p return crosses void links_cross(const set > & links, set & crosses) { for (set >::const_iterator link = links.begin(); @@ -163,106 +157,67 @@ void draw(const size_t curr_items, const const size_t curr_loc, const set > & links, const set & curr_ghosts, const string & annotation) { - std::cerr << "actual draw\n"; - std::cerr << "curr_items: " << curr_items << '\n'; - std::cerr << "next_items: " << next_items << '\n'; -//p line = [" "] * (curr_items * 2 - 1) -//p interline = [" "] * (max(curr_items, next_items) * 2 - 1) string line(curr_items * 2 - 1, ' '); string interline(max(curr_items, next_items) * 2 - 1, ' '); -//p # first draw the flow-through bars in the line -//p for i in xrange(curr_items): -//p line[i * 2] = "|" - std::cerr << "some |\n"; + // first draw the flow-through bars in the line for (size_t i = 0; i < curr_items; ++i) line[i * 2] = '|'; -//p # but then erase it for ghosts -//p for i in curr_ghosts: -//p line[i * 2] = " " - std::cerr << "some space\n"; + // but then erase it for ghosts for (set::const_iterator i = curr_ghosts.begin(); i != curr_ghosts.end(); ++i) line[(*i) * 2] = ' '; - std::cerr << "dots\n"; -//p # then the links -//p dots = set() + // then the links set dots; -//p for i, j in links: for (set >::const_iterator link = links.begin(); link != links.end(); ++link) { size_t i = link->first, j = link->second, start, end, dot; -//p if i == j: -//p interline[2 * i] = "|" - std::cerr << "foreach link (" << i << ", " << j << ")\n"; if (i == j) interline[2 * i] = '|'; -//p else: else { if (j < i) { -//p if j < i: -//p # | .---o -//p # |/| | | -//p # 0 1 2 3 -//p # j i -//p # 0123456 -//p # s e -//p start = 2*j + 3 -//p end = 2*i -//p dot = start - 1 -//p interline[dot - 1] = "/" + // | .---o + // |/| | | + // 0 1 2 3 + // j i + // 0123456 + // s e start = 2 * j + 3; end = 2 * i; dot = start - 1; interline[dot - 1] = '/'; - } else { -//p else: # i < j -//p # o---. -//p # | | |\| -//p # 0 1 2 3 -//p # i j -//p # 0123456 -//p # s e -//p start = 2*i + 1 -//p end = 2*j - 2 -//p dot = end -//p interline[dot + 1] = "\\" + } else { // i < j + // o---. + // | | |\| + // 0 1 2 3 + // i j + // 0123456 + // s e start = 2 * i + 1; end = 2 * j - 2; dot = end; interline[dot + 1] = '\\'; - std::cerr << interline << " interline\n"; } -//p if end - start >= 1: -//p dots.add(dot) -//p line[start:end] = "-" * (end - start) if ((end - start) > 0) dots.insert(dot); - std::cerr << "for with some - from " << start << " to " << end << "\n"; for (size_t l = start; l < end; ++l) line[l] = '-'; } } -//p # add any dots (must do this in a second pass, so that if there are -//p # cases like: -//p # | .-----.-o -//p # |/| | |/| -//p # where we want to make sure the second dot overwrites the first --. -//p for dot in dots: -//p line[dot] = "." + // add any dots (must do this in a second pass, so that if there are + // cases like: + // | .-----.-o + // |/| | |/| + // where we want to make sure the second dot overwrites the first --. for (set::const_iterator dot = dots.begin(); dot != dots.end(); ++dot) line[*dot] = 'ยท'; - std::cerr << line << " line\n"; -//p # and add the main attraction (may overwrite a "."). -//p line[curr_loc * 2] = "o" + // and add the main attraction (may overwrite a "."). line[curr_loc * 2] = 'o'; -//p print "".join(line) + " " + annotation -//p print "".join(interline) cout << line << " " << annotation << '\n'; cout << interline << '\n'; } @@ -271,35 +226,15 @@ bool try_draw(const vector const vector & next_row, const size_t curr_loc, const set & parents) { - std::cerr << "try draw\n"; -//p curr_items = len(curr_row) -//p next_items = len(next_row) size_t curr_items = curr_row.size(); size_t next_items = next_row.size(); I(curr_loc < curr_items); -//p curr_ghosts = [] -//p for i in xrange(curr_items): -//p if curr_row[i] is None: -//p curr_ghosts.append(i) - std::cerr << "ghosts\n"; set curr_ghosts; for (size_t i = 0; i < curr_items; ++i) if (idx(curr_row, i) == ghost) curr_ghosts.insert(i); -//p preservation_links = [] -//p have_shift = False -//p for rev in curr_row: -//p if rev is not None and rev in next_row: -//p i = curr_row.index(rev) -//p j = next_row.index(rev) -//p if i != j: -//p have_shift = True -//p if abs(i - j) > 1: -//p return False -//p preservation_links.append((i, j)) - std::cerr << "pres links\n"; set > preservation_links; bool have_shift = false; for (size_t i = 0; i < curr_items; ++i) { @@ -314,25 +249,14 @@ bool try_draw(const vector if (d != 0) have_shift = true; preservation_links.insert(pair(i, j)); - std::cerr << '(' << i << ',' << j << ") "; } } } - std::cerr << "\n"; -//p parent_links = [] -//p for p in parents: -//p i = curr_loc -//p j = next_row.index(p) -//p if abs(i - j) > 1 and have_shift: -//p return False -//p parent_links.append((i, j)) - std::cerr << "par links\n"; set > parent_links; for (set::const_iterator p = parents.begin(); p != parents.end(); ++p) { - std::cerr << (*p).inner()() << " parent\n"; size_t i = curr_loc; size_t j = distance(next_row.begin(), find(next_row.begin(), next_row.end(), *p)); @@ -341,15 +265,8 @@ bool try_draw(const vector if ((d > 1) && have_shift) return false; parent_links.insert(pair(i, j)); - std::cerr << '(' << i << ',' << j << ") "; } - std::cerr << "\n"; -//p preservation_crosses = links_cross(preservation_links) -//p parent_crosses = links_cross(parent_links) -//p if preservation_crosses.intersection(parent_crosses): -//p return False - std::cerr << "crosses\n"; set preservation_crosses, parent_crosses, intersection_crosses; links_cross(preservation_links, preservation_crosses); links_cross(parent_links, parent_crosses); @@ -360,20 +277,17 @@ bool try_draw(const vector if (intersection_crosses.size() > 0) return false; -//p links = preservation_links + parent_links -//p draw(curr_items, next_items, curr_loc, links, curr_ghosts, curr_row[curr_loc]) set > links(preservation_links); copy(parent_links.begin(), parent_links.end(), insert_iterator > >(links, links.begin())); draw(curr_items, next_items, curr_loc, links, curr_ghosts, /*annotation*/ idx(curr_row, curr_loc).inner()()); -//p return True return true; } CMD(asciik, N_("tree"), N_("SELECTOR"), - N_("prints ASCII-art tree representation"), options::opts::none) + N_("prints ASCII-art tree representation"), options::opts::none) { N(args.size() == 1, F("wrong argument count")); @@ -397,84 +311,49 @@ CMD(asciik, N_("tree"), N_("SELECTOR"), vector sorted; toposort(revs, sorted, app); vector curr_row; -//* for (vector::const_reverse_iterator rev = sorted.rbegin(); -//* rev != sorted.rend(); ++rev) +// for (vector::const_reverse_iterator rev = sorted.rbegin(); +// rev != sorted.rend(); ++rev) reverse(sorted.begin(), sorted.end()); //TODO: faster to use a reverse_iterator I guess, but that seems to give some problems for (vector::const_iterator rev = sorted.begin(); rev != sorted.end(); ++rev) { // print row - std::cerr << "asciik: foreach sorted: " << rev->inner()() << "\n"; -//p if curr_rev not in curr_row: -//p curr_row.append(curr_rev) if (find(curr_row.begin(), curr_row.end(), *rev) == curr_row.end()) curr_row.push_back(*rev); -//p curr_loc = curr_row.index(curr_rev) //iterator_traits::iterator>::difference_type size_t curr_loc = distance(curr_row.begin(), find(curr_row.begin(), curr_row.end(), *rev)); //assert(curr_loc < size()); as it is surely found - std::cerr << "asciik: parents\n"; set parents; app.db.get_revision_parents(*rev, parents); - parents.erase(ghost); -//p new_revs = [] -//p for p in parents: -//p if p not in curr_row: -//p new_revs.append(p) - std::cerr << "asciik: foreach in " << parents.size() << " parent\n"; + parents.erase(ghost); // remove the fake parent that root nodes have set new_revs; for (set::const_iterator parent = parents.begin(); parent != parents.end(); ++parent) - {//TODO if (find(curr_row.begin(), curr_row.end(), *parent) == curr_row.end()) new_revs.insert(*parent); - std::cerr << *parent << " parent\n"; - }//TODO -//p next_row = list(curr_row) -//p next_row[curr_loc:curr_loc + 1] = new_revs - std::cerr << "asciik: next row\n"; vector next_row(curr_row); next_row.insert( next_row.erase(next_row.begin() + curr_loc), new_revs.begin(), new_revs.end()); - //TODO:remove test print - std::cerr << "curr_row: "; - copy(curr_row.begin(), curr_row.end(), ostream_iterator(std::cerr, " ")); - std::cerr << "\nnext_row: "; - copy(next_row.begin(), next_row.end(), ostream_iterator(std::cerr, " ")); - std::cerr << "\n"; - -//p # now next_row contains exactly the revisions it needs to, except that no -//p # ghost handling has been done. - -//p no_ghost = without_a_ghost(next_row) + // now next_row contains exactly the revisions it needs to, except that no + // ghost handling has been done. vector no_ghost(next_row); - vector::iterator i_ghost = find(no_ghost.begin(), + vector::iterator first_ghost = find(no_ghost.begin(), no_ghost.end(), ghost); - if (i_ghost != no_ghost.end()) - no_ghost.erase(i_ghost); + if (first_ghost != no_ghost.end()) + no_ghost.erase(first_ghost); - std::cerr << "asciik: try draw\n"; -//p if try_draw(curr_row, no_ghost, curr_loc, parents): -//p return no_ghost if (try_draw(curr_row, no_ghost, curr_loc, parents)) curr_row = no_ghost; -//p if try_draw(curr_row, next_row, curr_loc, parents): -//p return next_row else if (try_draw(curr_row, next_row, curr_loc, parents)) curr_row = next_row; -//p if not new_revs: # this line has disappeared -//p extra_ghost = with_a_ghost_added(next_row, curr_loc) -//p if try_draw(curr_row, extra_ghost, curr_loc, parents): -//p return extra_ghost -//p assert False - else if (new_revs.size() == 0) { + else if (new_revs.size() == 0) { // this line has disappeared vector extra_ghost(next_row); extra_ghost.insert(curr_row.begin() + curr_loc, ghost); if (!try_draw(curr_row, extra_ghost, curr_loc, parents))