diff --git a/base/libgit2/types.jl b/base/libgit2/types.jl index f74a1499d1008..d713b6f94a772 100644 --- a/base/libgit2/types.jl +++ b/base/libgit2/types.jl @@ -956,8 +956,12 @@ The fields represent: boundary::Char end +""" + with(f::Function, obj) -""" Resource management helper function +Resource management helper function. Applies `f` to `obj`, making sure to call +`close` on `obj` after `f` successfully returns or throws an error. Ensures that +allocated git resources are finalized as soon as they are no longer needed. """ function with(f::Function, obj) try @@ -969,6 +973,15 @@ end with(f::Function, ::Type{T}, args...) where {T} = with(f, T(args...)) +""" + with_warn(f::Function, ::Type{T}, args...) + +Resource management helper function. Apply `f` to `args`, first constructing +an instance of type `T` from `args`. Makes sure to call `close` on the resulting +object after `f` successfully returns or throws an error. Ensures that +allocated git resources are finalized as soon as they are no longer needed. If an +error is thrown by `f`, a warning is shown containing the error. +""" function with_warn(f::Function, ::Type{T}, args...) where T obj = T(args...) try diff --git a/doc/src/devdocs/libgit2.md b/doc/src/devdocs/libgit2.md index 13709659c3c1f..cc5eca7d9b540 100644 --- a/doc/src/devdocs/libgit2.md +++ b/doc/src/devdocs/libgit2.md @@ -145,5 +145,6 @@ Base.LibGit2.update! Base.LibGit2.url Base.LibGit2.version Base.LibGit2.with +Base.LibGit2.with_warn Base.LibGit2.workdir ```