Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
0d4dd44b
Commit
0d4dd44b
authored
May 09, 2012
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #248 from CocoaPods/git-cache
[Downloader::Git] Cache repos
parents
81d3550d
cfbdef54
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
10 deletions
+73
-10
config.rb
lib/cocoapods/config.rb
+2
-0
downloader.rb
lib/cocoapods/downloader.rb
+2
-2
git.rb
lib/cocoapods/downloader/git.rb
+64
-4
spec_helper.rb
spec/spec_helper.rb
+1
-0
downloader_spec.rb
spec/unit/downloader_spec.rb
+4
-4
No files found.
lib/cocoapods/config.rb
View file @
0d4dd44b
...
@@ -14,6 +14,7 @@ module Pod
...
@@ -14,6 +14,7 @@ module Pod
attr_accessor
:clean
,
:verbose
,
:silent
attr_accessor
:clean
,
:verbose
,
:silent
attr_accessor
:generate_docs
,
:doc_install
,
:force_doc
attr_accessor
:generate_docs
,
:doc_install
,
:force_doc
attr_accessor
:integrate_targets
attr_accessor
:integrate_targets
attr_accessor
:git_cache_size
alias_method
:clean?
,
:clean
alias_method
:clean?
,
:clean
alias_method
:verbose?
,
:verbose
alias_method
:verbose?
,
:verbose
...
@@ -27,6 +28,7 @@ module Pod
...
@@ -27,6 +28,7 @@ module Pod
@repos_dir
=
Pathname
.
new
(
File
.
expand_path
(
"~/.cocoapods"
))
@repos_dir
=
Pathname
.
new
(
File
.
expand_path
(
"~/.cocoapods"
))
@verbose
=
@silent
=
@force_doc
=
false
@verbose
=
@silent
=
@force_doc
=
false
@clean
=
@generate_docs
=
@doc_install
=
@integrate_targets
=
true
@clean
=
@generate_docs
=
@doc_install
=
@integrate_targets
=
true
@git_cache_size
=
500
end
end
def
project_root
def
project_root
...
...
lib/cocoapods/downloader.rb
View file @
0d4dd44b
...
@@ -26,9 +26,9 @@ module Pod
...
@@ -26,9 +26,9 @@ module Pod
def
clean
def
clean
# implement in sub-classes
# implement in sub-classes
end
end
private
private
def
self
.
for_target
(
target_path
,
options
)
def
self
.
for_target
(
target_path
,
options
)
options
=
options
.
dup
options
=
options
.
dup
if
url
=
options
.
delete
(
:git
)
if
url
=
options
.
delete
(
:git
)
...
...
lib/cocoapods/downloader/git.rb
View file @
0d4dd44b
require
'open-uri'
require
'open-uri'
require
'tempfile'
require
'tempfile'
require
'zlib'
require
'zlib'
require
'digest/sha1'
module
Pod
module
Pod
class
Downloader
class
Downloader
class
Git
<
Downloader
class
Git
<
Downloader
include
Config
::
Mixin
executable
:git
executable
:git
def
download
def
download
prepare_cache
puts
'->'
.
green
<<
' Cloning git repo'
if
config
.
verbose?
if
options
[
:tag
]
if
options
[
:tag
]
download_tag
download_tag
elsif
options
[
:commit
]
elsif
options
[
:commit
]
...
@@ -15,16 +19,72 @@ module Pod
...
@@ -15,16 +19,72 @@ module Pod
else
else
download_head
download_head
end
end
removed_cached_repos_if_needed
end
def
prepare_cache
return
if
config
.
git_cache_size
==
0
if
is_cache_valid?
puts
'->'
.
green
<<
" Updating cache git repo (
#{
cache_path
}
)"
if
config
.
verbose?
Dir
.
chdir
(
cache_path
)
do
git
"reset --hard HEAD"
git
"clean -d -x -f"
git
"pull"
end
else
puts
'->'
.
green
<<
" Creating cache git repo (
#{
cache_path
}
)"
if
config
.
verbose?
cache_path
.
rmtree
if
cache_path
.
exist?
cache_path
.
mkpath
git
"clone '
#{
url
}
'
#{
cache_path
}
"
end
end
def
removed_cached_repos_if_needed
return
unless
caches_dir
.
exist?
Dir
.
chdir
(
caches_dir
)
do
repos
=
Pathname
.
new
(
caches_dir
).
children
.
select
{
|
c
|
c
.
directory?
}.
sort_by
(
&
:ctime
)
while
caches_size
>=
config
.
git_cache_size
&&
!
repos
.
empty?
dir
=
repos
.
shift
puts
'->'
.
yellow
<<
" Removing git cache for `
#{
origin_url
(
dir
)
}
'"
if
config
.
verbose?
dir
.
rmtree
end
end
end
def
cache_path
@cache_path
||=
caches_dir
+
"
#{
Digest
::
SHA1
.
hexdigest
(
url
.
to_s
)
}
"
end
def
is_cache_valid?
cache_path
.
exist?
&&
origin_url
(
cache_path
)
==
url
end
def
origin_url
(
dir
)
Dir
.
chdir
(
dir
)
{
`git config remote.origin.url`
.
chomp
}
end
def
caches_dir
Pathname
.
new
"/var/tmp/CocoaPods/Git"
end
def
clone_url
# git_cache_size = 0 disables the cache
config
.
git_cache_size
==
0
?
url
:
cache_path
end
def
caches_size
# expressed in Mb
`du -cm`
.
split
(
"
\n
"
).
last
.
to_i
end
end
def
download_head
def
download_head
git
"clone '
#{
url
}
' '
#{
target_path
}
'"
git
"clone '
#{
clone_
url
}
' '
#{
target_path
}
'"
end
end
def
download_tag
def
download_tag
Dir
.
chdir
(
target_path
)
do
Dir
.
chdir
(
target_path
)
do
git
"init"
git
"init"
git
"remote add origin '
#{
url
}
'"
git
"remote add origin '
#{
clone_
url
}
'"
git
"fetch origin tags/
#{
options
[
:tag
]
}
"
git
"fetch origin tags/
#{
options
[
:tag
]
}
"
git
"reset --hard FETCH_HEAD"
git
"reset --hard FETCH_HEAD"
git
"checkout -b activated-pod-commit"
git
"checkout -b activated-pod-commit"
...
@@ -32,7 +92,7 @@ module Pod
...
@@ -32,7 +92,7 @@ module Pod
end
end
def
download_commit
def
download_commit
git
"clone '
#{
url
}
' '
#{
target_path
}
'"
git
"clone '
#{
clone_
url
}
' '
#{
target_path
}
'"
Dir
.
chdir
(
target_path
)
do
Dir
.
chdir
(
target_path
)
do
git
"checkout -b activated-pod-commit
#{
options
[
:commit
]
}
"
git
"checkout -b activated-pod-commit
#{
options
[
:commit
]
}
"
...
@@ -71,7 +131,7 @@ module Pod
...
@@ -71,7 +131,7 @@ module Pod
original_url
,
username
,
reponame
=
*
(
url
.
match
(
/[:\/]([\w\-]+)\/([\w\-]+)\.git/
).
to_a
)
original_url
,
username
,
reponame
=
*
(
url
.
match
(
/[:\/]([\w\-]+)\/([\w\-]+)\.git/
).
to_a
)
"https://github.com/
#{
username
}
/
#{
reponame
}
/tarball/
#{
id
}
"
"https://github.com/
#{
username
}
/
#{
reponame
}
/tarball/
#{
id
}
"
end
end
def
tmp_path
def
tmp_path
target_path
+
"tarball.tar.gz"
target_path
+
"tarball.tar.gz"
end
end
...
...
spec/spec_helper.rb
View file @
0d4dd44b
...
@@ -53,6 +53,7 @@ end
...
@@ -53,6 +53,7 @@ end
config
=
Pod
::
Config
.
instance
config
=
Pod
::
Config
.
instance
config
.
silent
=
true
config
.
silent
=
true
config
.
repos_dir
=
SpecHelper
.
tmp_repos_path
config
.
repos_dir
=
SpecHelper
.
tmp_repos_path
config
.
git_cache_size
=
0
require
'tmpdir'
require
'tmpdir'
...
...
spec/unit/downloader_spec.rb
View file @
0d4dd44b
...
@@ -19,7 +19,7 @@ describe "Pod::Downloader" do
...
@@ -19,7 +19,7 @@ describe "Pod::Downloader" do
downloader
.
url
.
should
==
'http://banana-corp.local/banana-lib.git'
downloader
.
url
.
should
==
'http://banana-corp.local/banana-lib.git'
downloader
.
options
.
should
==
{
:tag
=>
'v1.0'
}
downloader
.
options
.
should
==
{
:tag
=>
'v1.0'
}
end
end
it
'returns a github downloader when the :git URL is on github'
do
it
'returns a github downloader when the :git URL is on github'
do
pod
=
Pod
::
LocalPod
.
new
(
fixture_spec
(
'banana-lib/BananaLib.podspec'
),
temporary_sandbox
,
Pod
::
Platform
.
ios
)
pod
=
Pod
::
LocalPod
.
new
(
fixture_spec
(
'banana-lib/BananaLib.podspec'
),
temporary_sandbox
,
Pod
::
Platform
.
ios
)
pod
.
specification
.
stubs
(
:source
).
returns
(
:git
=>
"git://github.com/CocoaPods/CocoaPods"
)
pod
.
specification
.
stubs
(
:source
).
returns
(
:git
=>
"git://github.com/CocoaPods/CocoaPods"
)
...
@@ -36,21 +36,21 @@ describe Pod::Downloader::GitHub do
...
@@ -36,21 +36,21 @@ describe Pod::Downloader::GitHub do
))
))
downloader
.
tarball_url_for
(
'master'
).
should
==
"https://github.com/CocoaPods/CocoaPods/tarball/master"
downloader
.
tarball_url_for
(
'master'
).
should
==
"https://github.com/CocoaPods/CocoaPods/tarball/master"
end
end
it
'can convert private HTTP repository URLs to the tarball URL'
do
it
'can convert private HTTP repository URLs to the tarball URL'
do
downloader
=
Pod
::
Downloader
.
for_pod
(
stub_pod_with_source
(
downloader
=
Pod
::
Downloader
.
for_pod
(
stub_pod_with_source
(
:git
=>
"https://lukeredpath@github.com/CocoaPods/CocoaPods.git"
:git
=>
"https://lukeredpath@github.com/CocoaPods/CocoaPods.git"
))
))
downloader
.
tarball_url_for
(
'master'
).
should
==
"https://github.com/CocoaPods/CocoaPods/tarball/master"
downloader
.
tarball_url_for
(
'master'
).
should
==
"https://github.com/CocoaPods/CocoaPods/tarball/master"
end
end
it
'can convert private SSH repository URLs to the tarball URL'
do
it
'can convert private SSH repository URLs to the tarball URL'
do
downloader
=
Pod
::
Downloader
.
for_pod
(
stub_pod_with_source
(
downloader
=
Pod
::
Downloader
.
for_pod
(
stub_pod_with_source
(
:git
=>
"git@github.com:CocoaPods/CocoaPods.git"
:git
=>
"git@github.com:CocoaPods/CocoaPods.git"
))
))
downloader
.
tarball_url_for
(
'master'
).
should
==
"https://github.com/CocoaPods/CocoaPods/tarball/master"
downloader
.
tarball_url_for
(
'master'
).
should
==
"https://github.com/CocoaPods/CocoaPods/tarball/master"
end
end
it
'can convert public git protocol repository URLs to the tarball URL'
do
it
'can convert public git protocol repository URLs to the tarball URL'
do
downloader
=
Pod
::
Downloader
.
for_pod
(
stub_pod_with_source
(
downloader
=
Pod
::
Downloader
.
for_pod
(
stub_pod_with_source
(
:git
=>
"git://github.com/CocoaPods/CocoaPods.git"
:git
=>
"git://github.com/CocoaPods/CocoaPods.git"
...
...
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