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

JuliaLang / julia / #37997

29 Jan 2025 02:08AM UTC coverage: 17.283% (-68.7%) from 85.981%
#37997

push

local

web-flow
bpart: Start enforcing min_world for global variable definitions (#57150)

This is the analog of #57102 for global variables. Unlike for consants,
there is no automatic global backdate mechanism. The reasoning for this
is that global variables can be declared at any time, unlike constants
which can only be decalared once their value is available. As a result
code patterns using `Core.eval` to declare globals are rarer and likely
incorrect.

1 of 22 new or added lines in 3 files covered. (4.55%)

31430 existing lines in 188 files now uncovered.

7903 of 45728 relevant lines covered (17.28%)

98663.7 hits per line

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

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

3
# TODO: make this a general purpose solution
4
function Base.cconvert(::Type{Ptr{DiffOptionsStruct}}, pathspecs::AbstractString)
UNCOV
5
    str_ref = Base.cconvert(Ref{Cstring}, [pathspecs])
×
UNCOV
6
    sa = StrArrayStruct(Base.unsafe_convert(Ref{Cstring}, str_ref), 1)
×
UNCOV
7
    do_ref = Ref(DiffOptionsStruct(pathspec = sa))
×
UNCOV
8
    do_ref, str_ref
×
9
end
10
function Base.unsafe_convert(::Type{Ptr{DiffOptionsStruct}}, rr::Tuple{Ref{DiffOptionsStruct}, Ref{Cstring}})
UNCOV
11
    Base.unsafe_convert(Ptr{DiffOptionsStruct}, first(rr))
×
12
end
13

14
"""
15
    diff_tree(repo::GitRepo, tree::GitTree, pathspecs::AbstractString=""; cached::Bool=false)
16

17
Generate a [`GitDiff`](@ref) between `tree` (which will be used for the "old"
18
side of the [`DiffDelta`](@ref)) and `repo` (which will be used for the "new" side).
19
If `repo` is `cached`, calls [`git_diff_tree_to_index`](https://libgit2.org/libgit2/#HEAD/group/diff/git_diff_tree_to_index).
20
The `cached` version is generally used to examine the diff for staged changes from one
21
commit to the next. If `cached` is `false`, calls
22
[`git_diff_tree_to_workdir_with_index`](https://libgit2.org/libgit2/#HEAD/group/diff/git_diff_tree_to_workdir_with_index).
23
This compares the current working directory against the [`GitIndex`](@ref) and can,
24
for example, be used to examine the changes in staged files before a commit.
25
"""
UNCOV
26
function diff_tree(repo::GitRepo, tree::GitTree, pathspecs::AbstractString=""; cached::Bool=false)
×
UNCOV
27
    ensure_initialized()
×
UNCOV
28
    diff_ptr_ptr = Ref{Ptr{Cvoid}}(C_NULL)
×
UNCOV
29
    if cached
×
UNCOV
30
        @check ccall((:git_diff_tree_to_index, libgit2), Cint,
×
31
                     (Ptr{Ptr{Cvoid}}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{DiffOptionsStruct}),
32
                     diff_ptr_ptr, repo, tree, C_NULL, isempty(pathspecs) ? C_NULL : pathspecs)
33
    else
UNCOV
34
        @check ccall((:git_diff_tree_to_workdir_with_index, libgit2), Cint,
×
35
                     (Ptr{Ptr{Cvoid}}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{DiffOptionsStruct}),
36
                     diff_ptr_ptr, repo, tree, isempty(pathspecs) ? C_NULL : pathspecs)
37
    end
UNCOV
38
    return GitDiff(repo, diff_ptr_ptr[])
×
39
end
40

41
"""
42
    diff_tree(repo::GitRepo, oldtree::GitTree, newtree::GitTree)
43

44
Generate a [`GitDiff`](@ref) between `oldtree` (which will be used for the "old"
45
side of the [`DiffDelta`](@ref)) and `newtree` (which will be used for the "new"
46
side of the `DiffDelta`). Equivalent to [`git_diff_tree_to_tree`](https://libgit2.org/libgit2/#HEAD/group/diff/git_diff_tree_to_tree).
47
This can be used to generate a diff between two commits. For instance, it could
48
be used to compare a commit made 2 months ago with the current latest commit, or
49
to compare a commit on another branch with the current latest commit on `master`.
50
"""
UNCOV
51
function diff_tree(repo::GitRepo, oldtree::GitTree, newtree::GitTree)
×
UNCOV
52
    ensure_initialized()
×
UNCOV
53
    diff_ptr_ptr = Ref{Ptr{Cvoid}}(C_NULL)
×
UNCOV
54
    @check ccall((:git_diff_tree_to_tree, libgit2), Cint,
×
55
                  (Ptr{Ptr{Cvoid}}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{DiffOptionsStruct}),
56
                   diff_ptr_ptr, repo, oldtree, newtree, C_NULL)
UNCOV
57
    return GitDiff(repo, diff_ptr_ptr[])
×
58
end
59

60
"""
61
    GitDiffStats(diff::GitDiff)
62

63
Get the diff statistics from the [`GitDiff`](@ref) `diff`. This object records a
64
summary of changes made across the `diff`. In particular, it records how many
65
files were changed, how many insertions were made, and how many deletions were made.
66
"""
UNCOV
67
function GitDiffStats(diff::GitDiff)
×
UNCOV
68
    ensure_initialized()
×
UNCOV
69
    diff_stat_ptr_ptr = Ref{Ptr{Cvoid}}(C_NULL)
×
UNCOV
70
    @check ccall((:git_diff_get_stats, libgit2), Cint,
×
71
                  (Ptr{Ptr{Cvoid}}, Ptr{Cvoid}),
72
                  diff_stat_ptr_ptr, diff)
UNCOV
73
    return GitDiffStats(diff.owner, diff_stat_ptr_ptr[])
×
74
end
75

76
"""
77
    files_changed(diff_stat::GitDiffStats) -> Csize_t
78

79
Return how many files were changed (added/modified/deleted) in the [`GitDiff`](@ref)
80
summarized by `diff_stat`. The result may vary depending on the [`DiffOptionsStruct`](@ref)
81
used to generate the parent `GitDiff` of `diff_stat` (for instance, whether ignored files
82
are to be included or not).
83
"""
UNCOV
84
function files_changed(diff_stat::GitDiffStats)
×
UNCOV
85
    ensure_initialized()
×
UNCOV
86
    return ccall((:git_diff_stats_files_changed, libgit2), Csize_t, (Ptr{Cvoid},), diff_stat)
×
87
end
88

89
"""
90
    insertions(diff_stat::GitDiffStats) -> Csize_t
91

92
Return the total number of insertions (lines added) in the [`GitDiff`](@ref)
93
summarized by `diff_stat`. The result may vary depending on the [`DiffOptionsStruct`](@ref)
94
used to generate the parent `GitDiff` of `diff_stat` (for instance, whether ignored files
95
are to be included or not).
96
"""
UNCOV
97
function insertions(diff_stat::GitDiffStats)
×
UNCOV
98
    ensure_initialized()
×
UNCOV
99
    return ccall((:git_diff_stats_insertions, libgit2), Csize_t, (Ptr{Cvoid},), diff_stat)
×
100
end
101

102
"""
103
    deletions(diff_stat::GitDiffStats) -> Csize_t
104

105
Return the total number of deletions (lines removed) in the [`GitDiff`](@ref)
106
summarized by `diff_stat`. The result may vary depending on the [`DiffOptionsStruct`](@ref)
107
used to generate the parent `GitDiff` of `diff_stat` (for instance, whether ignored files
108
are to be included or not).
109
"""
UNCOV
110
function deletions(diff_stat::GitDiffStats)
×
UNCOV
111
    ensure_initialized()
×
UNCOV
112
    return ccall((:git_diff_stats_deletions, libgit2), Csize_t, (Ptr{Cvoid},), diff_stat)
×
113
end
114

115
function count(diff::GitDiff)
UNCOV
116
    ensure_initialized()
×
UNCOV
117
    return ccall((:git_diff_num_deltas, libgit2), Cint, (Ptr{Cvoid},), diff)
×
118
end
119

UNCOV
120
function Base.getindex(diff::GitDiff, i::Integer)
×
UNCOV
121
    if i < 1 || i > count(diff)
×
UNCOV
122
        throw(BoundsError(diff, (i,)))
×
123
    end
UNCOV
124
    ensure_initialized()
×
UNCOV
125
    GC.@preserve diff begin # preserve `diff` object until return of `unsafe_load`
×
UNCOV
126
        delta_ptr = ccall((:git_diff_get_delta, libgit2),
×
127
                          Ptr{DiffDelta},
128
                          (Ptr{Cvoid}, Csize_t), diff, i-1)
UNCOV
129
        return unsafe_load(delta_ptr)
×
130
    end
131
end
132

UNCOV
133
function Base.show(io::IO, diff_stat::GitDiffStats)
×
UNCOV
134
    println(io, "GitDiffStats:")
×
UNCOV
135
    println(io, "Files changed: $(files_changed(diff_stat))")
×
UNCOV
136
    println(io, "Insertions: $(insertions(diff_stat))")
×
UNCOV
137
    println(io, "Deletions: $(deletions(diff_stat))")
×
138
end
139

UNCOV
140
function Base.show(io::IO, diff::GitDiff)
×
UNCOV
141
    println(io, "GitDiff:")
×
UNCOV
142
    println(io, "Number of deltas: $(count(diff))")
×
UNCOV
143
    show(io, GitDiffStats(diff))
×
144
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

© 2026 Coveralls, Inc