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
1a59766d
Commit
1a59766d
authored
Dec 20, 2016
by
Hiroyuki Sato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge two methods.
parent
e78f1048
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
13 deletions
+10
-13
app/models/repository.rb
app/models/repository.rb
+4
-7
lib/api/files.rb
lib/api/files.rb
+1
-1
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+5
-5
No files found.
app/models/repository.rb
View file @
1a59766d
...
...
@@ -654,19 +654,16 @@ class Repository
end
def
last_commit_for_path
(
sha
,
path
)
sha
=
cache_
last_commit_id_for_path
(
sha
,
path
)
sha
=
last_commit_id_for_path
(
sha
,
path
)
commit
(
sha
)
end
def
last_commit_id_for_path
(
sha
,
path
)
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
rev-list --max-count=1
#{
sha
}
--
#{
path
}
)
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
).
first
.
strip
end
def
cache_last_commit_id_for_path
(
sha
,
path
)
key
=
path
.
blank?
?
"last_commit_id_for_path:
#{
sha
}
"
:
"last_commit_id_for_path:
#{
sha
}
:
#{
Digest
::
SHA1
.
hexdigest
(
path
)
}
"
cache
.
fetch
(
key
)
do
last_commit_id_for_path
(
sha
,
path
)
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
rev-list --max-count=1
#{
sha
}
--
#{
path
}
)
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
).
first
.
strip
end
end
...
...
lib/api/files.rb
View file @
1a59766d
...
...
@@ -70,7 +70,7 @@ module API
ref:
params
[
:ref
],
blob_id:
blob
.
id
,
commit_id:
commit
.
id
,
last_commit_id:
repo
.
cache_
last_commit_id_for_path
(
commit
.
sha
,
params
[
:file_path
])
last_commit_id:
repo
.
last_commit_id_for_path
(
commit
.
sha
,
params
[
:file_path
])
}
end
...
...
spec/models/repository_spec.rb
View file @
1a59766d
...
...
@@ -142,16 +142,16 @@ describe Repository, models: true do
describe
'#last_commit_id_for_path'
do
subject
{
repository
.
last_commit_id_for_path
(
sample_commit
.
id
,
'.gitignore'
)
}
it
{
is_expected
.
to
eq
(
'c1acaa58bbcbc3eafe538cb8274ba387047b69f8'
)
}
end
it
"returns last commit id for a given path"
do
is_expected
.
to
eq
(
'c1acaa58bbcbc3eafe538cb8274ba387047b69f8'
)
end
describe
'#cache_last_commit_id_for_path'
do
it
"caches #last_commit_id_for_path"
do
it
"caches last commit id for a given path"
do
cache
=
repository
.
send
(
:cache
)
key
=
"last_commit_id_for_path:
#{
sample_commit
.
id
}
:
#{
Digest
::
SHA1
.
hexdigest
(
'.gitignore'
)
}
"
expect
(
cache
).
to
receive
(
:fetch
).
with
(
key
).
and_return
(
'c1acaa5'
)
expect
(
repository
.
cache_last_commit_id_for_path
(
sample_commit
.
id
,
'.gitignore'
))
.
to
eq
(
'c1acaa5'
)
is_expected
.
to
eq
(
'c1acaa5'
)
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