-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add GitShortHash type, remove some get methods #20104
Merged
+287
−250
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fc6b868
add GitShortHash type, remove some get methods
simonbyrne ec8e2f6
changes suggested by @kshyatt
simonbyrne 2587850
clarify doc
simonbyrne 8a02da9
Merge branch 'master' into sb/gitshorthash
ararslan dcde790
use quote instead of begin block, qualify macro
simonbyrne 0b1ad7f
Merge branch 'master' into sb/gitshorthash
simonbyrne d5bbd02
improve docs
simonbyrne 2a2e936
newline
simonbyrne 3c19117
Merge branch 'master' into sb/gitshorthash
simonbyrne 50261a3
add test for valid blob data
simonbyrne d9d15a8
fix function call
simonbyrne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ end | |
function iscommit(id::AbstractString, repo::GitRepo) | ||
res = true | ||
try | ||
c = get(GitCommit, repo, id) | ||
c = GitCommit(repo, id) | ||
if c === nothing | ||
res = false | ||
else | ||
|
@@ -94,9 +94,8 @@ See `git diff-index <treeish> [-- <path>]` | |
""" | ||
function isdiff(repo::GitRepo, treeish::AbstractString, paths::AbstractString=""; cached::Bool=false) | ||
tree_oid = revparseid(repo, "$treeish^{tree}") | ||
iszero(tree_oid) && error("invalid treeish $treeish") # this can be removed by #20104 | ||
result = false | ||
tree = get(GitTree, repo, tree_oid) | ||
tree = GitTree(repo, tree_oid) | ||
try | ||
diff = diff_tree(repo, tree, paths, cached=cached) | ||
result = count(diff) > 0 | ||
|
@@ -112,8 +111,8 @@ function diff_files(repo::GitRepo, branch1::AbstractString, branch2::AbstractStr | |
filter::Set{Cint}=Set([Consts.DELTA_ADDED, Consts.DELTA_MODIFIED, Consts.DELTA_DELETED])) | ||
b1_id = revparseid(repo, branch1*"^{tree}") | ||
b2_id = revparseid(repo, branch2*"^{tree}") | ||
tree1 = get(GitTree, repo, b1_id) | ||
tree2 = get(GitTree, repo, b2_id) | ||
tree1 = GitTree(repo, b1_id) | ||
tree2 = GitTree(repo, b2_id) | ||
files = AbstractString[] | ||
try | ||
diff = diff_tree(repo, tree1, tree2) | ||
|
@@ -241,7 +240,7 @@ function branch!(repo::GitRepo, branch_name::AbstractString, | |
GitHash(commit) | ||
end | ||
iszero(commit_id) && return | ||
cmt = get(GitCommit, repo, commit_id) | ||
cmt = GitCommit(repo, commit_id) | ||
new_branch_ref = nothing | ||
try | ||
new_branch_ref = create_branch(repo, branch_name, cmt, force=force) | ||
|
@@ -298,28 +297,17 @@ function checkout!(repo::GitRepo, commit::AbstractString = ""; | |
end | ||
|
||
# search for commit to get a commit object | ||
obj = get(GitUnknownObject, repo, GitHash(commit)) | ||
obj === nothing && return | ||
try | ||
peeled = peel(obj, Consts.OBJ_COMMIT) | ||
peeled === nothing && return | ||
opts = force ? CheckoutOptions(checkout_strategy = Consts.CHECKOUT_FORCE) : | ||
CheckoutOptions() | ||
try | ||
# detach commit | ||
obj_oid = GitHash(peeled) | ||
ref = GitReference(repo, obj_oid, force=force, | ||
msg="libgit2.checkout: moving from $head_name to $(string(obj_oid))") | ||
close(ref) | ||
|
||
# checkout commit | ||
checkout_tree(repo, peeled, options = opts) | ||
finally | ||
close(peeled) | ||
end | ||
finally | ||
close(obj) | ||
end | ||
obj = GitObject(repo, GitHash(commit)) | ||
peeled = peel(GitCommit, obj) | ||
|
||
opts = force ? CheckoutOptions(checkout_strategy = Consts.CHECKOUT_FORCE) : CheckoutOptions() | ||
# detach commit | ||
obj_oid = GitHash(peeled) | ||
ref = GitReference(repo, obj_oid, force=force, | ||
msg="libgit2.checkout: moving from $head_name to $(string(obj_oid))") | ||
|
||
# checkout commit | ||
checkout_tree(repo, peeled, options = opts) | ||
end | ||
|
||
""" git clone [-b <branch>] [--bare] <url> <dir> """ | ||
|
@@ -343,42 +331,22 @@ end | |
|
||
""" git reset [<committish>] [--] <pathspecs>... """ | ||
function reset!(repo::GitRepo, committish::AbstractString, pathspecs::AbstractString...) | ||
obj = revparse(repo, !isempty(committish) ? committish : Consts.HEAD_FILE) | ||
obj = GitObject(repo, isempty(committish) ? Consts.HEAD_FILE : committish) | ||
# do not remove entries in the index matching the provided pathspecs with empty target commit tree | ||
obj === nothing && throw(GitError(Error.Object, Error.ERROR, "`$committish` not found")) | ||
try | ||
head = reset!(repo, Nullable(obj), pathspecs...) | ||
return head | ||
finally | ||
close(obj) | ||
end | ||
return head_oid(repo) | ||
reset!(repo, Nullable(obj), pathspecs...) | ||
end | ||
|
||
""" git reset [--soft | --mixed | --hard] <commit> """ | ||
function reset!(repo::GitRepo, commit::GitHash, mode::Cint = Consts.RESET_MIXED) | ||
obj = get(GitUnknownObject, repo, commit) | ||
# object must exist for reset | ||
obj === nothing && throw(GitError(Error.Object, Error.ERROR, "Commit `$(string(commit))` object not found")) | ||
try | ||
head = reset!(repo, obj, mode) | ||
return head | ||
finally | ||
close(obj) | ||
end | ||
return head_oid(repo) | ||
end | ||
""" git reset [--soft | --mixed | --hard] <id> """ | ||
reset!(repo::GitRepo, id::GitHash, mode::Cint = Consts.RESET_MIXED) = | ||
reset!(repo, GitObject(repo, id), mode) | ||
|
||
""" git cat-file <commit> """ | ||
function cat{T<:GitObject}(repo::GitRepo, ::Type{T}, object::AbstractString) | ||
obj_id = revparseid(repo, object) | ||
iszero(obj_id) && return nothing | ||
|
||
obj = get(T, repo, obj_id) | ||
function cat(repo::GitRepo, spec) | ||
obj = GitObject(repo, spec) | ||
if isa(obj, GitBlob) | ||
return unsafe_string(convert(Ptr{UInt8}, content(obj))) | ||
content(obj) | ||
else | ||
return nothing | ||
nothing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does this correspond to? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the resulting object is a commit, tag or tree. Arguably this is another function that could be removed altogether. |
||
end | ||
end | ||
|
||
|
@@ -442,10 +410,10 @@ function merge!(repo::GitRepo; | |
remotename = with(GitConfig, repo) do cfg | ||
LibGit2.get(String, cfg, "branch.$branchname.remote") | ||
end | ||
obj = with(GitReference(repo, "refs/remotes/$remotename/$branchname")) do ref | ||
oid = with(GitReference(repo, "refs/remotes/$remotename/$branchname")) do ref | ||
LibGit2.GitHash(ref) | ||
end | ||
with(get(GitCommit, repo, obj)) do cmt | ||
with(GitCommit(repo, oid)) do cmt | ||
LibGit2.create_branch(repo, branchname, cmt) | ||
end | ||
return true | ||
|
@@ -543,7 +511,7 @@ end | |
""" Returns all commit authors """ | ||
function authors(repo::GitRepo) | ||
return with(GitRevWalker(repo)) do walker | ||
map((oid,repo)->with(get(GitCommit, repo, oid)) do cmt | ||
map((oid,repo)->with(GitCommit(repo, oid)) do cmt | ||
author(cmt)::Signature | ||
end, | ||
walker) #, by = Consts.SORT_TIME) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is binary content, it could easily have embedded nuls or be invalid utf-8, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. We can deal with the NUL issue by calling it with a length argument (which I presume is
git_blob_rawsize
). But I don't know how we could deal with non-UTF8 data.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have it return an array of bytes?