Skip to content

Commit

Permalink
API for status (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdayanand authored and StefanKarpinski committed Dec 27, 2017
1 parent a554607 commit 3b86007
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
15 changes: 15 additions & 0 deletions src/API.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module API

import Pkg3
using Pkg3.Display.DiffEntry
import Pkg3: depots, logdir, TOML
using Pkg3: Types, Dates
using Base.Random.UUID
Expand Down Expand Up @@ -127,6 +128,20 @@ function test(env::EnvCache, pkgs::Vector{PackageSpec}; coverage=false, preview=
end


function convert(::Type{Dict{String, VersionNumber}}, diffs::Union{Array{DiffEntry}, Void})
version_status = Dict{String, VersionNumber}()
diffs == nothing && return version_status
for entry in diffs
version_status[entry.name] = entry.new.ver
end
return version_status
end

function installed(mode::Symbol=:manifest)::Dict{String, VersionNumber}
diff = Pkg3.Display.status(EnvCache(), mode, true)
convert(Dict{String, VersionNumber}, diff)
end

function recursive_dir_size(path)
sz = 0
for (root, dirs, files) in walkdir(path)
Expand Down
18 changes: 12 additions & 6 deletions src/Display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ const colors = Dict(
)
const color_dark = :light_black

function status(env::EnvCache, mode::Symbol)
function status(env::EnvCache, mode::Symbol, use_as_api=false)
project₀ = project₁ = env.project
manifest₀ = manifest₁ = env.manifest
diff = nothing

if env.git != nothing
git_path = LibGit2.path(env.git)
project_path = relpath(env.project_file, git_path)
Expand All @@ -31,21 +33,25 @@ function status(env::EnvCache, mode::Symbol)
m₀ = filter_manifest(in_project(project₀["deps"]), manifest₀)
m₁ = filter_manifest(in_project(project₁["deps"]), manifest₁)
info("Status ", pathrepr(env, env.project_file))
print_diff(manifest_diff(m₀, m₁))
diff = manifest_diff(m₀, m₁)
use_as_api || print_diff(diff)
end
if mode == :manifest
info("Status ", pathrepr(env, env.manifest_file))
print_diff(manifest_diff(manifest₀, manifest₁))
diff = manifest_diff(manifest₀, manifest₁)
use_as_api || print_diff(diff)
elseif mode == :combined
p = !in_project(merge(project₀["deps"], project₁["deps"]))
m₀ = filter_manifest(p, manifest₀)
m₁ = filter_manifest(p, manifest₁)
diff = filter!(x->x.old != x.new, manifest_diff(m₀, m₁))
if !isempty(diff)
c_diff = filter!(x->x.old != x.new, manifest_diff(m₀, m₁))
if !isempty(c_diff)
info("Status ", pathrepr(env, env.manifest_file))
print_diff(diff)
use_as_api || print_diff(c_diff)
diff = Base.vcat(c_diff, diff)
end
end
return diff
end

function print_project_diff(env₀::EnvCache, env₁::EnvCache)
Expand Down
2 changes: 1 addition & 1 deletion src/Pkg3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ include("Operations.jl")
include("REPLMode.jl")
include("API.jl")

import .API: add, rm, up, test, gc, init, build
import .API: add, rm, up, test, gc, init, build, installed
const update = up

function __init__()
Expand Down

0 comments on commit 3b86007

Please sign in to comment.