Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Commit

Permalink
allow to plot changes with 'git pijul plot | dot -Txlib'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Louis Fuchs committed Jul 28, 2021
1 parent 9760feb commit 38a242b
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,7 @@ changes
### 0.4.0

* stop using .ignore, instead add root directory items one by one, ignoring .git

### 0.5.0

* allow to plot changes with `git pijul plot | dot -Txlib`
92 changes: 92 additions & 0 deletions git_pijul.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from subprocess import run as run

import click
import toml
from temppathlib import TemporaryDirectory
from tqdm import tqdm

Expand Down Expand Up @@ -60,6 +61,16 @@ def delete_internal(channel):
delete(f"in_{channel}")


def get_changes():
res = run(["pijul", "log", "--hash-only"], check=True, stdout=PIPE)
return res.stdout.decode("UTF-8").splitlines()


def get_change(hash):
res = run(["pijul", "change", hash], check=True, stdout=PIPE)
return res.stdout.decode("UTF-8")


def ancestry_path(head, base):
res = run(
["git", "rev-list", "--ancestry-path", f"{base}..{head}"],
Expand Down Expand Up @@ -279,6 +290,37 @@ def check_head(head):
return head


re_dep = re.compile(r"\d\] ([a-zA-Z0-9]{53})\b")


def find_dependencies():
dep_dict = dict()
for change_hash in get_changes():
change = get_change(change_hash)
in_block = False
dependencies = []
toml_lines = []
for line in change.splitlines():
if in_block:
if not line.split():
break
split = re_dep.findall(line)
if split:
dependencies.append(split[0])
elif line.startswith("# Dependencies"):
in_block = True
elif line.startswith("# Hunks"):
break
else:
toml_lines.append(line)
toml_code = os.linesep.join(toml_lines)
info = toml.loads(toml_code)
info["hash"] = change_hash
info["dependencies"] = dependencies
dep_dict[change_hash] = info
return dep_dict


re_rev = re.compile(r"\bin_[A-Fa-f0-9]{40}\b", re.MULTILINE)


Expand Down Expand Up @@ -320,11 +362,61 @@ def final_fork(head):
print(f"pijul channel rename {head} $new_name")


re_commit = re.compile(r"\bcommit [A-Fa-f0-9]{40}\b", re.MULTILINE)


def extract_subject(msg):
for line in msg.splitlines():
line = line.strip()
if not line or re_commit.match(line):
continue
return line
return "no message"


def plot_nodes(deps):
res = []
for item in deps.values():
hash = item["hash"]
msg = extract_subject(item["message"])
# msg = item["hash"]
res.append(f'"{hash}" [ label = "{msg}" ];')
return os.linesep.join(res)


def plot_edges(deps):
res = []
for item in deps.values():
for dep in item["dependencies"]:
start = item["hash"]
res.append(f'"{start}" -> "{dep}";')
return os.linesep.join(res)


def plot_digraph():
deps = find_dependencies()
# rankdir=LR;
return """
digraph {{
{nodes}
{edges}
}}
""".format(
nodes=plot_nodes(deps), edges=plot_edges(deps)
)


@click.group()
def main():
pass


@main.command()
def plot():
"""display current changes as graphviz file (git pijul plot | dot -Txlib)"""
print(plot_digraph())


@main.command()
def shallow():
"""create a new pijul repository from the current revision without history"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "git-pijul"
version = "0.4.0"
version = "0.5.0"
description = "update pijul from git."
authors = ["Jean-Louis Fuchs <jean-louis.fuchs@adfinis-sygroup.ch>"]
license = "AGPL-3.0-or-later"
Expand Down

0 comments on commit 38a242b

Please sign in to comment.