File tree Expand file tree Collapse file tree 6 files changed +97
-111
lines changed Expand file tree Collapse file tree 6 files changed +97
-111
lines changed Original file line number Diff line number Diff line change 1
1
# graph-diff
2
2
Utilities to view diff between graphs
3
3
4
- # Getting starget
4
+ # Getting started
5
5
6
6
## Install prerequisites
7
- 1 . graph-easy
8
-
7
+ Debian / Ubuntu:
8
+ ```
9
+ sudo apt-get install libgraph-easy-perl
10
+ ```
9
11
## Install
10
12
```
11
13
git clone https://github.com/yeger00/graph-diff
@@ -16,9 +18,24 @@ pip install -e .
16
18
```
17
19
cat samples/before.dot | graph-easy --as boxart
18
20
cat samples/after.dot | graph-easy --as boxart
19
- python -m graphdiff samples/before.dot samples/after.dot ./diff.dot
21
+ python -m graphdiff samples/before.dot samples/after.dot > ./diff.dot
20
22
cat ./diff.dot | ./diff-graph-color
21
23
```
22
24
23
- # git-diff
24
- TODO
25
+ # git-graph-diff-tool
26
+ It is possible to use graph-diff with git, with ` git-graph-diff-tool ` provided in this library. An usage example:
27
+ ![ ] ( images/git-log-example.gif?raw=true " git-graph-diff-tool example ")
28
+
29
+ ## Install
30
+ 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:
31
+ ```
32
+ echo "*.dot diff=graph_diff" >> .gitattributes
33
+ ```
34
+ Then, configure the difftool to be the ` git-graph-diff-tool ` . For example:
35
+ ```
36
+ git config diff.graph_diff.command /path/to/git-graph-diff-tool
37
+ ```
38
+ Then, you can use git as usual, while adding ` --ext-diff ` flag to enable external difftools.
39
+ ```
40
+ git log -p --ext-diff
41
+ ```
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env sh
2
+
3
+ # Git graph-diff tool.
4
+ # GIT_EXTERNAL_DIFF command line arguments are available <here>
5
+
6
+ set -eu
7
+
8
+ readonly SCRIPT_DIR=$( dirname $( readlink -f $0 ) )
9
+ readonly SCRIPT=$( basename $( readlink -f $0 ) )
10
+
11
+ perror ()
12
+ {
13
+ echo " ${SCRIPT} : ERROR: ${@ } " >&2
14
+ exit 1
15
+ }
16
+
17
+ help ()
18
+ {
19
+ (
20
+ cat << EOF
21
+ Git graph-diff tool.
22
+ See GIT_EXTERNAL_DIFF documentation for explanation of the arguments.
23
+
24
+ ./${SCRIPT} [-h] [-x] PATH OLD-FILE OLD-HEX OLD-MODE NEW-FILE NEW-HEX NEW-MODE
25
+ | * -h - print this help.
26
+ | * -x - set bash's -x flag.
27
+ EOF
28
+ ) | sed -r ' s/^\s*\|?//'
29
+ }
30
+
31
+ while getopts " :hx" option
32
+ do
33
+ case " ${option} " in
34
+ h) help
35
+ exit 0
36
+ ;;
37
+
38
+ x) set -x
39
+ ;;
40
+
41
+ \? ) perror " unknown option -${OPTARG} "
42
+ ;;
43
+ esac
44
+ done
45
+ shift $(( OPTIND- 1 ))
46
+
47
+ # validate number of arguments left
48
+ if [ " ${# } " -ne 7 ]
49
+ then
50
+ perror " Invalid number of arguments (use -h for help)."
51
+ fi
52
+
53
+ path=" ${1} "
54
+ old_file=" ${2} "
55
+ old_hex=" ${3} "
56
+ old_mode=" ${4} "
57
+ new_file=" ${5} "
58
+ new_hex=" ${6} "
59
+ new_mode=" ${7} "
60
+
61
+ python -m graphdiff " ${old_file} " " ${new_file} " | ${SCRIPT_DIR} /diff-graph-color
62
+
Original file line number Diff line number Diff line change @@ -8,8 +8,14 @@ def load_graph(path):
8
8
'''
9
9
Loads a graph from .dot file into a Graph() object.
10
10
'''
11
- pydot_graph = pydot .graph_from_dot_file (path )[0 ]
12
- return graphdiff .from_dot (pydot_graph )
11
+ with open (path ) as f :
12
+ data = f .read ()
13
+ graph = graphdiff .Graph ()
14
+ if data :
15
+ # TODO: handle multiple graphs
16
+ pydot_graph = pydot .graph_from_dot_data (data )[0 ]
17
+ graph = graphdiff .from_dot (pydot_graph )
18
+ return graph
13
19
14
20
15
21
def save_graph (graph , path ):
@@ -26,8 +32,8 @@ def main():
26
32
before_graph = load_graph (sys .argv [1 ])
27
33
after_graph = load_graph (sys .argv [2 ])
28
34
diff = graphdiff .generate_diff_graph (before_graph , after_graph )
29
- save_graph (diff , sys .argv [3 ])
30
- # print_graph(diff)
35
+ # save_graph(diff, sys.argv[3])
36
+ print_graph (diff )
31
37
32
38
33
39
if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -112,7 +112,8 @@ def remove_quotes(pydot_graph):
112
112
node .set_label (node .get_label ().replace ('"' , '' ))
113
113
114
114
for edge in pydot_graph .get_edges ():
115
- edge .set_label (edge .get_label ().replace ('"' , '' ))
115
+ if edge .get_label ():
116
+ edge .set_label (edge .get_label ().replace ('"' , '' ))
116
117
117
118
def from_dot (pydot_graph ):
118
119
"""Generated a graph from pydot graph."""
You can’t perform that action at this time.
0 commit comments