ReinH-gitviz 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ v0.1.0 Create GraphViz documents from your git history FTW
2
+
3
+ v0.0.1 Basic DOT file generation
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Rein Henrichs
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
1
+ bin/gitviz
2
+ CHANGELOG
3
+ lib/gitviz/digraph.rb
4
+ lib/gitviz/errors.rb
5
+ lib/gitviz/git_commands.rb
6
+ lib/gitviz.rb
7
+ LICENSE
8
+ Manifest
9
+ README.markdown
10
+ spec/gitviz_spec.rb
11
+ spec/spec.opts
12
+ spec/spec_helper.rb
@@ -0,0 +1,17 @@
1
+ GitViz
2
+ ======
3
+
4
+ The GitViz library creates GraphViz .dot format graphs from your git commit history.
5
+
6
+ # From a git repository
7
+ $ gitviz master > master.dot
8
+
9
+ ## Source Code ##
10
+
11
+ Main repository is at [http://github.com/ReinH/gitviz](http://github.com/ReinH/gitviz)
12
+
13
+ ## Contributors: ##
14
+ * [Rein Henrichs](http://github.com/ReinH)
15
+
16
+ ## Special Thanks ##
17
+ * jengelh on irc.freenode.com/git
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'gitviz'
4
+
5
+ begin
6
+ $stdout.write GitViz::Digraph.new(ARGV)
7
+ rescue GitViz::InvalidGitRefError => e
8
+ $stderr.write e.message
9
+ $stderr.write "\n"
10
+ Kernel.exit(1)
11
+ end
@@ -0,0 +1,38 @@
1
+
2
+ # Gem::Specification for Gitviz-0.1.0
3
+ # Originally generated by Echoe
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{gitviz}
7
+ s.version = "0.1.0"
8
+
9
+ s.specification_version = 2 if s.respond_to? :specification_version=
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = [""]
13
+ s.date = %q{2008-04-27}
14
+ s.default_executable = %q{gitviz}
15
+ s.description = %q{}
16
+ s.email = %q{}
17
+ s.executables = ["gitviz"]
18
+ s.extra_rdoc_files = ["bin/gitviz", "CHANGELOG", "lib/gitviz/digraph.rb", "lib/gitviz/errors.rb", "lib/gitviz/git_commands.rb", "lib/gitviz.rb", "LICENSE", "README.markdown"]
19
+ s.files = ["bin/gitviz", "CHANGELOG", "lib/gitviz/digraph.rb", "lib/gitviz/errors.rb", "lib/gitviz/git_commands.rb", "lib/gitviz.rb", "LICENSE", "Manifest", "README.markdown", "spec/gitviz_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "gitviz.gemspec"]
20
+ s.has_rdoc = true
21
+ s.homepage = %q{}
22
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Gitviz", "--main", "README.markdown"]
23
+ s.require_paths = ["lib"]
24
+ s.rubyforge_project = %q{gitviz}
25
+ s.rubygems_version = %q{1.0.1}
26
+ s.summary = %q{}
27
+ end
28
+
29
+
30
+ # # Original Rakefile source (requires the Echoe gem):
31
+ #
32
+ # require 'echoe'
33
+ # Echoe.new('gitviz')# do |p|
34
+ # # p.author = "Rein Henrichs"
35
+ # # p.email = "reinh@reinh.com"
36
+ # # p.summary = "GitViz generates DOT files from git commit graphs for GraphViz and great justice."
37
+ # # p.url = "http://github.com/reinh/gitviz"
38
+ # # end
@@ -0,0 +1,3 @@
1
+ require 'gitviz/errors'
2
+ require 'gitviz/git_commands'
3
+ require 'gitviz/digraph'
@@ -0,0 +1,46 @@
1
+ module GitViz
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)
5
+ @ref = ref
6
+ end
7
+
8
+ def to_dot_graph
9
+ str = digraph_head
10
+
11
+ heads_parents.each do |head, parents|
12
+ parents.each do |parent|
13
+ str << digraph_edge(head, parent)
14
+ end
15
+ end
16
+
17
+ str << digraph_foot
18
+ end
19
+ alias_method :to_s, :to_dot_graph
20
+
21
+ # Pretty object inspection
22
+ def inspect
23
+ %Q{#<GitViz::Digraph "ref: #{@ref}">}
24
+ end
25
+
26
+ private
27
+ def heads_parents
28
+ heads_parents_log = GitViz::GitCommands::git :log, @ref, "--pretty=format:\"<%h><%p>\""
29
+ heads_parents = heads_parents_log.map{|line| line.scan(/^<(.*?)><(.*?)>/).flatten}
30
+ heads_parents.map{|head, parents| [head, parents.split(' ')]}
31
+ end
32
+
33
+ def digraph_head
34
+ "digraph {\n\trankdir=RL;\n"
35
+ end
36
+
37
+ def digraph_foot
38
+ "};\n"
39
+ end
40
+
41
+ def digraph_edge(to, from)
42
+ "\t\"#{to}\" -> \"#{from}\";\n"
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,4 @@
1
+ module GitViz
2
+ class InvalidGitRefError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ module GitViz
2
+ module GitCommands
3
+ class << self
4
+ # Thank you grit
5
+ def git(cmd, *args)
6
+ `git #{cmd} #{args.join(' ')}`.chomp
7
+ end
8
+
9
+ def valid_ref?(ref)
10
+ not (git "show-ref", ref).empty?
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ class Git; include GitViz::GitCommands; end
4
+
5
+ describe GitViz::GitCommands do
6
+ before(:each) do
7
+ @g = Git.new
8
+ end
9
+ describe "git command" do
10
+ it "gets the git version" do
11
+ GitViz::GitCommands.git(:version).should =~ /^git version [\d\.a-z]*$/
12
+ end
13
+ end
14
+ end
15
+
16
+ describe GitViz::Digraph do
17
+ describe "initialized with a valid reference" do
18
+ before(:each) do
19
+ GitViz::GitCommands.should_receive(:valid_ref?).and_return(true)
20
+ @d = GitViz::Digraph.new
21
+ @log_string = "<123456><abcdef fedcba>"
22
+ @heads_parents = [["123456", ["abcdef", "fedcba"]]]
23
+ end
24
+
25
+ it "has a pretty inspect" do
26
+ @d.inspect.should == %Q{#<GitViz::Digraph "ref: master">}
27
+ end
28
+
29
+ it "takes heads and their parents from the log" do
30
+ GitViz::GitCommands.should_receive(:git).with(:log, "master", "--pretty=format:\"<%h><%p>\"").and_return(@log_string)
31
+ @d.send(:heads_parents).should == @heads_parents
32
+ end
33
+
34
+ it "creates a dot graph from the heads and their parents" do
35
+ @d.should_receive(:heads_parents).and_return(@heads_parents)
36
+
37
+ @d.to_dot_graph.should == "digraph {\n\trankdir=TB;\n\t\"123456\" -> \"abcdef\";\n\t\"123456\" -> \"fedcba\";\n};\n"
38
+ end
39
+ end
40
+
41
+ describe "initialized with an invalid reference" do
42
+ before(:each) do
43
+ GitViz::GitCommands.should_receive(:valid_ref?).and_return(false)
44
+ end
45
+ it "raises an error" do
46
+ initializing_invalid_digraph = lambda { GitViz::Digraph.new("invalid")}
47
+
48
+ initializing_invalid_digraph.should raise_error(GitViz::InvalidGitRefError)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'gitviz'
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ReinH-gitviz
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ""
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-04-27 00:00:00 -07:00
13
+ default_executable: gitviz
14
+ dependencies: []
15
+
16
+ description: ""
17
+ email: ""
18
+ executables:
19
+ - gitviz
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - bin/gitviz
24
+ - CHANGELOG
25
+ - lib/gitviz/digraph.rb
26
+ - lib/gitviz/errors.rb
27
+ - lib/gitviz/git_commands.rb
28
+ - lib/gitviz.rb
29
+ - LICENSE
30
+ - README.markdown
31
+ files:
32
+ - bin/gitviz
33
+ - CHANGELOG
34
+ - lib/gitviz/digraph.rb
35
+ - lib/gitviz/errors.rb
36
+ - lib/gitviz/git_commands.rb
37
+ - lib/gitviz.rb
38
+ - LICENSE
39
+ - Manifest
40
+ - README.markdown
41
+ - spec/gitviz_spec.rb
42
+ - spec/spec.opts
43
+ - spec/spec_helper.rb
44
+ - gitviz.gemspec
45
+ has_rdoc: true
46
+ homepage: ""
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --line-numbers
50
+ - --inline-source
51
+ - --title
52
+ - Gitviz
53
+ - --main
54
+ - README.markdown
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project: gitviz
72
+ rubygems_version: 1.0.1
73
+ signing_key:
74
+ specification_version: 2
75
+ summary: ""
76
+ test_files: []
77
+