Skip to content

Git graph diff tool #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# graph-diff
Utilities to view diff between graphs

# Getting starget
# Getting started

## Install prerequisites
1. graph-easy

Debian / Ubuntu:
```
sudo apt-get install libgraph-easy-perl
```
## Install
```
git clone https://github.com/yeger00/graph-diff
Expand All @@ -16,9 +18,24 @@ pip install -e .
```
cat samples/before.dot | graph-easy --as boxart
cat samples/after.dot | graph-easy --as boxart
python -m graphdiff samples/before.dot samples/after.dot ./diff.dot
python -m graphdiff samples/before.dot samples/after.dot > ./diff.dot
cat ./diff.dot | ./diff-graph-color
```

# git-diff
TODO
# git-graph-diff-tool
It is possible to use graph-diff with git, with `git-graph-diff-tool` provided in this library. An usage example:
![](images/git-log-example.gif?raw=true "git-graph-diff-tool example")

## Install
For every repository you would like to install you need to add to .gitattributes file a rules to know how to handle .dot files. For example:
```
echo "*.dot diff=graph_diff" >> .gitattributes
```
Then, configure the difftool to be the `git-graph-diff-tool`. For example:
```
git config diff.graph_diff.command /path/to/git-graph-diff-tool
```
Then, you can use git as usual, while adding `--ext-diff` flag to enable external difftools.
```
git log -p --ext-diff
```
100 changes: 0 additions & 100 deletions git-graph

This file was deleted.

62 changes: 62 additions & 0 deletions git-graph-diff-tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env sh

# Git graph-diff tool.
# GIT_EXTERNAL_DIFF command line arguments are available <here>

set -eu

readonly SCRIPT_DIR=$(dirname $(readlink -f $0))
readonly SCRIPT=$(basename $(readlink -f $0))

perror()
{
echo "${SCRIPT}: ERROR: ${@}" >&2
exit 1
}

help()
{
(
cat <<EOF
Git graph-diff tool.
See GIT_EXTERNAL_DIFF documentation for explanation of the arguments.

./${SCRIPT} [-h] [-x] PATH OLD-FILE OLD-HEX OLD-MODE NEW-FILE NEW-HEX NEW-MODE
| * -h - print this help.
| * -x - set bash's -x flag.
EOF
) | sed -r 's/^\s*\|?//'
}

while getopts ":hx" option
do
case "${option}" in
h) help
exit 0
;;

x) set -x
;;

\?) perror "unknown option -${OPTARG}"
;;
esac
done
shift $((OPTIND-1))

# validate number of arguments left
if [ "${#}" -ne 7 ]
then
perror "Invalid number of arguments (use -h for help)."
fi

path="${1}"
old_file="${2}"
old_hex="${3}"
old_mode="${4}"
new_file="${5}"
new_hex="${6}"
new_mode="${7}"

python -m graphdiff "${old_file}" "${new_file}" | ${SCRIPT_DIR}/diff-graph-color

14 changes: 10 additions & 4 deletions graphdiff/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ def load_graph(path):
'''
Loads a graph from .dot file into a Graph() object.
'''
pydot_graph = pydot.graph_from_dot_file(path)[0]
return graphdiff.from_dot(pydot_graph)
with open(path) as f:
data = f.read()
graph = graphdiff.Graph()
if data:
# TODO: handle multiple graphs
pydot_graph = pydot.graph_from_dot_data(data)[0]
graph = graphdiff.from_dot(pydot_graph)
return graph


def save_graph(graph, path):
Expand All @@ -26,8 +32,8 @@ def main():
before_graph = load_graph(sys.argv[1])
after_graph = load_graph(sys.argv[2])
diff = graphdiff.generate_diff_graph(before_graph, after_graph)
save_graph(diff, sys.argv[3])
# print_graph(diff)
# save_graph(diff, sys.argv[3])
print_graph(diff)


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion graphdiff/graphdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def remove_quotes(pydot_graph):
node.set_label(node.get_label().replace('"', ''))

for edge in pydot_graph.get_edges():
edge.set_label(edge.get_label().replace('"', ''))
if edge.get_label():
edge.set_label(edge.get_label().replace('"', ''))

def from_dot(pydot_graph):
"""Generated a graph from pydot graph."""
Expand Down
Binary file added images/git-log-example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.