ReinH-gitviz 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +2 -0
- data/README.markdown +8 -2
- data/bin/gitviz +52 -5
- data/gitviz.gemspec +2 -2
- data/lib/gitviz/digraph.rb +20 -6
- metadata +1 -1
data/CHANGELOG
CHANGED
data/README.markdown
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
GitViz
|
2
2
|
======
|
3
3
|
|
4
|
-
The GitViz library creates GraphViz
|
4
|
+
The GitViz library creates GraphViz dot format graphs from your git commit history.
|
5
5
|
|
6
6
|
# From a git repository
|
7
|
-
$ gitviz
|
7
|
+
$ gitviz -O
|
8
|
+
|
9
|
+
See gitviz -h for more info.
|
10
|
+
|
11
|
+
## Get It ##
|
12
|
+
|
13
|
+
$ sudo gem install ReinH-gitviz
|
8
14
|
|
9
15
|
## Source Code ##
|
10
16
|
|
data/bin/gitviz
CHANGED
@@ -1,11 +1,58 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'rubygems'
|
3
|
+
require 'optparse'
|
3
4
|
require 'gitviz'
|
4
5
|
|
6
|
+
BANNER = <<END
|
7
|
+
Usage: gitviz [options] [ref]
|
8
|
+
|
9
|
+
Description: Parses the given ref (default "master") of the current git
|
10
|
+
repository and outputs its dot representation.
|
11
|
+
|
12
|
+
Options:
|
13
|
+
END
|
14
|
+
|
15
|
+
options = {}
|
16
|
+
|
17
|
+
op = OptionParser.new do |opts|
|
18
|
+
opts.banner = BANNER
|
19
|
+
|
20
|
+
opts.on('--rankdir RANKDIR', 'Rank direction for the dot template. Default is TB (Top to Bottom)') do |rankdir|
|
21
|
+
options[:rankdir] = rankdir
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on('-l', '--limit LIMIT', 'Limit the number of commits graphed. Default is no limit.') do |limit|
|
25
|
+
options[:limit] = limit.to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on('-O', 'Write to <ref>.dot file in current directory') do
|
29
|
+
options[:output] = true
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on('-o NAME', 'Write to <NAME>.dot file in current directory') do |name|
|
33
|
+
options[:filename] = name
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
37
|
+
puts opts
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
5
42
|
begin
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
43
|
+
op.parse!(ARGV)
|
44
|
+
rev = ARGV.first || "master"
|
45
|
+
options[:filename] = rev if options[:output]
|
46
|
+
graph = GitViz::Digraph.new(rev, options)
|
47
|
+
if filename = options[:filename]
|
48
|
+
$stdout.puts "Writing to file #{filename}.dot"
|
49
|
+
File.open("#{filename}.dot", "w") {|f| f.write graph.to_s}
|
50
|
+
else
|
51
|
+
$stdout.puts graph
|
52
|
+
end
|
53
|
+
exit 0
|
54
|
+
rescue Exception => e
|
55
|
+
raise e if e.is_a? SystemExit
|
56
|
+
$stderr.puts e.message
|
57
|
+
exit 1
|
11
58
|
end
|
data/gitviz.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Gitviz-0.1.
|
2
|
+
# Gem::Specification for Gitviz-0.1.2
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = %q{gitviz}
|
7
|
-
s.version = "0.1.
|
7
|
+
s.version = "0.1.2"
|
8
8
|
|
9
9
|
s.specification_version = 2 if s.respond_to? :specification_version=
|
10
10
|
|
data/lib/gitviz/digraph.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
module GitViz
|
2
2
|
class Digraph
|
3
|
-
def initialize(ref = "master")
|
4
|
-
raise GitViz::InvalidGitRefError.new("#{ref} is not a valid ref") unless GitViz::GitCommands::valid_ref?(ref)
|
3
|
+
def initialize(ref = "master", options = {})
|
4
|
+
raise GitViz::InvalidGitRefError.new("\"#{ref}\" is not a valid ref") unless GitViz::GitCommands::valid_ref?(ref)
|
5
5
|
@ref = ref
|
6
|
+
@options = options
|
6
7
|
end
|
8
|
+
attr_reader :ref
|
7
9
|
|
8
10
|
def to_dot_graph
|
9
11
|
str = digraph_head
|
@@ -20,18 +22,30 @@ module GitViz
|
|
20
22
|
|
21
23
|
# Pretty object inspection
|
22
24
|
def inspect
|
23
|
-
%Q{#<GitViz::Digraph "ref: #{
|
25
|
+
%Q{#<GitViz::Digraph "ref: #{ref}">}
|
24
26
|
end
|
25
27
|
|
26
|
-
private
|
28
|
+
private
|
29
|
+
|
30
|
+
def rankdir
|
31
|
+
@options[:rankdir] || "TB"
|
32
|
+
end
|
33
|
+
|
34
|
+
def limit
|
35
|
+
@options[:limit]
|
36
|
+
end
|
37
|
+
|
38
|
+
# TODO: tail log output instead of slicing array
|
27
39
|
def heads_parents
|
28
40
|
heads_parents_log = GitViz::GitCommands::git :log, @ref, "--pretty=format:\"<%h><%p>\""
|
29
41
|
heads_parents = heads_parents_log.map{|line| line.scan(/^<(.*?)><(.*?)>/).flatten}
|
30
|
-
heads_parents.map{|head, parents| [head, parents.split(' ')]}
|
42
|
+
heads_parents = heads_parents.map{|head, parents| [head, parents.split(' ')]}
|
43
|
+
heads_parents = heads_parents.first(limit) if limit
|
44
|
+
heads_parents
|
31
45
|
end
|
32
46
|
|
33
47
|
def digraph_head
|
34
|
-
"digraph {\n\trankdir
|
48
|
+
"digraph {\n\trankdir=#{rankdir};\n"
|
35
49
|
end
|
36
50
|
|
37
51
|
def digraph_foot
|