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
d1788235
Commit
d1788235
authored
May 03, 2012
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Downloader::Git] Completed cache support
- ensure that cache git repos are clean - added cache size limit
parent
b86595a3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
11 deletions
+54
-11
config.rb
lib/cocoapods/config.rb
+2
-0
git.rb
lib/cocoapods/downloader/git.rb
+51
-11
spec_helper.rb
spec/spec_helper.rb
+1
-0
No files found.
lib/cocoapods/config.rb
View file @
d1788235
...
...
@@ -14,6 +14,7 @@ module Pod
attr_accessor
:clean
,
:verbose
,
:silent
attr_accessor
:generate_docs
,
:doc_install
,
:force_doc
attr_accessor
:integrate_targets
attr_accessor
:git_cache_size
alias_method
:clean?
,
:clean
alias_method
:verbose?
,
:verbose
...
...
@@ -27,6 +28,7 @@ module Pod
@repos_dir
=
Pathname
.
new
(
File
.
expand_path
(
"~/.cocoapods"
))
@verbose
=
@silent
=
@force_doc
=
false
@clean
=
@generate_docs
=
@doc_install
=
@integrate_targets
=
true
@git_cache_size
=
200
end
def
project_root
...
...
lib/cocoapods/downloader/git.rb
View file @
d1788235
...
...
@@ -6,10 +6,12 @@ require 'digest/sha1'
module
Pod
class
Downloader
class
Git
<
Downloader
include
Config
::
Mixin
executable
:git
def
download
prepare_cache
puts
'->'
.
green
<<
' Cloning git repo'
if
config
.
verbose?
if
options
[
:tag
]
download_tag
elsif
options
[
:commit
]
...
...
@@ -17,33 +19,71 @@ module Pod
else
download_head
end
removed_cached_repos_if_needed
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
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
"clone '
#{
url
}
' ."
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
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
||=
Pathname
.
new
"/var/tmp/CocoaPods/Git/
#{
Digest
::
SHA1
.
hexdigest
(
url
.
to_s
)
}
/"
@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 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
def
download_head
git
"clone '
#{
c
ache_path
}
' '
#{
target_path
}
'"
git
"clone '
#{
c
lone_url
}
' '
#{
target_path
}
'"
end
def
download_tag
Dir
.
chdir
(
target_path
)
do
git
"init"
git
"remote add origin '
#{
c
ache_path
}
'"
git
"remote add origin '
#{
c
lone_url
}
'"
git
"fetch origin tags/
#{
options
[
:tag
]
}
"
git
"reset --hard FETCH_HEAD"
git
"checkout -b activated-pod-commit"
...
...
@@ -51,7 +91,7 @@ module Pod
end
def
download_commit
git
"clone '
#{
c
ache_path
}
' '
#{
target_path
}
'"
git
"clone '
#{
c
lone_url
}
' '
#{
target_path
}
'"
Dir
.
chdir
(
target_path
)
do
git
"checkout -b activated-pod-commit
#{
options
[
:commit
]
}
"
...
...
spec/spec_helper.rb
View file @
d1788235
...
...
@@ -53,6 +53,7 @@ end
config
=
Pod
::
Config
.
instance
config
.
silent
=
true
config
.
repos_dir
=
SpecHelper
.
tmp_repos_path
config
.
git_cache_size
=
0
require
'tmpdir'
...
...
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