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
e108fe91
Commit
e108fe91
authored
May 02, 2012
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Downloader::Git] Cache repos
parent
e19bf01c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
98 deletions
+24
-98
downloader.rb
lib/cocoapods/downloader.rb
+2
-7
git.rb
lib/cocoapods/downloader/git.rb
+22
-52
downloader_spec.rb
spec/unit/downloader_spec.rb
+0
-39
No files found.
lib/cocoapods/downloader.rb
View file @
e108fe91
...
...
@@ -3,7 +3,6 @@ require 'uri'
module
Pod
class
Downloader
autoload
:Git
,
'cocoapods/downloader/git'
autoload
:GitHub
,
'cocoapods/downloader/git'
autoload
:Mercurial
,
'cocoapods/downloader/mercurial'
autoload
:Subversion
,
'cocoapods/downloader/subversion'
autoload
:Http
,
'cocoapods/downloader/http'
...
...
@@ -26,17 +25,13 @@ module Pod
def
clean
# implement in sub-classes
end
private
def
self
.
for_target
(
target_path
,
options
)
options
=
options
.
dup
if
url
=
options
.
delete
(
:git
)
if
url
.
to_s
=~
/github.com/
GitHub
.
new
(
target_path
,
url
,
options
)
else
Git
.
new
(
target_path
,
url
,
options
)
end
elsif
url
=
options
.
delete
(
:hg
)
Mercurial
.
new
(
target_path
,
url
,
options
)
elsif
url
=
options
.
delete
(
:svn
)
...
...
lib/cocoapods/downloader/git.rb
View file @
e108fe91
require
'open-uri'
require
'tempfile'
require
'zlib'
require
'digest/sha1'
module
Pod
class
Downloader
...
...
@@ -8,6 +9,7 @@ module Pod
executable
:git
def
download
prepare_cache
if
options
[
:tag
]
download_tag
elsif
options
[
:commit
]
...
...
@@ -17,14 +19,31 @@ module Pod
end
end
def
prepare_cache
# TODO:clean oldest repos if the cache becomes too big
if
cache_path
.
exist?
#TODO: check remote and reset hard
Dir
.
chdir
(
cache_path
)
{
git
"pull"
}
else
FileUtils
.
mkdir_p
cache_path
Dir
.
chdir
(
cache_path
)
do
git
"clone '
#{
url
}
' ."
end
end
end
def
cache_path
@cache_path
||=
Pathname
.
new
"/var/tmp/CocoaPods/Git/
#{
Digest
::
SHA1
.
hexdigest
(
url
)
}
/"
end
def
download_head
git
"clone '
#{
url
}
' '
#{
target_path
}
'"
git
"clone '
#{
cache_path
}
' '
#{
target_path
}
'"
end
def
download_tag
Dir
.
chdir
(
target_path
)
do
git
"init"
git
"remote add origin '
#{
url
}
'"
git
"remote add origin '
#{
cache_path
}
'"
git
"fetch origin tags/
#{
options
[
:tag
]
}
"
git
"reset --hard FETCH_HEAD"
git
"checkout -b activated-pod-commit"
...
...
@@ -32,7 +51,7 @@ module Pod
end
def
download_commit
git
"clone '
#{
url
}
' '
#{
target_path
}
'"
git
"clone '
#{
cache_path
}
' '
#{
target_path
}
'"
Dir
.
chdir
(
target_path
)
do
git
"checkout -b activated-pod-commit
#{
options
[
:commit
]
}
"
...
...
@@ -43,54 +62,5 @@ module Pod
(
target_path
+
'.git'
).
rmtree
end
end
class
GitHub
<
Git
def
download_head
download_only?
?
download_and_extract_tarball
(
'master'
)
:
super
end
def
download_tag
super
unless
download_only?
download_only?
?
download_and_extract_tarball
(
options
[:
tag
])
:
super
end
def
download_commit
super
unless
download_only?
download_only?
?
download_and_extract_tarball
(
options
[:
commit
])
:
super
end
def
clean
if
download_only?
FileUtils
.
rm_f
(
tmp_path
)
else
super
end
end
def
tarball_url_for
(
id
)
original_url
,
username
,
reponame
=
*
(
url
.
match
(
/[:\/]([\w\-]+)\/([\w\-]+)\.git/
).
to_a
)
"https://github.com/
#{
username
}
/
#{
reponame
}
/tarball/
#{
id
}
"
end
def
tmp_path
target_path
+
"tarball.tar.gz"
end
private
def
download_only?
@options
[
:download_only
]
end
def
download_and_extract_tarball
(
id
)
File
.
open
(
tmp_path
,
"w+"
)
do
|
tmpfile
|
open
tarball_url_for
(
id
)
do
|
archive
|
tmpfile
.
write
Zlib
::
GzipReader
.
new
(
archive
).
read
end
system
"tar xf
#{
tmpfile
.
path
}
-C
#{
target_path
}
--strip-components 1"
end
end
end
end
end
spec/unit/downloader_spec.rb
View file @
e108fe91
...
...
@@ -19,43 +19,4 @@ describe "Pod::Downloader" do
downloader
.
url
.
should
==
'http://banana-corp.local/banana-lib.git'
downloader
.
options
.
should
==
{
:tag
=>
'v1.0'
}
end
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
.
specification
.
stubs
(
:source
).
returns
(
:git
=>
"git://github.com/CocoaPods/CocoaPods"
)
downloader
=
Pod
::
Downloader
.
for_pod
(
pod
)
downloader
.
should
.
be
.
instance_of
Pod
::
Downloader
::
GitHub
end
end
describe
Pod
::
Downloader
::
GitHub
do
it
'can convert public HTTP repository URLs to the tarball URL'
do
downloader
=
Pod
::
Downloader
.
for_pod
(
stub_pod_with_source
(
:git
=>
"https://github.com/CocoaPods/CocoaPods.git"
))
downloader
.
tarball_url_for
(
'master'
).
should
==
"https://github.com/CocoaPods/CocoaPods/tarball/master"
end
it
'can convert private HTTP repository URLs to the tarball URL'
do
downloader
=
Pod
::
Downloader
.
for_pod
(
stub_pod_with_source
(
:git
=>
"https://lukeredpath@github.com/CocoaPods/CocoaPods.git"
))
downloader
.
tarball_url_for
(
'master'
).
should
==
"https://github.com/CocoaPods/CocoaPods/tarball/master"
end
it
'can convert private SSH repository URLs to the tarball URL'
do
downloader
=
Pod
::
Downloader
.
for_pod
(
stub_pod_with_source
(
:git
=>
"git@github.com:CocoaPods/CocoaPods.git"
))
downloader
.
tarball_url_for
(
'master'
).
should
==
"https://github.com/CocoaPods/CocoaPods/tarball/master"
end
it
'can convert public git protocol repository URLs to the tarball URL'
do
downloader
=
Pod
::
Downloader
.
for_pod
(
stub_pod_with_source
(
:git
=>
"git://github.com/CocoaPods/CocoaPods.git"
))
downloader
.
tarball_url_for
(
'master'
).
should
==
"https://github.com/CocoaPods/CocoaPods/tarball/master"
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