Skip to content

Commit

Permalink
fix(cli): fix the wrong graph in "gas log" when merging branches
Browse files Browse the repository at this point in the history
When merging the left branch, the right branch also needs to move to the left
```
* 4c564ea (b3) 15
* a3f25ce 13
* ebb775e 8
| * 2da7d6e (b1) 14
| * aeac003 6
| | * 8c9e82e (main) 12
| | | * 1c22915 (b5) 11
| | |/
| |/|
| * | bec94e0 a
| | | * ef0e4c2 (b2) 10
| | | * dee8986 7
| | |/
| |/|
|/| |
* | | d7677e0 4
* | | e1d77c4 3
|/|
| | * f478341 (b4) 9
| |/
| * dc2a3cc 5
|/
* d0eeb20 2
* bce9056 1
```
  • Loading branch information
marshallmallows committed Nov 18, 2021
1 parent 168d77a commit ba8c9ea
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tensorbay/cli/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,10 @@ def _add_graph_oneline(
# Merge branches.
del self._layer_colors[self._merge_pointer]
lines = [f"{self._get_title_prefix(prefixes, original_pointer)} {log}"]
lines.extend(f"{prefixes}\n" for prefixes in self._get_merge_prefixes())
lines.extend(
f"{prefixes}\n"
for prefixes in self._get_merge_prefixes(self._merge_pointer, self._pointer)
)
return "".join(lines)

def _add_graph_full(
Expand All @@ -342,21 +345,26 @@ def _add_graph_full(
else:
# Merge branches.
del self._layer_colors[self._merge_pointer]
merge_prefixes = self._get_merge_prefixes()
merge_prefixes = self._get_merge_prefixes(self._merge_pointer, self._pointer)
lines.extend(self._combine_details(list(merge_prefixes), list(splitlines)))
return "".join(lines)

def _get_colorful_prefixes(self) -> List[str]:
return [click.style("|", fg=color) for color in self._layer_colors]

def _get_merge_prefixes(self) -> Iterator[str]:
def _get_merge_prefixes(self, merge_pointer: int, pointer: int) -> Iterator[str]:
prefixes = []
for color in self._layer_colors:
prefixes.append(click.style("|", fg=color))
prefixes.append(" ")
for i in range(self._merge_pointer, self._pointer, -1): # type: ignore[arg-type]

for i in range(merge_pointer, pointer, -1):
temp_prefixes = prefixes.copy()
temp_prefixes[2 * i - 1] = click.style("/", fg=self._layer_colors[self._pointer])
temp_prefixes[2 * i - 1] = click.style("/", fg=self._layer_colors[pointer])
if i == merge_pointer:
for j, color in enumerate(self._layer_colors[i:], i):
temp_prefixes[2 * j] = " "
temp_prefixes[2 * j + 1] = click.style("/", fg=color)
yield "".join(temp_prefixes)

@staticmethod
Expand Down

0 comments on commit ba8c9ea

Please sign in to comment.