square-circle-triangle-grit 1.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.
@@ -0,0 +1,88 @@
1
+ module Grit
2
+
3
+ class Submodule
4
+ attr_reader :id
5
+ attr_reader :mode
6
+ attr_reader :name
7
+
8
+ # Create a Submodule containing just the specified attributes
9
+ # +repo+ is the Repo
10
+ # +atts+ is a Hash of instance variable data
11
+ #
12
+ # Returns Grit::Submodule (unbaked)
13
+ def self.create(repo, atts)
14
+ self.allocate.create_initialize(repo, atts)
15
+ end
16
+
17
+ # Initializer for Submodule.create
18
+ # +repo+ is the Repo
19
+ # +atts+ is a Hash of instance variable data
20
+ #
21
+ # Returns Grit::Submodule
22
+ def create_initialize(repo, atts)
23
+ @repo = repo
24
+ atts.each do |k, v|
25
+ instance_variable_set("@#{k}".to_sym, v)
26
+ end
27
+ self
28
+ end
29
+
30
+ # The url of this submodule
31
+ # +ref+ is the committish that should be used to look up the url
32
+ #
33
+ # Returns String
34
+ def url(ref)
35
+ config = self.class.config(@repo, ref)
36
+
37
+ lookup = config.keys.inject({}) do |acc, key|
38
+ id = config[key]['id']
39
+ acc[id] = config[key]['url']
40
+ acc
41
+ end
42
+
43
+ lookup[@id]
44
+ end
45
+
46
+ # The configuration information for the given +repo+
47
+ # +repo+ is the Repo
48
+ # +ref+ is the committish (defaults to 'master')
49
+ #
50
+ # Returns a Hash of { <path:String> => { 'url' => <url:String>, 'id' => <id:String> } }
51
+ # Returns {} if no .gitmodules file was found
52
+ def self.config(repo, ref = "master")
53
+ commit = repo.commit(ref)
54
+ blob = commit.tree/'.gitmodules'
55
+ return {} unless blob
56
+
57
+ lines = blob.data.gsub(/\r\n?/, "\n" ).split("\n")
58
+
59
+ config = {}
60
+ current = nil
61
+
62
+ lines.each do |line|
63
+ if line =~ /^\[submodule "(.+)"\]$/
64
+ current = $1
65
+ config[current] = {}
66
+ config[current]['id'] = (commit.tree/current).id
67
+ elsif line =~ /^\t(\w+) = (.+)$/
68
+ config[current][$1] = $2
69
+ config[current]['id'] = (commit.tree/$2).id if $1 == 'path'
70
+ else
71
+ # ignore
72
+ end
73
+ end
74
+
75
+ config
76
+ end
77
+
78
+ def basename
79
+ File.basename(name)
80
+ end
81
+
82
+ # Pretty object inspection
83
+ def inspect
84
+ %Q{#<Grit::Submodule "#{@id}">}
85
+ end
86
+ end # Submodule
87
+
88
+ end # Grit
data/lib/grit/tag.rb ADDED
@@ -0,0 +1,66 @@
1
+ module Grit
2
+
3
+ class Tag < Ref
4
+ def self.find_all(repo, options = {})
5
+ refs = []
6
+ already = {}
7
+
8
+ Dir.chdir(repo.path) do
9
+ files = Dir.glob(prefix + '/**/*')
10
+
11
+ files.each do |ref|
12
+ next if !File.file?(ref)
13
+
14
+ id = File.read(ref).chomp
15
+ name = ref.sub("#{prefix}/", '')
16
+ commit = commit_from_sha(repo, id)
17
+
18
+ if !already[name]
19
+ refs << self.new(name, commit)
20
+ already[name] = true
21
+ end
22
+ end
23
+
24
+ if File.file?('packed-refs')
25
+ lines = File.readlines('packed-refs')
26
+ lines.each_with_index do |line, i|
27
+ if m = /^(\w{40}) (.*?)$/.match(line)
28
+ next if !Regexp.new('^' + prefix).match(m[2])
29
+ name = m[2].sub("#{prefix}/", '')
30
+
31
+ # Annotated tags in packed-refs include a reference
32
+ # to the commit object on the following line.
33
+ next_line = lines[i+1]
34
+ if next_line && next_line[0] == ?^
35
+ commit = Commit.create(repo, :id => next_line[1..-1].chomp)
36
+ else
37
+ commit = commit_from_sha(repo, m[1])
38
+ end
39
+
40
+ if !already[name]
41
+ refs << self.new(name, commit)
42
+ already[name] = true
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ refs
50
+ end
51
+
52
+ def self.commit_from_sha(repo, id)
53
+ git_ruby_repo = GitRuby::Repository.new(repo.path)
54
+ object = git_ruby_repo.get_object_by_sha1(id)
55
+
56
+ if object.type == :commit
57
+ Commit.create(repo, :id => id)
58
+ elsif object.type == :tag
59
+ Commit.create(repo, :id => object.object)
60
+ else
61
+ raise "Unknown object type."
62
+ end
63
+ end
64
+ end
65
+
66
+ end
data/lib/grit/tree.rb ADDED
@@ -0,0 +1,123 @@
1
+ module Grit
2
+
3
+ class Tree
4
+ lazy_reader :contents
5
+ attr_reader :id
6
+ attr_reader :mode
7
+ attr_reader :name
8
+
9
+ # Construct the contents of the tree
10
+ # +repo+ is the Repo
11
+ # +treeish+ is the reference
12
+ # +paths+ is an optional Array of directory paths to restrict the tree
13
+ #
14
+ # Returns Grit::Tree (baked)
15
+ def self.construct(repo, treeish, paths = [])
16
+ output = repo.git.ls_tree({}, treeish, *paths)
17
+ self.allocate.construct_initialize(repo, treeish, output)
18
+ end
19
+
20
+ def construct_initialize(repo, id, text)
21
+ @repo = repo
22
+ @id = id
23
+ @contents = []
24
+
25
+ text.split("\n").each do |line|
26
+ @contents << content_from_string(repo, line)
27
+ end
28
+ @contents.compact!
29
+
30
+ self
31
+ end
32
+
33
+ def lazy_source
34
+ Tree.construct(@repo, @id, [])
35
+ end
36
+
37
+ # Create an unbaked Tree containing just the specified attributes
38
+ # +repo+ is the Repo
39
+ # +atts+ is a Hash of instance variable data
40
+ #
41
+ # Returns Grit::Tree (unbaked)
42
+ def self.create(repo, atts)
43
+ self.allocate.create_initialize(repo, atts)
44
+ end
45
+
46
+ # Initializer for Tree.create
47
+ # +repo+ is the Repo
48
+ # +atts+ is a Hash of instance variable data
49
+ #
50
+ # Returns Grit::Tree (unbaked)
51
+ def create_initialize(repo, atts)
52
+ @repo = repo
53
+
54
+ atts.each do |k, v|
55
+ instance_variable_set("@#{k}", v)
56
+ end
57
+ self
58
+ end
59
+
60
+ # Parse a content item and create the appropriate object
61
+ # +repo+ is the Repo
62
+ # +text+ is the single line containing the items data in `git ls-tree` format
63
+ #
64
+ # Returns Grit::Blob or Grit::Tree
65
+ def content_from_string(repo, text)
66
+ mode, type, id, name = text.split(" ", 4)
67
+ case type
68
+ when "tree"
69
+ Tree.create(repo, :id => id, :mode => mode, :name => name)
70
+ when "blob"
71
+ Blob.create(repo, :id => id, :mode => mode, :name => name)
72
+ when "link"
73
+ Blob.create(repo, :id => id, :mode => mode, :name => name)
74
+ when "commit"
75
+ Submodule.create(repo, :id => id, :mode => mode, :name => name)
76
+ else
77
+ raise "Invalid type: #{type}"
78
+ end
79
+ end
80
+
81
+ # Find the named object in this tree's contents
82
+ #
83
+ # Examples
84
+ # Repo.new('/path/to/grit').tree/'lib'
85
+ # # => #<Grit::Tree "6cc23ee138be09ff8c28b07162720018b244e95e">
86
+ # Repo.new('/path/to/grit').tree/'README.txt'
87
+ # # => #<Grit::Blob "8b1e02c0fb554eed2ce2ef737a68bb369d7527df">
88
+ #
89
+ # Returns Grit::Blob or Grit::Tree or nil if not found
90
+ def /(file)
91
+ if file =~ /\//
92
+ file.split("/").inject(self) { |acc, x| acc/x } rescue nil
93
+ else
94
+ self.contents.find { |c| c.name == file }
95
+ end
96
+ end
97
+
98
+ def basename
99
+ File.basename(name)
100
+ end
101
+
102
+ # Pretty object inspection
103
+ def inspect
104
+ %Q{#<Grit::Tree "#{@id}">}
105
+ end
106
+
107
+ # Find only Tree objects from contents
108
+ def trees
109
+ contents.select {|v| v.kind_of? Tree}
110
+ end
111
+
112
+ # Find only Blob objects from contents
113
+ def blobs
114
+ contents.select {|v| v.kind_of? Blob}
115
+ end
116
+
117
+ # Compares trees by name
118
+ def <=>(other)
119
+ name <=> other.name
120
+ end
121
+ end # Tree
122
+
123
+ end # Grit
data/lib/grit.rb ADDED
@@ -0,0 +1,68 @@
1
+ $:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
2
+
3
+ # core
4
+ require 'fileutils'
5
+ require 'time'
6
+
7
+ # stdlib
8
+ require 'timeout'
9
+ require 'logger'
10
+ require 'digest/sha1'
11
+
12
+ if defined? RUBY_ENGINE && RUBY_ENGINE == 'jruby'
13
+ require 'open3'
14
+ else
15
+ require 'open3_detach'
16
+ end
17
+
18
+ # third party
19
+ require 'rubygems'
20
+ gem "mime-types", ">=0"
21
+ require 'mime/types'
22
+
23
+ # ruby 1.9 compatibility
24
+ require 'grit/ruby1.9'
25
+
26
+ # internal requires
27
+ require 'grit/lazy'
28
+ require 'grit/errors'
29
+ require 'grit/git-ruby'
30
+ require 'grit/git'
31
+ require 'grit/ref'
32
+ require 'grit/tag'
33
+ require 'grit/commit'
34
+ require 'grit/commit_stats'
35
+ require 'grit/tree'
36
+ require 'grit/blob'
37
+ require 'grit/actor'
38
+ require 'grit/diff'
39
+ require 'grit/config'
40
+ require 'grit/repo'
41
+ require 'grit/index'
42
+ require 'grit/status'
43
+ require 'grit/submodule'
44
+ require 'grit/blame'
45
+ require 'grit/merge'
46
+
47
+
48
+ module Grit
49
+ class << self
50
+ # Set +debug+ to true to log all git calls and responses
51
+ attr_accessor :debug
52
+ attr_accessor :use_git_ruby
53
+ # The standard +logger+ for debugging git calls - this defaults to a plain STDOUT logger
54
+ attr_accessor :logger
55
+ def log(str)
56
+ logger.debug { str }
57
+ end
58
+ end
59
+ self.debug = false
60
+ self.use_git_ruby = true
61
+
62
+ @logger ||= ::Logger.new(STDOUT)
63
+
64
+ def self.version
65
+ yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
66
+ "#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
67
+ end
68
+ end
@@ -0,0 +1,46 @@
1
+ module Open3
2
+ extend self
3
+
4
+ def popen3(*cmd)
5
+ pw = IO::pipe # pipe[0] for read, pipe[1] for write
6
+ pr = IO::pipe
7
+ pe = IO::pipe
8
+
9
+ pid = fork{
10
+ # child
11
+ fork{
12
+ # grandchild
13
+ pw[1].close
14
+ STDIN.reopen(pw[0])
15
+ pw[0].close
16
+
17
+ pr[0].close
18
+ STDOUT.reopen(pr[1])
19
+ pr[1].close
20
+
21
+ pe[0].close
22
+ STDERR.reopen(pe[1])
23
+ pe[1].close
24
+
25
+ exec(*cmd)
26
+ }
27
+ exit!(0)
28
+ }
29
+
30
+ pw[0].close
31
+ pr[1].close
32
+ pe[1].close
33
+ Process.waitpid(pid)
34
+ pi = [pw[1], pr[0], pe[0]]
35
+ pw[1].sync = true
36
+ if defined? yield
37
+ begin
38
+ return yield(*pi)
39
+ ensure
40
+ Process.detach(pid) if pid
41
+ pi.each { |p| p.close unless p.closed? }
42
+ end
43
+ end
44
+ pi
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: square-circle-triangle-grit
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Tom Preston-Werner
8
+ - Scott Chacon
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-03-31 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: mime-types
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "1.15"
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: diff-lcs
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 1.1.2
35
+ version:
36
+ description: Grit is a Ruby library for extracting information from a git repository in an object oriented manner.
37
+ email: tom@mojombo.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - API.txt
46
+ - History.txt
47
+ - README.md
48
+ - VERSION.yml
49
+ - lib/grit
50
+ - lib/grit/actor.rb
51
+ - lib/grit/blame.rb
52
+ - lib/grit/blob.rb
53
+ - lib/grit/commit.rb
54
+ - lib/grit/commit_stats.rb
55
+ - lib/grit/config.rb
56
+ - lib/grit/diff.rb
57
+ - lib/grit/errors.rb
58
+ - lib/grit/git-ruby
59
+ - lib/grit/git-ruby/commit_db.rb
60
+ - lib/grit/git-ruby/file_index.rb
61
+ - lib/grit/git-ruby/git_object.rb
62
+ - lib/grit/git-ruby/internal
63
+ - lib/grit/git-ruby/internal/file_window.rb
64
+ - lib/grit/git-ruby/internal/loose.rb
65
+ - lib/grit/git-ruby/internal/pack.rb
66
+ - lib/grit/git-ruby/internal/raw_object.rb
67
+ - lib/grit/git-ruby/object.rb
68
+ - lib/grit/git-ruby/repository.rb
69
+ - lib/grit/git-ruby.rb
70
+ - lib/grit/git.rb
71
+ - lib/grit/index.rb
72
+ - lib/grit/lazy.rb
73
+ - lib/grit/merge.rb
74
+ - lib/grit/ref.rb
75
+ - lib/grit/repo.rb
76
+ - lib/grit/ruby1.9.rb
77
+ - lib/grit/status.rb
78
+ - lib/grit/submodule.rb
79
+ - lib/grit/tag.rb
80
+ - lib/grit/tree.rb
81
+ - lib/grit.rb
82
+ - lib/open3_detach.rb
83
+ has_rdoc: true
84
+ homepage: http://github.com/mojombo/grit
85
+ post_install_message:
86
+ rdoc_options:
87
+ - --inline-source
88
+ - --charset=UTF-8
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "0"
96
+ version:
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
102
+ version:
103
+ requirements: []
104
+
105
+ rubyforge_project: grit
106
+ rubygems_version: 1.2.0
107
+ signing_key:
108
+ specification_version: 2
109
+ summary: Grit is a Ruby library for extracting information from a git repository in an object oriented manner.
110
+ test_files: []
111
+