##// END OF EJS Templates
graphlog: shorter variable names, fewer underscores, single state container
Dirkjan Ochtman -
r9370:b360addf default
parent child Browse files
Show More
@@ -118,12 +118,12 b' def ascii(ui, dag):'
118 in the current revision. That is: -1 means one column removed;
118 in the current revision. That is: -1 means one column removed;
119 0 means no columns added or removed; 1 means one column added.
119 0 means no columns added or removed; 1 means one column added.
120 """
120 """
121 prev_n_columns_diff = 0
122 prev_node_index = 0
123 for (node_index, type, (node_ch, node_lines), edges, n_columns, n_columns_diff) in dag:
124
121
125 assert -2 < n_columns_diff < 2
122 base = [0, 0]
126 if n_columns_diff == -1:
123 for idx, type, (char, text), edges, ncols, coldiff in dag:
124
125 assert -2 < coldiff < 2
126 if coldiff == -1:
127 # Transform
127 # Transform
128 #
128 #
129 # | | | | | |
129 # | | | | | |
@@ -139,8 +139,8 b' def ascii(ui, dag):'
139 # | / / | | | # <--- padding line
139 # | / / | | | # <--- padding line
140 # o | | | / /
140 # o | | | / /
141 # o | |
141 # o | |
142 add_padding_line = (len(node_lines) > 2 and
142 add_padding_line = (len(text) > 2 and
143 n_columns_diff == -1 and
143 coldiff == -1 and
144 [x for (x, y) in edges if x + 1 < y])
144 [x for (x, y) in edges if x + 1 < y])
145
145
146 # fix_nodeline_tail says whether to rewrite
146 # fix_nodeline_tail says whether to rewrite
@@ -150,31 +150,30 b' def ascii(ui, dag):'
150 # | o | | into | o / / # <--- fixed nodeline tail
150 # | o | | into | o / / # <--- fixed nodeline tail
151 # | |/ / | |/ /
151 # | |/ / | |/ /
152 # o | | o | |
152 # o | | o | |
153 fix_nodeline_tail = len(node_lines) <= 2 and not add_padding_line
153 fix_nodeline_tail = len(text) <= 2 and not add_padding_line
154
154
155 # nodeline is the line containing the node character (typically o)
155 # nodeline is the line containing the node character (typically o)
156 nodeline = ["|", " "] * node_index
156 nodeline = ["|", " "] * idx
157 nodeline.extend([node_ch, " "])
157 nodeline.extend([char, " "])
158
158
159 nodeline.extend(
159 nodeline.extend(
160 get_nodeline_edges_tail(
160 get_nodeline_edges_tail(idx, base[1], ncols, coldiff,
161 node_index, prev_node_index, n_columns, n_columns_diff,
161 base[0], fix_nodeline_tail))
162 prev_n_columns_diff, fix_nodeline_tail))
163
162
164 # shift_interline is the line containing the non-vertical
163 # shift_interline is the line containing the non-vertical
165 # edges between this entry and the next
164 # edges between this entry and the next
166 shift_interline = ["|", " "] * node_index
165 shift_interline = ["|", " "] * idx
167 if n_columns_diff == -1:
166 if coldiff == -1:
168 n_spaces = 1
167 n_spaces = 1
169 edge_ch = "/"
168 edge_ch = "/"
170 elif n_columns_diff == 0:
169 elif coldiff == 0:
171 n_spaces = 2
170 n_spaces = 2
172 edge_ch = "|"
171 edge_ch = "|"
173 else:
172 else:
174 n_spaces = 3
173 n_spaces = 3
175 edge_ch = "\\"
174 edge_ch = "\\"
176 shift_interline.extend(n_spaces * [" "])
175 shift_interline.extend(n_spaces * [" "])
177 shift_interline.extend([edge_ch, " "] * (n_columns - node_index - 1))
176 shift_interline.extend([edge_ch, " "] * (ncols - idx - 1))
178
177
179 # draw edges from the current node to its parents
178 # draw edges from the current node to its parents
180 draw_edges(edges, nodeline, shift_interline)
179 draw_edges(edges, nodeline, shift_interline)
@@ -182,27 +181,27 b' def ascii(ui, dag):'
182 # lines is the list of all graph lines to print
181 # lines is the list of all graph lines to print
183 lines = [nodeline]
182 lines = [nodeline]
184 if add_padding_line:
183 if add_padding_line:
185 lines.append(get_padding_line(node_index, n_columns, edges))
184 lines.append(get_padding_line(idx, ncols, edges))
186 lines.append(shift_interline)
185 lines.append(shift_interline)
187
186
188 # make sure that there are as many graph lines as there are
187 # make sure that there are as many graph lines as there are
189 # log strings
188 # log strings
190 while len(node_lines) < len(lines):
189 while len(text) < len(lines):
191 node_lines.append("")
190 text.append("")
192 if len(lines) < len(node_lines):
191 if len(lines) < len(text):
193 extra_interline = ["|", " "] * (n_columns + n_columns_diff)
192 extra_interline = ["|", " "] * (ncols + coldiff)
194 while len(lines) < len(node_lines):
193 while len(lines) < len(text):
195 lines.append(extra_interline)
194 lines.append(extra_interline)
196
195
197 # print lines
196 # print lines
198 indentation_level = max(n_columns, n_columns + n_columns_diff)
197 indentation_level = max(ncols, ncols + coldiff)
199 for (line, logstr) in zip(lines, node_lines):
198 for (line, logstr) in zip(lines, text):
200 ln = "%-*s %s" % (2 * indentation_level, "".join(line), logstr)
199 ln = "%-*s %s" % (2 * indentation_level, "".join(line), logstr)
201 ui.write(ln.rstrip() + '\n')
200 ui.write(ln.rstrip() + '\n')
202
201
203 # ... and start over
202 # ... and start over
204 prev_node_index = node_index
203 base[0] = coldiff
205 prev_n_columns_diff = n_columns_diff
204 base[1] = idx
206
205
207 def get_revs(repo, rev_opt):
206 def get_revs(repo, rev_opt):
208 if rev_opt:
207 if rev_opt:
General Comments 0
You need to be logged in to leave comments. Login now