Skip to content

Instantly share code, notes, and snippets.

@KristofferC
Created August 29, 2016 12:19
Show Gist options
  • Save KristofferC/d4e3acbda9a5845dfc0738171c2f039d to your computer and use it in GitHub Desktop.
Save KristofferC/d4e3acbda9a5845dfc0738171c2f039d to your computer and use it in GitHub Desktop.
function read_version{T <: AbstractString}(s::Vector{T}, i::Int)
version = s[i]; i += 1
# @assert ismatch(Base.VERSION_REGEX, version)
i += 1 # skip "-----" under the version
sha = s[i]; i += 1
requires = String[]
while i <= length(s) && !isempty(s[i])
push!(requires, s[i]); i += 1
end
i += 1 # skip the empty string
return version, sha, requires, i
end
function available(repo::GitRepo)
pkgs = Dict{String,Dict{VersionNumber,Available}}()
head = LibGit2.head(repo)
ht = LibGit2.peel(LibGit2.GitTree, head)
for first_letter_tree in ht # A, B, C folders...
!isdir(first_letter_tree) && continue
first_letter_name = filename(first_letter_tree)
startswith(first_letter_name, '.') && continue
for pkg_entry in peel(GitTree, object(repo, first_letter_tree))
pkg_name = filename(pkg_entry)
(!endswith(pkg_name, ".versions") || !isfile(pkg_entry)) && continue
pkg_name = split(pkg_name, ".version")[1]
blob = peel(GitBlob, object(repo, pkg_entry))
file_lines = split(unsafe_string(convert(Cstring, content(blob))), '\n')
i = 3 # Skip url + empty line
isempty(file_lines[i]) && continue # TODO: Package is without a version
while i <= length(file_lines)
ver, sha, requires, i = read_version(file_lines, i)
haskey(pkgs, pkg_name) || (pkgs[pkg_name] = Dict{VersionNumber,Available}())
pkgs[pkg_name][convert(VersionNumber, ver)] = Available(sha, Reqs.parse(requires))
end
end
end
return pkgs
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment