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
73903ae8
Commit
73903ae8
authored
May 18, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix a RuntimeError: cannot modify frozen string
parent
d6c8a551
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
11 deletions
+11
-11
lib/gitlab/git/blob.rb
lib/gitlab/git/blob.rb
+10
-10
lib/gitlab/git/path_helper.rb
lib/gitlab/git/path_helper.rb
+1
-1
No files found.
lib/gitlab/git/blob.rb
View file @
73903ae8
...
@@ -104,25 +104,22 @@ module Gitlab
...
@@ -104,25 +104,22 @@ module Gitlab
# file.rb # oid: 4a
# file.rb # oid: 4a
#
#
#
#
# Blob.find_entry_by_path(repo, '1a', '
app/
file.rb') # => '4a'
# Blob.find_entry_by_path(repo, '1a', '
blog', 'app', '
file.rb') # => '4a'
#
#
def
find_entry_by_path
(
repository
,
root_id
,
path
)
def
find_entry_by_path
(
repository
,
root_id
,
*
path_parts
)
root_tree
=
repository
.
lookup
(
root_id
)
root_tree
=
repository
.
lookup
(
root_id
)
# Strip leading slashes
path
[
%r{^/*}
]
=
''
path_arr
=
path
.
split
(
'/'
)
entry
=
root_tree
.
find
do
|
entry
|
entry
=
root_tree
.
find
do
|
entry
|
entry
[
:name
]
==
path_
arr
[
0
]
entry
[
:name
]
==
path_
parts
[
0
]
end
end
return
nil
unless
entry
return
nil
unless
entry
if
path_
arr
.
size
>
1
if
path_
parts
.
size
>
1
return
nil
unless
entry
[
:type
]
==
:tree
return
nil
unless
entry
[
:type
]
==
:tree
path_
arr
.
shift
path_
parts
.
shift
find_entry_by_path
(
repository
,
entry
[
:oid
],
path_arr
.
join
(
'/'
)
)
find_entry_by_path
(
repository
,
entry
[
:oid
],
*
path_parts
)
else
else
[
:blob
,
:commit
].
include?
(
entry
[
:type
])
?
entry
:
nil
[
:blob
,
:commit
].
include?
(
entry
[
:type
])
?
entry
:
nil
end
end
...
@@ -185,10 +182,13 @@ module Gitlab
...
@@ -185,10 +182,13 @@ module Gitlab
def
find_by_rugged
(
repository
,
sha
,
path
,
limit
:)
def
find_by_rugged
(
repository
,
sha
,
path
,
limit
:)
return
unless
path
return
unless
path
# Strip any leading / characters from the path
path
=
path
.
sub
(
%r{
\A
/*}
,
''
)
rugged_commit
=
repository
.
lookup
(
sha
)
rugged_commit
=
repository
.
lookup
(
sha
)
root_tree
=
rugged_commit
.
tree
root_tree
=
rugged_commit
.
tree
blob_entry
=
find_entry_by_path
(
repository
,
root_tree
.
oid
,
path
)
blob_entry
=
find_entry_by_path
(
repository
,
root_tree
.
oid
,
*
path
.
split
(
'/'
)
)
return
nil
unless
blob_entry
return
nil
unless
blob_entry
...
...
lib/gitlab/git/path_helper.rb
View file @
73903ae8
...
@@ -6,7 +6,7 @@ module Gitlab
...
@@ -6,7 +6,7 @@ module Gitlab
class
<<
self
class
<<
self
def
normalize_path
(
filename
)
def
normalize_path
(
filename
)
# Strip all leading slashes so that //foo -> foo
# Strip all leading slashes so that //foo -> foo
filename
[
%r{^/*}
]
=
''
filename
=
filename
.
sub
(
%r{
\A
/*}
,
''
)
# Expand relative paths (e.g. foo/../bar)
# Expand relative paths (e.g. foo/../bar)
filename
=
Pathname
.
new
(
filename
)
filename
=
Pathname
.
new
(
filename
)
...
...
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