Skip to content

Commit 9096e44

Browse files
committed
add commit hash information to registry
1 parent 77e2a02 commit 9096e44

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

src/register.jl

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,25 @@ end
326326
function update_versions_file(pkg::Project,
327327
versions_file::AbstractString,
328328
versions_data::Dict{String, Any},
329-
tree_hash::AbstractString)
329+
tree_hash::AbstractString;
330+
commit_hash::Union{AbstractString,Nothing}=nothing,
331+
tag_hash::Union{AbstractString,Nothing}=nothing,
332+
tag_name::Union{AbstractString,Nothing}=nothing,
333+
subdir::AbstractString="",
334+
)
330335
version_info = Dict{String, Any}("git-tree-sha1" => string(tree_hash))
336+
if !isnothing(commit_hash)
337+
version_info["git-commit-sha1"] = commit_hash
338+
end
339+
if !isnothing(tag_hash)
340+
version_info["git-tag-sha1"] = tag_hash
341+
end
342+
if !isnothing(tag_name)
343+
version_info["git-tag-name"] = tag_name
344+
end
345+
if subdir != ""
346+
version_info["git-tree-path"] = subdir
347+
end
331348
versions_data[string(pkg.version)] = version_info
332349

333350
open(versions_file, "w") do io
@@ -341,10 +358,18 @@ function update_versions_file(pkg::Project,
341358
else
342359
if x == "git-tree-sha1"
343360
return 1
344-
elseif x == "yanked"
361+
elseif x == "git-commit-sha1"
345362
return 2
346-
else
363+
elseif x == "git-tag-sha1"
347364
return 3
365+
elseif x == "git-tag-name"
366+
return 4
367+
elseif x == "git-tree-path"
368+
return 5
369+
elseif x == "yanked"
370+
return 100
371+
else
372+
return 200
348373
end
349374
end
350375
end
@@ -528,7 +553,8 @@ end
528553

529554
function check_and_update_registry_files(pkg::Project, package_repo, tree_hash,
530555
registry_path, registry_deps_paths,
531-
status; subdir = "")
556+
status;
557+
commit_hash = nothing, tag_hash = nothing, tag_name = nothing, subdir = "")
532558
# find package in registry
533559
@debug("find package in registry")
534560
registry_file = joinpath(registry_path, "Registry.toml")
@@ -548,7 +574,7 @@ function check_and_update_registry_files(pkg::Project, package_repo, tree_hash,
548574
versions_file, versions_data = get_versions_file(package_path)
549575
old_versions = check_versions!(pkg, versions_data, status)
550576
haserror(status) && return
551-
update_versions_file(pkg, versions_file, versions_data, tree_hash)
577+
update_versions_file(pkg, versions_file, versions_data, tree_hash; commit_hash, tag_hash, tag_name, subdir)
552578

553579
# update package data: deps file
554580
@debug("update package data: deps file")
@@ -586,7 +612,10 @@ errors or warnings that occurred.
586612
* `registry_fork::AbstractString=registry: the git repository URL for a fork of the registry
587613
* `registry_deps::Vector{String}=[]`: the git repository URLs for any registries containing
588614
packages depended on by `pkg`
589-
* `subdir::AbstractString=""`: path to package within `package_repo`
615+
* `commit_hash::Union{AbstractString, Nothing}`: commit hash of the package revision (optional)
616+
* `tag_hash::Union{AbstractString, Nothing}`: tag hash of the package revision (optional)
617+
* `tag_name::Union{AbstractString, Nothing}`: tag name of the package revision (optional)
618+
* `subdir::AbstractString=""`: path to package tree within `package_repo`
590619
* `push::Bool=false`: whether to push a registration branch to `registry` for consideration
591620
* `gitconfig::Dict=Dict()`: dictionary of configuration options for the `git` command
592621
"""
@@ -595,6 +624,9 @@ function register(
595624
registry::AbstractString = DEFAULT_REGISTRY_URL,
596625
registry_fork::AbstractString = registry,
597626
registry_deps::Vector{<:AbstractString} = AbstractString[],
627+
commit_hash::Union{AbstractString,Nothing} = nothing,
628+
tag_hash::Union{AbstractString,Nothing} = nothing,
629+
tag_name::Union{AbstractString,Nothing} = nothing,
598630
subdir::AbstractString = "",
599631
checks_triggering_error = registrator_errors,
600632
push::Bool = false,
@@ -643,7 +675,8 @@ function register(
643675

644676
check_and_update_registry_files(pkg, package_repo, tree_hash,
645677
registry_path, registry_deps_paths,
646-
status, subdir = subdir)
678+
status;
679+
commit_hash, tag_hash, tag_name, subdir)
647680
haserror(status) && return set_metadata!(regbr, status)
648681

649682
regtreesha = get_registrator_tree_sha()

test/regedit.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,21 @@ end
295295
@test data["1.0.0"] isa Dict
296296
@test collect(keys(data["1.0.0"])) == ["git-tree-sha1"]
297297
@test data["1.0.0"]["git-tree-sha1"] == tree_hash
298+
@test !haskey(data["1.0.0"], "git-commit-sha1")
299+
@test !haskey(data["1.0.0"], "git-tree-path")
300+
301+
commit_hash = repeat("1", 40)
302+
subdir = "sub/dir"
303+
update_versions_file(pkg, filename, data, tree_hash; commit_hash, subdir)
304+
305+
_, data = get_versions_file(temp_dir)
306+
@test data isa Dict
307+
@test collect(keys(data)) == ["1.0.0"]
308+
@test data["1.0.0"] isa Dict
309+
@test collect(keys(data["1.0.0"])) == ["git-tree-sha1"]
310+
@test data["1.0.0"]["git-tree-sha1"] == tree_hash
311+
@test data["1.0.0"]["git-commit-sha1"] = commit_hash
312+
@test data["1.0.0"]["git-tree-path"] = subdir
298313

299314
check_versions!(pkg, data, status)
300315
# This version was just registered, should be a complaint now.

0 commit comments

Comments
 (0)