Skip to content

Commit 1064c99

Browse files
committed
perm.py: remove broken hack for excluding transitive edges
Graphviz includes the tred program for computing transitive reduction so use this to post process the complete graph instead. This means that graphs containing edges that drop more than one perm that are not implied by transitivity are displayed correctly.
1 parent 1a107c1 commit 1064c99

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

archdoc/misc/perms/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
all: perms.svg
33

44
perms.dot: perms.py
5-
./perms.py > $@
5+
./perms.py | tred > $@
66

77
%.svg : %.dot
88
dot -Tsvg -o $@ $<

archdoc/misc/perms/perms.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,28 +134,26 @@ def comb_to_str(c):
134134
return '_'.join(cs) or "0"
135135

136136
# Now we output a graph representation of the useful combinations in dot format.
137-
# To make it pretty we add edges for the subset partial order, excluding edges
138-
# implied by transitivity.
137+
# To make it pretty we add edges for the subset partial order.
139138

140139
print("digraph {")
141140

142141
# Output the names of nodes in the graph
143142
for x in useful_combinations:
144143
print(comb_to_str(x))
145144

146-
# Output the edges for the subset relation. To exclude transitive edges
147-
# we stick to pairs of combinations that differ in size by one. This
148-
# doesn't work for all graphs but seems to be OK for us.
145+
# Output the edges for the subset relation. This results in many redundant edges
146+
# but fortunately graphviz provides `tred` for computing the transitive
147+
# reduction.
149148
for x in useful_combinations:
150149
for y in useful_combinations:
151-
if len(x) + 1 == len(y):
152-
xs = set(x)
153-
ys = set(y)
154-
if xs.issubset(ys):
155-
# find the permission in ys not in xs to use as label
156-
diff = (ys - xs).pop()
157-
x_str=comb_to_str(x)
158-
y_str=comb_to_str(y)
159-
print(f"{y_str} -> {x_str} [label=\"{diff}\", fontsize=10]")
150+
xs = set(x)
151+
ys = set(y)
152+
if xs < ys:
153+
# find the permissions in ys not in xs to use as label
154+
diff = ys - xs
155+
x_str=comb_to_str(x)
156+
y_str=comb_to_str(y)
157+
print(f"{y_str} -> {x_str} [label=\"{comb_to_str(diff)}\", fontsize=10]")
160158

161159
print("}")

0 commit comments

Comments
 (0)