1
1
using LibGit2
2
+ using ProgressMeter
3
+ const update! = ProgressMeter. update!
2
4
3
5
export ArchiveSource, FileSource, GitSource, DirectorySource
4
6
@@ -142,10 +144,34 @@ function download_source(source::T; verbose::Bool = false, downloads_dir = stora
142
144
return SetupSource {T} (src_path, source. hash, gettarget (source))
143
145
end
144
146
147
+ struct GitTransferProgress
148
+ total_objects:: Cuint
149
+ indexed_objects:: Cuint
150
+ received_objects:: Cuint
151
+ local_objects:: Cuint
152
+ total_deltas:: Cuint
153
+ indexed_deltas:: Cuint
154
+ received_bytes:: Csize_t
155
+ end
156
+
157
+ function transfer_progress (progress:: Ptr{GitTransferProgress} , p:: Any )
158
+ progress = unsafe_load (progress)
159
+ p. n = progress. total_objects
160
+ if progress. total_deltas != 0
161
+ p. desc = " Resolving Deltas: "
162
+ p. n = progress. total_deltas
163
+ update! (p, Int (max (1 , progress. indexed_deltas)))
164
+ else
165
+ update! (p, Int (max (1 , progress. received_objects)))
166
+ end
167
+ return Cint (0 )
168
+ end
169
+
145
170
function cached_git_clone (url:: String ;
146
171
hash_to_check:: Union{Nothing, String} = nothing ,
147
172
downloads_dir:: String = storage_dir (" downloads" ),
148
173
verbose:: Bool = false ,
174
+ progressbar:: Bool = false ,
149
175
)
150
176
repo_path = joinpath (downloads_dir, " clones" , string (basename (url), " -" , bytes2hex (sha256 (url))))
151
177
if isdir (repo_path)
@@ -163,11 +189,29 @@ function cached_git_clone(url::String;
163
189
end
164
190
end
165
191
else
192
+ # If there is no repo_path yet, clone it down into a bare repository
166
193
if verbose
167
194
@info (" Cloning git repository" , url, repo_path)
168
195
end
169
- # If there is no repo_path yet, clone it down into a bare repository
170
- LibGit2. clone (url, repo_path; isbare= true )
196
+ if progressbar
197
+ # Clone with a progress bar
198
+ p = Progress (0 , 1 , " Cloning: " )
199
+ GC. @preserve p begin
200
+ callbacks = LibGit2. RemoteCallbacks (
201
+ transfer_progress= @cfunction (
202
+ transfer_progress,
203
+ Cint,
204
+ (Ptr{GitTransferProgress}, Any)
205
+ ),
206
+ payload = p
207
+ )
208
+ fetch_opts = LibGit2. FetchOptions (; callbacks)
209
+ clone_opts = LibGit2. CloneOptions (; fetch_opts, bare = Cint (true ))
210
+ LibGit2. clone (url, repo_path, clone_opts)
211
+ end
212
+ else
213
+ LibGit2. clone (url, repo_path; isbare= true )
214
+ end
171
215
end
172
216
return repo_path
173
217
end
0 commit comments