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

JuliaLang / julia / #37535

pending completion
#37535

push

local

web-flow
irinterp: Fix accidentally introduced deletion of effectful statement (#49750)

I moved around some code in #49692 that broadened the replacement of
statements by their const results. This is fine for how we're currently
using irinterp in base, because we're requiring some fairly strong
effects, but some downstream pipelines (and potentially Base in the future)
want to use irinterp on code with arbitrary effects, so put in an
appropriate check.

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

71489 of 83224 relevant lines covered (85.9%)

32529585.83 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)
×
5
    str_ref = Base.cconvert(Ref{Cstring}, [pathspecs])
×
6
    sa = StrArrayStruct(Base.unsafe_convert(Ref{Cstring}, str_ref), 1)
×
7
    do_ref = Ref(DiffOptionsStruct(pathspec = sa))
×
8
    do_ref, str_ref
×
9
end
10
function Base.unsafe_convert(::Type{Ptr{DiffOptionsStruct}}, rr::Tuple{Ref{DiffOptionsStruct}, Ref{Cstring}})
×
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
"""
26
function diff_tree(repo::GitRepo, tree::GitTree, pathspecs::AbstractString=""; cached::Bool=false)
×
27
    ensure_initialized()
×
28
    diff_ptr_ptr = Ref{Ptr{Cvoid}}(C_NULL)
×
29
    if cached
×
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.ptr, tree.ptr, C_NULL, isempty(pathspecs) ? C_NULL : pathspecs)
33
    else
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.ptr, tree.ptr, isempty(pathspecs) ? C_NULL : pathspecs)
37
    end
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
"""
51
function diff_tree(repo::GitRepo, oldtree::GitTree, newtree::GitTree)
×
52
    ensure_initialized()
×
53
    diff_ptr_ptr = Ref{Ptr{Cvoid}}(C_NULL)
×
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.ptr, oldtree.ptr, newtree.ptr, C_NULL)
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
"""
67
function GitDiffStats(diff::GitDiff)
×
68
    ensure_initialized()
×
69
    diff_stat_ptr_ptr = Ref{Ptr{Cvoid}}(C_NULL)
×
70
    @check ccall((:git_diff_get_stats, :libgit2), Cint,
×
71
                  (Ptr{Ptr{Cvoid}}, Ptr{Cvoid}),
72
                  diff_stat_ptr_ptr, diff.ptr)
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
"""
84
function files_changed(diff_stat::GitDiffStats)
×
85
    ensure_initialized()
×
86
    return ccall((:git_diff_stats_files_changed, :libgit2), Csize_t, (Ptr{Cvoid},), diff_stat.ptr)
×
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
"""
97
function insertions(diff_stat::GitDiffStats)
×
98
    ensure_initialized()
×
99
    return ccall((:git_diff_stats_insertions, :libgit2), Csize_t, (Ptr{Cvoid},), diff_stat.ptr)
×
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
"""
110
function deletions(diff_stat::GitDiffStats)
×
111
    ensure_initialized()
×
112
    return ccall((:git_diff_stats_deletions, :libgit2), Csize_t, (Ptr{Cvoid},), diff_stat.ptr)
×
113
end
114

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

120
function Base.getindex(diff::GitDiff, i::Integer)
×
121
    if i < 1 || i > count(diff)
×
122
        throw(BoundsError(diff, (i,)))
×
123
    end
124
    ensure_initialized()
×
125
    delta_ptr = ccall((:git_diff_get_delta, :libgit2),
×
126
                      Ptr{DiffDelta},
127
                      (Ptr{Cvoid}, Csize_t), diff.ptr, i-1)
128
    return unsafe_load(delta_ptr)
×
129
end
130

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

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