[PATCH 2 of 2] graphlog: draw graphs in give order
Peter Arrenbrecht
peter.arrenbrecht at gmail.com
Wed Apr 7 04:58:58 CDT 2010
On Mon, Apr 5, 2010 at 1:13 PM, vsh <vsh426 at gmail.com> wrote:
> On Mon, Apr 5, 2010 at 4:32 PM, Benoit Boissinot
> <benoit.boissinot at ens-lyon.org> wrote:
>>
>> On Mon, Apr 05, 2010 at 04:25:52PM +0530, vsh wrote:
>> > On Mon, Apr 5, 2010 at 1:44 PM, Benoit Boissinot <
>> > benoit.boissinot at ens-lyon.org> wrote:
>> > >
>> > > In my opinion, there is still an alignement problem with the '\' edges
>> > > in the example above.
>> > >
>> >
>> > i agree about the alignment being off, but graphlog does the same thing
>> > in
>> > similar situations AFAIK
>>
>> Do you have an example? If yes you could open a bug about that.
>>
> it never happens on the same scale as the patch because graphlog is under
> the assumption that there will never be more than one new column to add. my
> point was that when there are multiple '\' in the graph the alignment is not
> exactly 'perfect' .
> maybe if it draws it with a new column each step the alignment problem will
> not be so obvious. that would probably make the graph much longer in some
> cases though.
Here's what I use in pbranch, which also has to deal with adding more
than one column (for octopus merges at the branch level):
def octopusasciiedges(nodes, joinchar='\\'):
"""grapher for ascii() on a list of nodes and their parents
nodes must generate tuples (node, type, (char, lines), parents) where
- parents must generate the parents of node, in sorted order,
- char is the char to print as the node symbol, and
- lines are the lines to display next to the node.
Inserts artificial lines with joinchar as marker to make room
when a node has >2 parents.
Extension of graphlog.asciiedges().
"""
seen = []
for node, type, (char, lines), parents in nodes:
if node not in seen:
seen.append(node)
nodeidx = seen.index(node)
knownparents = []
newparents = []
for parent in parents:
if parent in seen:
knownparents.append(parent)
else:
newparents.append(parent)
ncols = len(seen)
nextseen = seen[:]
nextseen[nodeidx:nodeidx + 1] = newparents
edges = [(nodeidx, nextseen.index(p)) for p in knownparents]
while len(newparents) > 2:
edges.append((nodeidx, nodeidx))
edges.append((nodeidx, nodeidx + 1))
nmorecols = +1
yield (type, char, lines, (nodeidx, edges, ncols, nmorecols))
char = joinchar
lines = []
seen = nextseen
nodeidx += 1
ncols += 1
edges = []
del newparents[0]
if len(newparents) > 0:
edges.append((nodeidx, nodeidx))
if len(newparents) > 1:
edges.append((nodeidx, nodeidx + 1))
nmorecols = len(nextseen) - ncols
seen = nextseen
yield (type, char, lines, (nodeidx, edges, ncols, nmorecols))
-parren
More information about the Mercurial-devel
mailing list