mojombo-grit 0.9.4 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/API.txt +101 -0
- data/History.txt +38 -2
- data/README.md +210 -0
- data/VERSION.yml +4 -0
- data/lib/grit.rb +13 -4
- data/lib/grit/blame.rb +61 -0
- data/lib/grit/blob.rb +11 -2
- data/lib/grit/commit.rb +44 -31
- data/lib/grit/commit_stats.rb +26 -2
- data/lib/grit/diff.rb +6 -6
- data/lib/grit/git-ruby.rb +4 -2
- data/lib/grit/git-ruby/file_index.rb +10 -3
- data/lib/grit/git-ruby/git_object.rb +9 -3
- data/lib/grit/git-ruby/internal/{mmap.rb → file_window.rb} +2 -2
- data/lib/grit/git-ruby/internal/loose.rb +6 -6
- data/lib/grit/git-ruby/internal/pack.rb +19 -19
- data/lib/grit/git-ruby/object.rb +8 -2
- data/lib/grit/git-ruby/repository.rb +11 -6
- data/lib/grit/git.rb +23 -10
- data/lib/grit/index.rb +12 -11
- data/lib/grit/merge.rb +45 -0
- data/lib/grit/ref.rb +20 -16
- data/lib/grit/repo.rb +59 -9
- data/lib/grit/ruby1.9.rb +7 -0
- data/lib/grit/submodule.rb +5 -1
- data/lib/grit/tag.rb +61 -66
- data/lib/grit/tree.rb +20 -1
- metadata +29 -47
- data/Manifest.txt +0 -71
- data/README.txt +0 -213
- data/Rakefile +0 -29
- data/grit.gemspec +0 -62
- data/lib/grit/head.rb +0 -83
- data/test/test_actor.rb +0 -35
- data/test/test_blob.rb +0 -79
- data/test/test_commit.rb +0 -190
- data/test/test_config.rb +0 -58
- data/test/test_diff.rb +0 -18
- data/test/test_git.rb +0 -64
- data/test/test_grit.rb +0 -32
- data/test/test_head.rb +0 -47
- data/test/test_real.rb +0 -19
- data/test/test_reality.rb +0 -17
- data/test/test_remote.rb +0 -14
- data/test/test_repo.rb +0 -277
- data/test/test_tag.rb +0 -25
- data/test/test_tree.rb +0 -96
data/lib/grit/ruby1.9.rb
ADDED
data/lib/grit/submodule.rb
CHANGED
@@ -54,7 +54,7 @@ module Grit
|
|
54
54
|
blob = commit.tree/'.gitmodules'
|
55
55
|
return {} unless blob
|
56
56
|
|
57
|
-
lines = blob.data.split("\n")
|
57
|
+
lines = blob.data.gsub(/\r\n?/, "\n" ).split("\n")
|
58
58
|
|
59
59
|
config = {}
|
60
60
|
current = nil
|
@@ -75,6 +75,10 @@ module Grit
|
|
75
75
|
config
|
76
76
|
end
|
77
77
|
|
78
|
+
def basename
|
79
|
+
File.basename(name)
|
80
|
+
end
|
81
|
+
|
78
82
|
# Pretty object inspection
|
79
83
|
def inspect
|
80
84
|
%Q{#<Grit::Submodule "#{@id}">}
|
data/lib/grit/tag.rb
CHANGED
@@ -1,71 +1,66 @@
|
|
1
1
|
module Grit
|
2
|
-
|
3
|
-
class Tag
|
4
|
-
attr_reader :name
|
5
|
-
attr_reader :commit
|
6
|
-
|
7
|
-
# Instantiate a new Tag
|
8
|
-
# +name+ is the name of the head
|
9
|
-
# +commit+ is the Commit that the head points to
|
10
|
-
#
|
11
|
-
# Returns Grit::Tag (baked)
|
12
|
-
def initialize(name, commit)
|
13
|
-
@name = name
|
14
|
-
@commit = commit
|
15
|
-
end
|
16
|
-
|
17
|
-
# Find all Tags
|
18
|
-
# +repo+ is the Repo
|
19
|
-
# +options+ is a Hash of options
|
20
|
-
#
|
21
|
-
# Returns Grit::Tag[] (baked)
|
2
|
+
|
3
|
+
class Tag < Ref
|
22
4
|
def self.find_all(repo, options = {})
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
43
47
|
end
|
44
|
-
|
45
|
-
|
48
|
+
|
49
|
+
refs
|
46
50
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
full_name, id = line.split("\0")
|
60
|
-
name = full_name.split("/").last
|
61
|
-
commit = Commit.create(repo, :id => id)
|
62
|
-
self.new(name, commit)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Pretty object inspection
|
66
|
-
def inspect
|
67
|
-
%Q{#<Grit::Tag "#{@name}">}
|
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
|
68
63
|
end
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/lib/grit/tree.rb
CHANGED
@@ -95,10 +95,29 @@ module Grit
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
+
def basename
|
99
|
+
File.basename(name)
|
100
|
+
end
|
101
|
+
|
98
102
|
# Pretty object inspection
|
99
103
|
def inspect
|
100
104
|
%Q{#<Grit::Tree "#{@id}">}
|
101
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
|
102
121
|
end # Tree
|
103
|
-
|
122
|
+
|
104
123
|
end # Grit
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mojombo-grit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Preston-Werner
|
@@ -10,87 +10,82 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2009-03-31 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
17
|
-
name: diff-lcs
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
25
16
|
- !ruby/object:Gem::Dependency
|
26
17
|
name: mime-types
|
18
|
+
type: :runtime
|
27
19
|
version_requirement:
|
28
20
|
version_requirements: !ruby/object:Gem::Requirement
|
29
21
|
requirements:
|
30
|
-
- - "
|
22
|
+
- - ">="
|
31
23
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
24
|
+
version: "1.15"
|
33
25
|
version:
|
34
26
|
- !ruby/object:Gem::Dependency
|
35
|
-
name:
|
27
|
+
name: diff-lcs
|
28
|
+
type: :runtime
|
36
29
|
version_requirement:
|
37
30
|
version_requirements: !ruby/object:Gem::Requirement
|
38
31
|
requirements:
|
39
|
-
- - "
|
32
|
+
- - ">="
|
40
33
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
34
|
+
version: 1.1.2
|
42
35
|
version:
|
43
|
-
description: Grit is a Ruby library for extracting information from a git repository in
|
44
|
-
email: tom@
|
36
|
+
description: Grit is a Ruby library for extracting information from a git repository in an object oriented manner.
|
37
|
+
email: tom@mojombo.com
|
45
38
|
executables: []
|
46
39
|
|
47
40
|
extensions: []
|
48
41
|
|
49
|
-
extra_rdoc_files:
|
50
|
-
|
51
|
-
- Manifest.txt
|
52
|
-
- README.txt
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
53
44
|
files:
|
45
|
+
- API.txt
|
54
46
|
- History.txt
|
55
|
-
- README.
|
56
|
-
-
|
57
|
-
- grit
|
47
|
+
- README.md
|
48
|
+
- VERSION.yml
|
49
|
+
- lib/grit
|
58
50
|
- lib/grit/actor.rb
|
51
|
+
- lib/grit/blame.rb
|
59
52
|
- lib/grit/blob.rb
|
60
53
|
- lib/grit/commit.rb
|
61
54
|
- lib/grit/commit_stats.rb
|
62
55
|
- lib/grit/config.rb
|
63
56
|
- lib/grit/diff.rb
|
64
57
|
- lib/grit/errors.rb
|
58
|
+
- lib/grit/git-ruby
|
65
59
|
- lib/grit/git-ruby/commit_db.rb
|
66
60
|
- lib/grit/git-ruby/file_index.rb
|
67
61
|
- lib/grit/git-ruby/git_object.rb
|
62
|
+
- lib/grit/git-ruby/internal
|
63
|
+
- lib/grit/git-ruby/internal/file_window.rb
|
68
64
|
- lib/grit/git-ruby/internal/loose.rb
|
69
|
-
- lib/grit/git-ruby/internal/mmap.rb
|
70
65
|
- lib/grit/git-ruby/internal/pack.rb
|
71
66
|
- lib/grit/git-ruby/internal/raw_object.rb
|
72
67
|
- lib/grit/git-ruby/object.rb
|
73
68
|
- lib/grit/git-ruby/repository.rb
|
74
69
|
- lib/grit/git-ruby.rb
|
75
70
|
- lib/grit/git.rb
|
76
|
-
- lib/grit/head.rb
|
77
71
|
- lib/grit/index.rb
|
78
72
|
- lib/grit/lazy.rb
|
73
|
+
- lib/grit/merge.rb
|
79
74
|
- lib/grit/ref.rb
|
80
75
|
- lib/grit/repo.rb
|
76
|
+
- lib/grit/ruby1.9.rb
|
81
77
|
- lib/grit/status.rb
|
82
78
|
- lib/grit/submodule.rb
|
83
79
|
- lib/grit/tag.rb
|
84
80
|
- lib/grit/tree.rb
|
85
81
|
- lib/grit.rb
|
86
82
|
- lib/open3_detach.rb
|
87
|
-
- Manifest.txt
|
88
83
|
has_rdoc: true
|
89
84
|
homepage: http://github.com/mojombo/grit
|
90
85
|
post_install_message:
|
91
86
|
rdoc_options:
|
92
|
-
- --
|
93
|
-
-
|
87
|
+
- --inline-source
|
88
|
+
- --charset=UTF-8
|
94
89
|
require_paths:
|
95
90
|
- lib
|
96
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -107,23 +102,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
102
|
version:
|
108
103
|
requirements: []
|
109
104
|
|
110
|
-
rubyforge_project:
|
105
|
+
rubyforge_project: grit
|
111
106
|
rubygems_version: 1.2.0
|
112
107
|
signing_key:
|
113
108
|
specification_version: 2
|
114
|
-
summary:
|
115
|
-
test_files:
|
116
|
-
|
117
|
-
- test/test_blob.rb
|
118
|
-
- test/test_commit.rb
|
119
|
-
- test/test_config.rb
|
120
|
-
- test/test_diff.rb
|
121
|
-
- test/test_git.rb
|
122
|
-
- test/test_grit.rb
|
123
|
-
- test/test_head.rb
|
124
|
-
- test/test_real.rb
|
125
|
-
- test/test_reality.rb
|
126
|
-
- test/test_remote.rb
|
127
|
-
- test/test_repo.rb
|
128
|
-
- test/test_tag.rb
|
129
|
-
- test/test_tree.rb
|
109
|
+
summary: Grit is a Ruby library for extracting information from a git repository in an object oriented manner.
|
110
|
+
test_files: []
|
111
|
+
|
data/Manifest.txt
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
History.txt
|
2
|
-
Manifest.txt
|
3
|
-
README.txt
|
4
|
-
Rakefile
|
5
|
-
grit.gemspec
|
6
|
-
lib/grit/actor.rb
|
7
|
-
lib/grit/blob.rb
|
8
|
-
lib/grit/commit.rb
|
9
|
-
lib/grit/commit_stats.rb
|
10
|
-
lib/grit/config.rb
|
11
|
-
lib/grit/diff.rb
|
12
|
-
lib/grit/errors.rb
|
13
|
-
lib/grit/git-ruby/commit_db.rb
|
14
|
-
lib/grit/git-ruby/file_index.rb
|
15
|
-
lib/grit/git-ruby/git_object.rb
|
16
|
-
lib/grit/git-ruby/internal/loose.rb
|
17
|
-
lib/grit/git-ruby/internal/mmap.rb
|
18
|
-
lib/grit/git-ruby/internal/pack.rb
|
19
|
-
lib/grit/git-ruby/internal/raw_object.rb
|
20
|
-
lib/grit/git-ruby/object.rb
|
21
|
-
lib/grit/git-ruby/repository.rb
|
22
|
-
lib/grit/git-ruby.rb
|
23
|
-
lib/grit/git.rb
|
24
|
-
lib/grit/head.rb
|
25
|
-
lib/grit/index.rb
|
26
|
-
lib/grit/lazy.rb
|
27
|
-
lib/grit/ref.rb
|
28
|
-
lib/grit/repo.rb
|
29
|
-
lib/grit/status.rb
|
30
|
-
lib/grit/submodule.rb
|
31
|
-
lib/grit/tag.rb
|
32
|
-
lib/grit/tree.rb
|
33
|
-
lib/grit.rb
|
34
|
-
test/fixtures/blame
|
35
|
-
test/fixtures/cat_file_blob
|
36
|
-
test/fixtures/cat_file_blob_size
|
37
|
-
test/fixtures/diff_2
|
38
|
-
test/fixtures/diff_2f
|
39
|
-
test/fixtures/diff_f
|
40
|
-
test/fixtures/diff_i
|
41
|
-
test/fixtures/diff_mode_only
|
42
|
-
test/fixtures/diff_new_mode
|
43
|
-
test/fixtures/diff_p
|
44
|
-
test/fixtures/for_each_ref
|
45
|
-
test/fixtures/for_each_ref_remotes
|
46
|
-
test/fixtures/for_each_ref_tags
|
47
|
-
test/fixtures/ls_tree_a
|
48
|
-
test/fixtures/ls_tree_b
|
49
|
-
test/fixtures/ls_tree_commit
|
50
|
-
test/fixtures/rev_list
|
51
|
-
test/fixtures/rev_list_count
|
52
|
-
test/fixtures/rev_list_single
|
53
|
-
test/fixtures/rev_parse
|
54
|
-
test/fixtures/show_empty_commit
|
55
|
-
test/fixtures/simple_config
|
56
|
-
test/helper.rb
|
57
|
-
test/profile.rb
|
58
|
-
test/suite.rb
|
59
|
-
test/test_actor.rb
|
60
|
-
test/test_blob.rb
|
61
|
-
test/test_commit.rb
|
62
|
-
test/test_config.rb
|
63
|
-
test/test_diff.rb
|
64
|
-
test/test_git.rb
|
65
|
-
test/test_grit.rb
|
66
|
-
test/test_head.rb
|
67
|
-
test/test_reality.rb
|
68
|
-
test/test_remote.rb
|
69
|
-
test/test_repo.rb
|
70
|
-
test/test_tag.rb
|
71
|
-
test/test_tree.rb
|
data/README.txt
DELETED
@@ -1,213 +0,0 @@
|
|
1
|
-
grit
|
2
|
-
by Tom Preston-Werner, Scott Chacon
|
3
|
-
http://github.com/mojombo/grit
|
4
|
-
|
5
|
-
== DESCRIPTION:
|
6
|
-
|
7
|
-
Grit is a Ruby library for extracting information from a git repository in and
|
8
|
-
object oriented manner.
|
9
|
-
|
10
|
-
== REQUIREMENTS:
|
11
|
-
|
12
|
-
* git (http://git-scm.com) tested with 1.6.0.2
|
13
|
-
|
14
|
-
== INSTALL:
|
15
|
-
|
16
|
-
$ gem sources -a http://gems.github.com/ (you only need to do this once)
|
17
|
-
$ gem install mojombo-grit
|
18
|
-
|
19
|
-
== SOURCE:
|
20
|
-
|
21
|
-
Grit's git repo is available on GitHub, which can be browsed at:
|
22
|
-
|
23
|
-
http://github.com/mojombo/grit
|
24
|
-
|
25
|
-
and cloned from:
|
26
|
-
|
27
|
-
git://github.com/mojombo/grit.git
|
28
|
-
|
29
|
-
== USAGE:
|
30
|
-
|
31
|
-
Grit gives you object model access to your git repository. Once you have
|
32
|
-
created a repository object, you can traverse it to find parent commit(s),
|
33
|
-
trees, blobs, etc.
|
34
|
-
|
35
|
-
= Initialize a Repo object
|
36
|
-
|
37
|
-
The first step is to create a Grit::Repo object to represent your repo. I
|
38
|
-
include the Grit module so reduce typing.
|
39
|
-
|
40
|
-
require 'mojombo-grit'
|
41
|
-
include Grit
|
42
|
-
repo = Repo.new("/Users/tom/dev/grit")
|
43
|
-
|
44
|
-
In the above example, the directory /Users/tom/dev/grit is my working
|
45
|
-
repo and contains the .git directory. You can also initialize Grit with a
|
46
|
-
bare repo.
|
47
|
-
|
48
|
-
repo = Repo.new("/var/git/grit.git")
|
49
|
-
|
50
|
-
= Getting a list of commits
|
51
|
-
|
52
|
-
From the Repo object, you can get a list of commits as an array of Commit
|
53
|
-
objects.
|
54
|
-
|
55
|
-
repo.commits
|
56
|
-
# => [#<Grit::Commit "e80bbd2ce67651aa18e57fb0b43618ad4baf7750">,
|
57
|
-
#<Grit::Commit "91169e1f5fa4de2eaea3f176461f5dc784796769">,
|
58
|
-
#<Grit::Commit "038af8c329ef7c1bae4568b98bd5c58510465493">,
|
59
|
-
#<Grit::Commit "40d3057d09a7a4d61059bca9dca5ae698de58cbe">,
|
60
|
-
#<Grit::Commit "4ea50f4754937bf19461af58ce3b3d24c77311d9">]
|
61
|
-
|
62
|
-
Called without arguments, Repo#commits returns a list of up to ten commits
|
63
|
-
reachable by the master branch (starting at the latest commit). You can ask
|
64
|
-
for commits beginning at a different branch, commit, tag, etc.
|
65
|
-
|
66
|
-
repo.commits('mybranch')
|
67
|
-
repo.commits('40d3057d09a7a4d61059bca9dca5ae698de58cbe')
|
68
|
-
repo.commits('v0.1')
|
69
|
-
|
70
|
-
You can specify the maximum number of commits to return.
|
71
|
-
|
72
|
-
repo.commits('master', 100)
|
73
|
-
|
74
|
-
If you need paging, you can specify a number of commits to skip.
|
75
|
-
|
76
|
-
repo.commits('master', 10, 20)
|
77
|
-
|
78
|
-
The above will return commits 21-30 from the commit list.
|
79
|
-
|
80
|
-
= The Commit object
|
81
|
-
|
82
|
-
Commit objects contain information about that commit.
|
83
|
-
|
84
|
-
head = repo.commits.first
|
85
|
-
|
86
|
-
head.id
|
87
|
-
# => "e80bbd2ce67651aa18e57fb0b43618ad4baf7750"
|
88
|
-
|
89
|
-
head.parents
|
90
|
-
# => [#<Grit::Commit "91169e1f5fa4de2eaea3f176461f5dc784796769">]
|
91
|
-
|
92
|
-
head.tree
|
93
|
-
# => #<Grit::Tree "3536eb9abac69c3e4db583ad38f3d30f8db4771f">
|
94
|
-
|
95
|
-
head.author
|
96
|
-
# => #<Grit::Actor "Tom Preston-Werner <tom@mojombo.com>">
|
97
|
-
|
98
|
-
head.authored_date
|
99
|
-
# => Wed Oct 24 22:02:31 -0700 2007
|
100
|
-
|
101
|
-
head.committer
|
102
|
-
# => #<Grit::Actor "Tom Preston-Werner <tom@mojombo.com>">
|
103
|
-
|
104
|
-
head.committed_date
|
105
|
-
# => Wed Oct 24 22:02:31 -0700 2007
|
106
|
-
|
107
|
-
head.message
|
108
|
-
# => "add Actor inspect"
|
109
|
-
|
110
|
-
You can traverse a commit's ancestry by chaining calls to #parents.
|
111
|
-
|
112
|
-
repo.commits.first.parents[0].parents[0].parents[0]
|
113
|
-
|
114
|
-
The above corresponds to master^^^ or master~3 in git parlance.
|
115
|
-
|
116
|
-
= The Tree object
|
117
|
-
|
118
|
-
A tree records pointers to the contents of a directory. Let's say you want
|
119
|
-
the root tree of the latest commit on the master branch.
|
120
|
-
|
121
|
-
tree = repo.commits.first.tree
|
122
|
-
# => #<Grit::Tree "3536eb9abac69c3e4db583ad38f3d30f8db4771f">
|
123
|
-
|
124
|
-
tree.id
|
125
|
-
# => "3536eb9abac69c3e4db583ad38f3d30f8db4771f"
|
126
|
-
|
127
|
-
Once you have a tree, you can get the contents.
|
128
|
-
|
129
|
-
contents = tree.contents
|
130
|
-
# => [#<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">,
|
131
|
-
#<Grit::Blob "81d2c27608b352814cbe979a6acd678d30219678">,
|
132
|
-
#<Grit::Tree "c3d07b0083f01a6e1ac969a0f32b8d06f20c62e5">,
|
133
|
-
#<Grit::Tree "4d00fe177a8407dbbc64a24dbfc564762c0922d8">]
|
134
|
-
|
135
|
-
This tree contains two Blob objects and two Tree objects. The trees are
|
136
|
-
subdirectories and the blobs are files. Trees below the root have additional
|
137
|
-
attributes.
|
138
|
-
|
139
|
-
contents.last.name
|
140
|
-
# => "lib"
|
141
|
-
|
142
|
-
contents.last.mode
|
143
|
-
# => "040000"
|
144
|
-
|
145
|
-
There is a convenience method that allows you to get a named sub-object
|
146
|
-
from a tree.
|
147
|
-
|
148
|
-
tree/"lib"
|
149
|
-
# => #<Grit::Tree "e74893a3d8a25cbb1367cf241cc741bfd503c4b2">
|
150
|
-
|
151
|
-
You can also get a tree directly from the repo if you know its name.
|
152
|
-
|
153
|
-
repo.tree
|
154
|
-
# => #<Grit::Tree "master">
|
155
|
-
|
156
|
-
repo.tree("91169e1f5fa4de2eaea3f176461f5dc784796769")
|
157
|
-
# => #<Grit::Tree "91169e1f5fa4de2eaea3f176461f5dc784796769">
|
158
|
-
|
159
|
-
= The Blob object
|
160
|
-
|
161
|
-
A blob represents a file. Trees often contain blobs.
|
162
|
-
|
163
|
-
blob = tree.contents.first
|
164
|
-
# => #<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">
|
165
|
-
|
166
|
-
A blob has certain attributes.
|
167
|
-
|
168
|
-
blob.id
|
169
|
-
# => "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666"
|
170
|
-
|
171
|
-
blob.name
|
172
|
-
# => "README.txt"
|
173
|
-
|
174
|
-
blob.mode
|
175
|
-
# => "100644"
|
176
|
-
|
177
|
-
blob.size
|
178
|
-
# => 7726
|
179
|
-
|
180
|
-
You can get the data of a blob as a string.
|
181
|
-
|
182
|
-
blob.data
|
183
|
-
# => "Grit is a library to ..."
|
184
|
-
|
185
|
-
You can also get a blob directly from the repo if you know its name.
|
186
|
-
|
187
|
-
repo.blob("4ebc8aea50e0a67e000ba29a30809d0a7b9b2666")
|
188
|
-
# => #<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">
|
189
|
-
|
190
|
-
== LICENSE:
|
191
|
-
|
192
|
-
(The MIT License)
|
193
|
-
|
194
|
-
Copyright (c) 2007 Tom Preston-Werner
|
195
|
-
|
196
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
197
|
-
a copy of this software and associated documentation files (the
|
198
|
-
'Software'), to deal in the Software without restriction, including
|
199
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
200
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
201
|
-
permit persons to whom the Software is furnished to do so, subject to
|
202
|
-
the following conditions:
|
203
|
-
|
204
|
-
The above copyright notice and this permission notice shall be
|
205
|
-
included in all copies or substantial portions of the Software.
|
206
|
-
|
207
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
208
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
209
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
210
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
211
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
212
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
213
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|