Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
03f41e28
Commit
03f41e28
authored
Apr 02, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gitlab::Git::Tree & Blob added
parent
0c5795a4
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
65 additions
and
26 deletions
+65
-26
app/controllers/refs_controller.rb
app/controllers/refs_controller.rb
+1
-1
app/helpers/tree_helper.rb
app/helpers/tree_helper.rb
+2
-3
app/models/merge_request.rb
app/models/merge_request.rb
+1
-1
app/models/tree.rb
app/models/tree.rb
+1
-5
app/views/commits/_diffs.html.haml
app/views/commits/_diffs.html.haml
+4
-4
app/views/tree/_tree.html.haml
app/views/tree/_tree.html.haml
+1
-1
lib/extracts_path.rb
lib/extracts_path.rb
+1
-1
lib/gitlab/git/blob.rb
lib/gitlab/git/blob.rb
+30
-0
lib/gitlab/git/tree.rb
lib/gitlab/git/tree.rb
+24
-10
No files found.
app/controllers/refs_controller.rb
View file @
03f41e28
...
@@ -30,7 +30,7 @@ class RefsController < ProjectResourceController
...
@@ -30,7 +30,7 @@ class RefsController < ProjectResourceController
end
end
def
logs_tree
def
logs_tree
contents
=
@tree
.
content
s
contents
=
@tree
.
entrie
s
@logs
=
contents
.
map
do
|
content
|
@logs
=
contents
.
map
do
|
content
|
file
=
params
[
:path
]
?
File
.
join
(
params
[
:path
],
content
.
name
)
:
content
.
name
file
=
params
[
:path
]
?
File
.
join
(
params
[
:path
],
content
.
name
)
:
content
.
name
last_commit
=
@repo
.
commits
(
@commit
.
id
,
file
,
1
).
last
last_commit
=
@repo
.
commits
(
@commit
.
id
,
file
,
1
).
last
...
...
app/helpers/tree_helper.rb
View file @
03f41e28
...
@@ -3,9 +3,9 @@ module TreeHelper
...
@@ -3,9 +3,9 @@ module TreeHelper
# their corresponding partials
# their corresponding partials
#
#
# contents - A Grit::Tree object for the current tree
# contents - A Grit::Tree object for the current tree
def
render_tree
(
contents
)
def
render_tree
(
tree
)
# Render Folders before Files/Submodules
# Render Folders before Files/Submodules
folders
,
files
=
contents
.
partition
{
|
v
|
v
.
kind_of?
(
Grit
::
Tree
)
}
folders
,
files
=
tree
.
trees
,
tree
.
blobs
tree
=
""
tree
=
""
...
@@ -91,5 +91,4 @@ module TreeHelper
...
@@ -91,5 +91,4 @@ module TreeHelper
file
=
File
.
join
(
tree
.
path
,
".."
)
file
=
File
.
join
(
tree
.
path
,
".."
)
tree_join
(
tree
.
ref
,
file
)
tree_join
(
tree
.
ref
,
file
)
end
end
end
end
app/models/merge_request.rb
View file @
03f41e28
...
@@ -152,7 +152,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -152,7 +152,7 @@ class MergeRequest < ActiveRecord::Base
end
end
def
commits
def
commits
load_commits
(
st_commits
)
||
[]
load_commits
(
st_commits
||
[])
end
end
def
probably_merged?
def
probably_merged?
...
...
app/models/tree.rb
View file @
03f41e28
class
Tree
class
Tree
attr_accessor
:
path
,
:tree
,
:ref
attr_accessor
:
raw
def
initialize
(
repository
,
sha
,
ref
=
nil
,
path
=
nil
)
def
initialize
(
repository
,
sha
,
ref
=
nil
,
path
=
nil
)
@raw
=
Gitlab
::
Git
::
Tree
.
new
(
repository
,
sha
,
ref
,
path
)
@raw
=
Gitlab
::
Git
::
Tree
.
new
(
repository
,
sha
,
ref
,
path
)
end
end
def
invalid?
@raw
.
nil?
end
def
method_missing
(
m
,
*
args
,
&
block
)
def
method_missing
(
m
,
*
args
,
&
block
)
@raw
.
send
(
m
,
*
args
,
&
block
)
@raw
.
send
(
m
,
*
args
,
&
block
)
end
end
...
...
app/views/commits/_diffs.html.haml
View file @
03f41e28
...
@@ -16,8 +16,8 @@
...
@@ -16,8 +16,8 @@
-
unless
@suppress_diff
-
unless
@suppress_diff
-
diffs
.
each_with_index
do
|
diff
,
i
|
-
diffs
.
each_with_index
do
|
diff
,
i
|
-
next
if
diff
.
diff
.
empty?
-
next
if
diff
.
diff
.
empty?
-
file
=
Tree
.
new
(
@repository
,
@commit
.
id
,
@ref
,
diff
.
new_path
)
-
file
=
Gitlab
::
Git
::
Blob
.
new
(
@repository
,
@commit
.
id
,
@ref
,
diff
.
new_path
)
-
file
=
Tree
.
new
(
@repository
,
@commit
.
parent_id
,
@ref
,
diff
.
old_path
)
unless
file
-
file
=
Gitlab
::
Git
::
Blob
.
new
(
@repository
,
@commit
.
parent_id
,
@ref
,
diff
.
old_path
)
unless
file
.
exists?
-
next
unless
file
-
next
unless
file
.file
{
id:
"diff-#{i}"
}
.file
{
id:
"diff-#{i}"
}
.header
.header
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
%span
=
diff
.
old_path
%span
=
diff
.
old_path
-
if
@commit
.
parent_ids
.
present?
-
if
@commit
.
parent_ids
.
present?
=
link_to
project_tree_path
(
@project
,
tree_join
(
@commit
.
p
rev_commi
t_id
,
diff
.
new_path
)),
{
:class
=>
'btn btn-tiny pull-right view-file'
}
do
=
link_to
project_tree_path
(
@project
,
tree_join
(
@commit
.
p
aren
t_id
,
diff
.
new_path
)),
{
:class
=>
'btn btn-tiny pull-right view-file'
}
do
View file @
View file @
%span
.commit-short-id
=
@commit
.
short_id
(
6
)
%span
.commit-short-id
=
@commit
.
short_id
(
6
)
-
else
-
else
...
@@ -43,7 +43,7 @@
...
@@ -43,7 +43,7 @@
-
if
file
.
text?
-
if
file
.
text?
=
render
"commits/text_file"
,
diff:
diff
,
index:
i
=
render
"commits/text_file"
,
diff:
diff
,
index:
i
-
elsif
file
.
image?
-
elsif
file
.
image?
-
old_file
=
Tree
.
new
(
@repository
,
@commit
.
parent_id
,
@ref
,
diff
.
old_path
)
if
@commit
.
parent_id
-
old_file
=
Gitlab
::
Git
::
Blob
.
new
(
@repository
,
@commit
.
parent_id
,
@ref
,
diff
.
old_path
)
if
@commit
.
parent_id
=
render
"commits/image"
,
diff:
diff
,
old_file:
old_file
,
file:
file
,
index:
i
=
render
"commits/image"
,
diff:
diff
,
old_file:
old_file
,
file:
file
,
index:
i
-
else
-
else
%p
.nothing_here_message
No preview for this file type
%p
.nothing_here_message
No preview for this file type
app/views/tree/_tree.html.haml
View file @
03f41e28
...
@@ -32,7 +32,7 @@
...
@@ -32,7 +32,7 @@
%td
%td
%td
%td
=
render_tree
(
tree
.
contents
)
=
render_tree
(
tree
)
-
if
tree
.
readme
-
if
tree
.
readme
=
render
"tree/readme"
,
readme:
tree
.
readme
=
render
"tree/readme"
,
readme:
tree
.
readme
...
...
lib/extracts_path.rb
View file @
03f41e28
...
@@ -104,7 +104,7 @@ module ExtractsPath
...
@@ -104,7 +104,7 @@ module ExtractsPath
@tree
=
Tree
.
new
(
@project
.
repository
,
@commit
.
id
,
@ref
,
@path
)
@tree
=
Tree
.
new
(
@project
.
repository
,
@commit
.
id
,
@ref
,
@path
)
raise
InvalidPathError
if
@tree
.
invalid
?
raise
InvalidPathError
unless
@tree
.
exists
?
rescue
RuntimeError
,
NoMethodError
,
InvalidPathError
rescue
RuntimeError
,
NoMethodError
,
InvalidPathError
not_found!
not_found!
end
end
...
...
lib/gitlab/git/blob.rb
0 → 100644
View file @
03f41e28
module
Gitlab
module
Git
class
Blob
include
Linguist
::
BlobHelper
attr_accessor
:raw_blob
delegate
:name
,
to: :raw_blob
def
initialize
(
repository
,
sha
,
ref
,
path
)
@repository
,
@sha
,
@ref
=
repository
,
sha
,
ref
@commit
=
@repository
.
commit
(
sha
)
@raw_blob
=
@repository
.
tree
(
@commit
,
path
)
end
def
data
if
raw_blob
raw_blob
.
data
else
nil
end
end
def
exists?
@raw_blob
end
end
end
end
lib/gitlab/git/tree.rb
View file @
03f41e28
module
Gitlab
module
Gitlab
module
Git
module
Git
class
Tree
class
Tree
include
Linguist
::
BlobHelper
attr_accessor
:repository
,
:sha
,
:path
,
:ref
,
:raw_tree
,
:id
attr_accessor
:repository
,
:sha
,
:path
,
:ref
,
:raw_tree
def
initialize
(
repository
,
sha
,
ref
=
nil
,
path
=
nil
)
def
initialize
(
repository
,
sha
,
ref
=
nil
,
path
=
nil
)
@repository
,
@sha
,
@ref
=
repository
,
sha
,
ref
@repository
,
@sha
,
@ref
,
@path
=
repository
,
sha
,
ref
,
path
@path
=
nil
if
@path
.
blank?
# Load tree from repository
# Load tree from repository
@commit
=
@repository
.
commit
(
sha
)
@commit
=
@repository
.
commit
(
@sha
)
@raw_tree
=
@repository
.
tree
(
@commit
,
path
)
@raw_tree
=
@repository
.
tree
(
@commit
,
@path
)
end
def
exists?
raw_tree
end
end
def
empty?
def
empty?
data
.
blank?
data
.
blank?
end
end
def
data
def
trees
raw_tree
.
data
entries
.
select
{
|
t
|
t
.
is_a?
(
Grit
::
Tree
)
}
end
def
blobs
entries
.
select
{
|
t
|
t
.
is_a?
(
Grit
::
Blob
)
}
end
end
def
is_blob?
def
is_blob?
tree
.
is_a?
(
Grit
::
Blob
)
raw_
tree
.
is_a?
(
Grit
::
Blob
)
end
end
def
up_dir?
def
up_dir?
...
@@ -30,7 +38,13 @@ module Gitlab
...
@@ -30,7 +38,13 @@ module Gitlab
end
end
def
readme
def
readme
@readme
||=
contents
.
find
{
|
c
|
c
.
is_a?
(
Grit
::
Blob
)
and
c
.
name
=~
/^readme/i
}
@readme
||=
entries
.
find
{
|
c
|
c
.
is_a?
(
Grit
::
Blob
)
and
c
.
name
=~
/^readme/i
}
end
protected
def
entries
raw_tree
.
contents
end
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment