From c172e9271d57cf2641def7fc362af2f1e71b456d Mon Sep 17 00:00:00 2001 From: kshyatt Date: Wed, 13 Sep 2017 17:05:58 -0700 Subject: [PATCH] More tests for walker, fix docs --- base/libgit2/walker.jl | 4 +++- doc/src/devdocs/libgit2.md | 2 +- test/libgit2.jl | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/base/libgit2/walker.jl b/base/libgit2/walker.jl index ecac18dbeb7de..e1b15f68fd241 100644 --- a/base/libgit2/walker.jl +++ b/base/libgit2/walker.jl @@ -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 diff --git a/doc/src/devdocs/libgit2.md b/doc/src/devdocs/libgit2.md index b4e674d762c1f..df48c164c7c89 100644 --- a/doc/src/devdocs/libgit2.md +++ b/doc/src/devdocs/libgit2.md @@ -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 diff --git a/test/libgit2.jl b/test/libgit2.jl index 1005a489c6826..8ea3a15053e19 100644 --- a/test/libgit2.jl +++ b/test/libgit2.jl @@ -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) @@ -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)