Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d6517b1

Browse files
Forgot to remove old methods and move specs from 353ba53 (blob_finder)
Remove: * Old methods in utilities.rb, which were moved to blob_finder.rb Move: * Specs related to the blob_finder from utilities.rb spec location
1 parent d435487 commit d6517b1

File tree

4 files changed

+39
-88
lines changed

4 files changed

+39
-88
lines changed

‎lib/git_statistics/blob_finder.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ def self.get_blob(commit, file)
66
file = file.split(File::Separator)
77

88
# Acquire blob of the file for this specific commit
9-
blob = Utilities.find_blob_in_tree(commit.tree, file)
9+
blob = BlobFinder.find_blob_in_tree(commit.tree, file)
1010

1111
# If we cannot find blob in current commit (deleted file), check previous commit
1212
if blob.nil? || blob.instance_of?(Grit::Tree)
1313
prev_commit = commit.parents.first
1414
return nil if prev_commit.nil?
1515

16-
blob = Utilities.find_blob_in_tree(prev_commit.tree, file)
16+
blob = BlobFinder.find_blob_in_tree(prev_commit.tree, file)
1717
end
1818
return blob
1919
end

‎lib/git_statistics/utilities.rb‎

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,6 @@ def self.max_length_in_list(list, max = nil)
1111
max
1212
end
1313

14-
def self.get_blob(commit, file)
15-
# Split up file for Grit navigation
16-
file = file.split(File::Separator)
17-
18-
# Acquire blob of the file for this specific commit
19-
blob = Utilities.find_blob_in_tree(commit.tree, file)
20-
21-
# If we cannot find blob in current commit (deleted file), check previous commit
22-
if blob.nil? || blob.instance_of?(Grit::Tree)
23-
prev_commit = commit.parents.first
24-
return nil if prev_commit.nil?
25-
26-
blob = Utilities.find_blob_in_tree(prev_commit.tree, file)
27-
end
28-
return blob
29-
end
30-
31-
def self.find_blob_in_tree(tree, file)
32-
# Check If cannot find tree in commit or if we found a submodule as the changed file
33-
if tree.nil? || file.nil?
34-
return nil
35-
elsif tree.instance_of?(Grit::Submodule)
36-
return tree
37-
end
38-
39-
# If the blob is within the current directory (tree)
40-
if file.one?
41-
blob = tree / file.first
42-
43-
# Check if blob is nil (could not find changed file in tree)
44-
if blob.nil?
45-
46-
# Try looking for submodules as they cannot be found using tree / file notation
47-
tree.contents.each do |content|
48-
if file.first == content.name
49-
return tree
50-
end
51-
end
52-
53-
# Exit through recusion with the base case of a nil tree/blob
54-
return find_blob_in_tree(blob, file)
55-
end
56-
return blob
57-
else
58-
# Explore deeper in the tree to find the blob of the changed file
59-
return find_blob_in_tree(tree / file.first, file[1..-1])
60-
end
61-
end
62-
6314
def self.get_modified_time(file)
6415
if os == :windows
6516
raise "`stat` is not supported on the Windows operating system"

‎spec/blob_finder_spec.rb‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,41 @@
2626
end
2727
end
2828

29+
describe "#find_blob_in_tree" do
30+
let(:sha) {"7d6c29f0ad5860d3238debbaaf696e361bf8c541"} # Commit within repository
31+
let(:tree) {repo.tree(sha)}
32+
let(:file) {nil}
33+
let(:blob) {BlobFinder.find_blob_in_tree(tree, file.split(File::Separator))}
34+
subject { blob }
35+
36+
context "blob on root tree" do
37+
let(:file) {"Gemfile"}
38+
it { should be_instance_of Grit::Blob }
39+
its(:name) { should == file }
40+
end
41+
42+
context "blob down tree" do
43+
let(:file) {"lib/git_statistics/collector.rb"}
44+
it { should be_instance_of Grit::Blob }
45+
its(:name) { should == File.basename(file) }
46+
end
47+
48+
context "file is nil" do
49+
subject {BlobFinder.find_blob_in_tree(tree, nil)}
50+
it { should be_nil }
51+
end
52+
53+
context "file is empty" do
54+
let(:file) {""}
55+
it { should be_nil }
56+
end
57+
58+
context "file is submodule" do
59+
let(:sha) {"1940ef1c613a04f855d3867b874a4267d3e2c011"}
60+
let(:file) {"Spoon-Knife"}
61+
it { should be_instance_of Grit::Submodule }
62+
its(:name) { should == file }
63+
end
64+
end
65+
2966
end

‎spec/utilities_spec.rb‎

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -56,43 +56,6 @@
5656
end
5757
end
5858

59-
describe "#find_blob_in_tree" do
60-
let(:sha) {"7d6c29f0ad5860d3238debbaaf696e361bf8c541"} # Commit within repository
61-
let(:tree) {GIT_REPO.tree(sha)}
62-
let(:file) {nil}
63-
let(:blob) {Utilities.find_blob_in_tree(tree, file.split(File::Separator))}
64-
subject { blob }
65-
66-
context "blob on root tree" do
67-
let(:file) {"Gemfile"}
68-
it { should be_instance_of Grit::Blob }
69-
its(:name) { should == file }
70-
end
71-
72-
context "blob down tree" do
73-
let(:file) {"lib/git_statistics/collector.rb"}
74-
it { should be_instance_of Grit::Blob }
75-
its(:name) { should == File.basename(file) }
76-
end
77-
78-
context "file is nil" do
79-
subject {Utilities.find_blob_in_tree(tree, nil)}
80-
it { should be_nil }
81-
end
82-
83-
context "file is empty" do
84-
let(:file) {""}
85-
it { should be_nil }
86-
end
87-
88-
context "file is submodule" do
89-
let(:sha) {"1940ef1c613a04f855d3867b874a4267d3e2c011"}
90-
let(:file) {"Spoon-Knife"}
91-
it { should be_instance_of Grit::Submodule }
92-
its(:name) { should == file }
93-
end
94-
end
95-
9659
describe "#number_of_matching_files" do
9760
let(:pattern) { (/\d+\.json/) }
9861
subject {Utilities.number_of_matching_files(Dir.pwd, pattern)}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /