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

JuliaLang / julia / #37433

pending completion
#37433

push

local

web-flow
Merge pull request #48513 from JuliaLang/jn/extend-once

ensure extension triggers are only run by the package that satified them

60 of 60 new or added lines in 1 file covered. (100.0%)

72324 of 82360 relevant lines covered (87.81%)

31376331.4 hits per line

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

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

3
repository(c::GitCommit) = c.owner
×
4

5
"""
6
    message(c::GitCommit, raw::Bool=false)
7

8
Return the commit message describing the changes made in commit `c`. If
9
`raw` is `false`, return a slightly "cleaned up" message (which has any
10
leading newlines removed). If `raw` is `true`, the message is not stripped
11
of any such newlines.
12
"""
13
function message(c::GitCommit, raw::Bool=false)
4✔
14
    ensure_initialized()
4✔
15
    GC.@preserve c begin
2✔
16
        local msg_ptr::Cstring
×
17
        msg_ptr = raw ? ccall((:git_commit_message_raw, :libgit2), Cstring, (Ptr{Cvoid},), c.ptr) :
4✔
18
                        ccall((:git_commit_message, :libgit2), Cstring, (Ptr{Cvoid},), c.ptr)
19
        if msg_ptr == C_NULL
2✔
20
            return nothing
×
21
        end
22
        msg_str = unsafe_string(msg_ptr)
2✔
23
    end
24
    return msg_str
2✔
25
end
26

27
"""
28
    author(c::GitCommit)
29

30
Return the `Signature` of the author of the commit `c`. The author is
31
the person who made changes to the relevant file(s). See also [`committer`](@ref).
32
"""
33
function author(c::GitCommit)
6✔
34
    ensure_initialized()
6✔
35
    GC.@preserve c begin
6✔
36
        ptr = ccall((:git_commit_author, :libgit2), Ptr{SignatureStruct}, (Ptr{Cvoid},), c.ptr)
6✔
37
        @assert ptr != C_NULL
6✔
38
        sig = Signature(ptr)
6✔
39
    end
40
    return sig
6✔
41
end
42

43
"""
44
    committer(c::GitCommit)
45

46
Return the `Signature` of the committer of the commit `c`. The committer is
47
the person who committed the changes originally authored by the [`author`](@ref), but
48
need not be the same as the `author`, for example, if the `author` emailed a patch to
49
a `committer` who committed it.
50
"""
51
function committer(c::GitCommit)
2✔
52
    ensure_initialized()
2✔
53
    GC.@preserve c begin
2✔
54
        ptr = ccall((:git_commit_committer, :libgit2), Ptr{SignatureStruct}, (Ptr{Cvoid},), c.ptr)
2✔
55
        sig = Signature(ptr)
2✔
56
    end
57
    return sig
2✔
58
end
59

60
function Base.show(io::IO, c::GitCommit)
1✔
61
    authstr = sprint(show, author(c))
1✔
62
    cmtrstr = sprint(show, committer(c))
1✔
63
    print(io, "Git Commit:\nCommit Author: $authstr\nCommitter: $cmtrstr\nSHA: $(GitHash(c))\nMessage:\n$(message(c))")
1✔
64
end
65

66
function commit(repo::GitRepo,
29✔
67
                refname::AbstractString,
68
                msg::AbstractString,
69
                author::GitSignature,
70
                committer::GitSignature,
71
                tree::GitTree,
72
                parents::GitCommit...)
73
    ensure_initialized()
29✔
74
    commit_id_ptr = Ref(GitHash())
29✔
75
    nparents = length(parents)
28✔
76
    parentptrs = Ptr{Cvoid}[c.ptr for c in parents]
28✔
77
    @check ccall((:git_commit_create, :libgit2), Cint,
58✔
78
                 (Ptr{GitHash}, Ptr{Cvoid}, Ptr{UInt8},
79
                  Ptr{SignatureStruct}, Ptr{SignatureStruct},
80
                  Ptr{UInt8}, Ptr{UInt8}, Ptr{Cvoid},
81
                  Csize_t, Ptr{Ptr{Cvoid}}),
82
                 commit_id_ptr, repo.ptr, isempty(refname) ? C_NULL : refname,
83
                 author.ptr, committer.ptr,
84
                 C_NULL, msg, tree.ptr,
85
                 nparents, nparents > 0 ? parentptrs : C_NULL)
86
    return commit_id_ptr[]
29✔
87
end
88

89
"""
90
    commit(repo::GitRepo, msg::AbstractString; kwargs...) -> GitHash
91

92
Wrapper around [`git_commit_create`](https://libgit2.org/libgit2/#HEAD/group/commit/git_commit_create).
93
Create a commit in the repository `repo`. `msg` is the commit message. Return the OID of the new commit.
94

95
The keyword arguments are:
96
  * `refname::AbstractString=Consts.HEAD_FILE`: if not NULL, the name of the reference to update to point to
97
    the new commit. For example, `"HEAD"` will update the HEAD of the current branch. If the reference does
98
    not yet exist, it will be created.
99
  * `author::Signature = Signature(repo)` is a `Signature` containing information about the person who authored the commit.
100
  * `committer::Signature = Signature(repo)` is a `Signature` containing information about the person who committed the commit to
101
    the repository. Not necessarily the same as `author`, for instance if `author` emailed a patch to
102
    `committer` who committed it.
103
  * `tree_id::GitHash = GitHash()` is a git tree to use to create the commit, showing its ancestry and relationship with
104
    any other history. `tree` must belong to `repo`.
105
  * `parent_ids::Vector{GitHash}=GitHash[]` is a list of commits by [`GitHash`](@ref) to use as parent
106
    commits for the new one, and may be empty. A commit might have multiple parents if it is a merge commit, for example.
107
"""
108
function commit(repo::GitRepo, msg::AbstractString;
58✔
109
                refname::AbstractString=Consts.HEAD_FILE,
110
                author::Signature = Signature(repo),
111
                committer::Signature = Signature(repo),
112
                tree_id::GitHash = GitHash(),
113
                parent_ids::Vector{GitHash}=GitHash[])
114
    # Retrieve tree identifier
115
    if iszero(tree_id)
609✔
116
        tree_id = with(GitIndex, repo) do idx; write_tree!(idx) end
58✔
117
    end
118

119
    # Retrieve parents from HEAD
120
    if isempty(parent_ids)
29✔
121
        try # if throws then HEAD not found -> empty repo
29✔
122
            Base.push!(parent_ids, GitHash(repo, refname))
30✔
123
        catch
124
        end
125
    end
126

127
    # return commit id
128
    commit_id  = GitHash()
29✔
129

130
    # get necessary objects
131
    tree = GitTree(repo, tree_id)
29✔
132
    auth_sig = convert(GitSignature, author)
29✔
133
    comm_sig = convert(GitSignature, committer)
29✔
134
    parents = GitCommit[]
29✔
135
    try
29✔
136
        for id in parent_ids
30✔
137
            Base.push!(parents, GitCommit(repo, id))
28✔
138
        end
56✔
139
        commit_id = commit(repo, refname, msg, auth_sig, comm_sig, tree, parents...)
29✔
140
    finally
141
        for parent in parents
30✔
142
            close(parent)
56✔
143
        end
56✔
144
        close(tree)
58✔
145
        close(auth_sig)
29✔
146
        close(comm_sig)
29✔
147
    end
148
    return commit_id
29✔
149
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