@@ -413,6 +413,44 @@ function get_tree_hash(tree::LibGit2.GitTree)
413
413
return unsafe_load (oid_ptr)
414
414
end
415
415
416
+ """
417
+ get_commit_sha(url::String, tree_hash::Base.SHA1; verbose::Bool=false)
418
+
419
+ Find the latest git commit corresponding to the given git tree SHA1 for the remote
420
+ repository with the given `url`. The repository is cached locally for quicker future
421
+ access. If `verbose` is `true`, print to screen some debugging information.
422
+
423
+ The return value is the commit SHA as a `String`, if the corresponding revision is found,
424
+ `nothing` otherwise.
425
+ """
426
+ function get_commit_sha (url:: String , tree_hash:: Base.SHA1 ; verbose:: Bool = false )
427
+ git_commit_sha = nothing
428
+ dir = cached_git_clone (url; verbose)
429
+
430
+ LibGit2. with (LibGit2. GitRepo (dir)) do repo
431
+ LibGit2. with (LibGit2. GitRevWalker (repo)) do walker
432
+ # The repo is cached, so locally it may be checking out an outdated commit.
433
+ # Start the search from HEAD of the tracking upstream repo.
434
+ try
435
+ LibGit2. push! (walker, LibGit2. GitHash (LibGit2. peel (LibGit2. GitCommit, LibGit2. upstream (LibGit2. head (repo)))))
436
+ catch
437
+ @warn (" Could not walk from origin branch!" )
438
+ LibGit2. push_head! (walker)
439
+ end
440
+ # For each commit in the git repo, check to see if its treehash
441
+ # matches the one we're looking for.
442
+ for oid in walker
443
+ tree = LibGit2. peel (LibGit2. GitTree, LibGit2. GitCommit (repo, oid))
444
+ if all (get_tree_hash (tree). val .== tree_hash. bytes)
445
+ git_commit_sha = LibGit2. string (oid)
446
+ break
447
+ end
448
+ end
449
+ end
450
+ end
451
+ return git_commit_sha
452
+ end
453
+
416
454
"""
417
455
get_addable_spec(name::AbstractString, version::VersionNumber)
418
456
@@ -467,39 +505,15 @@ function get_addable_spec(name::AbstractString, version::VersionNumber;
467
505
end
468
506
469
507
tree_hash_sha1 = first (tree_hashes)
470
- tree_hash_bytes = tree_hash_sha1. bytes
471
508
472
509
# Once we have a tree hash, turn that into a git commit sha
473
510
git_commit_sha = nothing
474
511
valid_url = nothing
475
512
for url in repo_urls
476
- dir = cached_git_clone (url; verbose)
477
-
478
- LibGit2. with (LibGit2. GitRepo (dir)) do repo
479
- LibGit2. with (LibGit2. GitRevWalker (repo)) do walker
480
- # The repo is cached, so locally it may be checking out an outdated commit.
481
- # Start the search from HEAD of the tracking upstream repo.
482
- try
483
- LibGit2. push! (walker, LibGit2. GitHash (LibGit2. peel (LibGit2. GitCommit, LibGit2. upstream (LibGit2. head (repo)))))
484
- catch
485
- @warn (" Could not walk from origin branch!" )
486
- LibGit2. push_head! (walker)
487
- end
488
- # For each commit in the git repo, check to see if its treehash
489
- # matches the one we're looking for.
490
- for oid in walker
491
- tree = LibGit2. peel (LibGit2. GitTree, LibGit2. GitCommit (repo, oid))
492
- if all (get_tree_hash (tree). val .== tree_hash_bytes)
493
- git_commit_sha = LibGit2. string (oid)
494
- valid_url = url
495
- break
496
- end
497
- end
498
- end
499
- end
500
-
513
+ git_commit_sha = get_commit_sha (url, tree_hash_sha1; verbose)
501
514
# Stop searching urls as soon as we find one
502
515
if git_commit_sha != = nothing
516
+ valid_url = url
503
517
break
504
518
end
505
519
end
@@ -508,7 +522,7 @@ function get_addable_spec(name::AbstractString, version::VersionNumber;
508
522
@error (" Unable to find revision for specified dependency!" ,
509
523
name,
510
524
version,
511
- tree_hash = bytes2hex (tree_hash_bytes ),
525
+ tree_hash = bytes2hex (tree_hash_sha1 . bytes ),
512
526
repo_urls,
513
527
)
514
528
error (" Unable to find revision for specified dependency!" )
0 commit comments