Skip to content

Commit

Permalink
More tests for walker, fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt committed Sep 14, 2017
1 parent 957848b commit c172e92
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion base/libgit2/walker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ end
repository(w::GitRevWalker) = w.owner

"""
LibGit2.map(f::Function, walker::GitRevWalker; oid::GitHash=GitHash(), by::Cint=Consts.SORT_NONE, rev::Bool=false)
LibGit2.map(f::Function, walker::GitRevWalker; oid::GitHash=GitHash(), range::AbstractString="", by::Cint=Consts.SORT_NONE, rev::Bool=false)
Using the [`GitRevWalker`](@ref) `walker` to "walk" over every commit in the repository's history,
apply `f` to each commit in the walk. The keyword arguments are:
* `oid`: The [`GitHash`](@ref) of the commit to begin the walk from. The default is to use
[`push_head!`](@ref) and therefore the HEAD commit and all its ancestors.
* `range`: A range of `GitHash`s in the format `oid1..oid2`. `f` will be
applied to all commits between the two.
* `by`: The sorting method. The default is not to sort. Other options are to sort by
topology (`LibGit2.Consts.SORT_TOPOLOGICAL`), to sort forwards in time
(`LibGit2.Consts.SORT_TIME`, most ancient first) or to sort backwards in time
Expand Down
2 changes: 1 addition & 1 deletion doc/src/devdocs/libgit2.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Base.LibGit2.isorphan
Base.LibGit2.isset
Base.LibGit2.iszero
Base.LibGit2.lookup_branch
Base.LibGit2.map(::Function, ::Base.LibGit2.GitRevWalker; ::Base.LibGit2.GitHash, ::Cint, ::Bool)
Base.LibGit2.map(::Function, ::Base.LibGit2.GitRevWalker; ::Base.LibGit2.GitHash, ::AbstractString, ::Cint, ::Bool)
Base.LibGit2.mirror_callback
Base.LibGit2.mirror_cb
Base.LibGit2.message
Expand Down
13 changes: 13 additions & 0 deletions test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1258,10 +1258,18 @@ mktempdir() do dir
repo = LibGit2.GitRepo(test_repo)
cache = LibGit2.GitRepo(cache_repo)
try
# test map with oid
oids = LibGit2.with(LibGit2.GitRevWalker(repo)) do walker
LibGit2.map((oid,repo)->(oid,repo), walker, oid=commit_oid1, by=LibGit2.Consts.SORT_TIME)
end
@test length(oids) == 1
# test map with range
str_1 = string(commit_oid1)
str_3 = string(commit_oid3)
oids = LibGit2.with(LibGit2.GitRevWalker(repo)) do walker
LibGit2.map((oid,repo)->(oid,repo), walker, range="$str_1..$str_3", by=LibGit2.Consts.SORT_TIME)
end
@test length(oids) == 1

test_oids = LibGit2.with(LibGit2.GitRevWalker(repo)) do walker
LibGit2.map((oid,repo)->string(oid), walker, by = LibGit2.Consts.SORT_TIME)
Expand All @@ -1272,9 +1280,14 @@ mktempdir() do dir
for i in eachindex(oids)
@test cache_oids[i] == test_oids[i]
end
# test with specified oid
LibGit2.with(LibGit2.GitRevWalker(repo)) do walker
@test count((oid,repo)->(oid == commit_oid1), walker, oid=commit_oid1, by=LibGit2.Consts.SORT_TIME) == 1
end
# test without specified oid
LibGit2.with(LibGit2.GitRevWalker(repo)) do walker
@test count((oid,repo)->(oid == commit_oid1), walker, by=LibGit2.Consts.SORT_TIME) == 1
end
finally
close(repo)
close(cache)
Expand Down

0 comments on commit c172e92

Please sign in to comment.