• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / #37514

pending completion
#37514

push

local

web-flow
annotate the signature type of the first argument of `kwcall` method (#49439)

This commit annotates the signature type of the first argument of
`kwcall` method as `kwargs::NamedTuple`.
Previously it's annotated as `::Any` but only `NamedTuple` object is
supported (and synthesized by the frontend) as the first argument to
`kwcall` method.

7 of 7 new or added lines in 5 files covered. (100.0%)

70339 of 83008 relevant lines covered (84.74%)

32590523.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/stdlib/LibGit2/src/blob.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
function Base.length(blob::GitBlob)
×
4
    ensure_initialized()
×
5
    return ccall((:git_blob_rawsize, :libgit2), Int64, (Ptr{Cvoid},), blob.ptr)
×
6
end
7

8
"""
9
    rawcontent(blob::GitBlob) -> Vector{UInt8}
10

11
Fetch the *raw* contents of the [`GitBlob`](@ref) `blob`. This is an
12
`Array` containing the contents of the blob, which may be binary or may be Unicode.
13
If you write to this `Array` the blob on disk will not be updated.
14
`rawcontent` will allow the user to load the raw binary data into
15
the output `Array` and will not check to ensure it is valid Unicode, so errors
16
may occur if the result is passed to functions which expect valid Unicode data.
17

18
See also [`content`](@ref), which *will* throw an error if the content of the `blob`
19
is binary and not valid Unicode.
20
"""
21
function rawcontent(blob::GitBlob)
×
22
    ensure_initialized()
×
23
    ptr = ccall((:git_blob_rawcontent, :libgit2), Ptr{UInt8}, (Ptr{Cvoid},), blob.ptr)
×
24
    copy(unsafe_wrap(Array, ptr, (length(blob),), own = false))
×
25
end
26

27
"""
28
    content(blob::GitBlob) -> String
29

30
Fetch the contents of the [`GitBlob`](@ref) `blob`. If the `blob` contains
31
binary data (which can be determined using [`isbinary`](@ref)),
32
throw an error. Otherwise, return a `String` containing the contents
33
of the `blob`.
34
"""
35
function content(blob::GitBlob)
×
36
    s = String(rawcontent(blob))
×
37
    isvalid(s) || error("Blob does not contain valid UTF-8 data")
×
38
    return s
×
39
end
40

41
"""
42
    isbinary(blob::GitBlob) -> Bool
43

44
Use a heuristic to guess if a file is binary: searching for NULL bytes and
45
looking for a reasonable ratio of printable to non-printable characters among
46
the first 8000 bytes.
47
"""
48
function isbinary(blob::GitBlob)
×
49
    ensure_initialized()
×
50
    bin_flag = ccall((:git_blob_is_binary, :libgit2), Cint, (Ptr{Cvoid},), blob.ptr)
×
51
    return bin_flag == 1
×
52
end
53

54
"""
55
    LibGit2.addblob!(repo::GitRepo, path::AbstractString)
56

57
Read the file at `path` and adds it to the object database of `repo` as a loose blob.
58
Return the [`GitHash`](@ref) of the resulting blob.
59

60
# Examples
61
```julia
62
hash_str = string(commit_oid)
63
blob_file = joinpath(repo_path, ".git", "objects", hash_str[1:2], hash_str[3:end])
64
id = LibGit2.addblob!(repo, blob_file)
65
```
66
"""
67
function addblob!(repo::GitRepo, path::AbstractString)
×
68
    ensure_initialized()
×
69
    id_ref = Ref{GitHash}()
×
70
    @check ccall((:git_blob_create_from_disk, :libgit2), Cint,
×
71
                 (Ptr{GitHash}, Ptr{Cvoid}, Cstring),
72
                 id_ref, repo.ptr, path)
73
    return id_ref[]
×
74
end
75

76
function Base.show(io::IO, blob::GitBlob)
×
77
    if !isbinary(blob)
×
78
        conts   = split(content(blob), "\n")
×
79
        showlen = max(length(conts), 3)
×
80
        println(io, "GitBlob:\nBlob id: ", GitHash(blob), "\nContents:")
×
81
        for i in 1:showlen
×
82
            println(io, conts[i])
×
83
        end
×
84
    else
85
        println(io, "GitBlob:\nBlob id: ", GitHash(blob), "\nContents are binary.")
×
86
    end
87
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc