@@ -480,30 +480,31 @@ Base.isempty(obj::AbstractGitObject) = (obj.ptr == C_NULL)
480
480
481
481
abstract type GitObject <: AbstractGitObject end
482
482
483
- for (typ, reporef, sup, cname) in [
484
- (:GitRepo , nothing , :AbstractGitObject , :git_repository ),
485
- (:GitTreeEntry , nothing , :AbstractGitObject , :git_tree_entry ),
486
- (:GitDiffStats , nothing , :AbstractGitObject , :git_diff_stats ),
487
- (:GitConfig , :Nullable , :AbstractGitObject , :git_config ),
488
- (:GitIndex , :Nullable , :AbstractGitObject , :git_index ),
489
- (:GitRemote , :GitRepo , :AbstractGitObject , :git_remote ),
490
- (:GitRevWalker , :GitRepo , :AbstractGitObject , :git_revwalk ),
491
- (:GitReference , :GitRepo , :AbstractGitObject , :git_reference ),
492
- (:GitDiff , :GitRepo , :AbstractGitObject , :git_diff ),
493
- (:GitAnnotated , :GitRepo , :AbstractGitObject , :git_annotated_commit ),
494
- (:GitRebase , :GitRepo , :AbstractGitObject , :git_rebase ),
495
- (:GitStatus , :GitRepo , :AbstractGitObject , :git_status_list ),
496
- (:GitBranchIter , :GitRepo , :AbstractGitObject , :git_branch_iterator ),
497
- (:GitUnknownObject , :GitRepo , :GitObject , :git_object ),
498
- (:GitCommit , :GitRepo , :GitObject , :git_commit ),
499
- (:GitBlob , :GitRepo , :GitObject , :git_blob ),
500
- (:GitTree , :GitRepo , :GitObject , :git_tree ),
501
- (:GitTag , :GitRepo , :GitObject , :git_tag )]
502
-
503
- if reporef === nothing
483
+ for (typ, owntyp, sup, cname) in [
484
+ (:GitRepo , nothing , :AbstractGitObject , :git_repository ),
485
+ (:GitDiffStats , nothing , :AbstractGitObject , :git_diff_stats ),
486
+ (:GitConfig , :(Nullable{GitRepo}), :AbstractGitObject , :git_config ),
487
+ (:GitIndex , :(Nullable{GitRepo}), :AbstractGitObject , :git_index ),
488
+ (:GitRemote , :GitRepo , :AbstractGitObject , :git_remote ),
489
+ (:GitRevWalker , :GitRepo , :AbstractGitObject , :git_revwalk ),
490
+ (:GitReference , :GitRepo , :AbstractGitObject , :git_reference ),
491
+ (:GitDiff , :GitRepo , :AbstractGitObject , :git_diff ),
492
+ (:GitAnnotated , :GitRepo , :AbstractGitObject , :git_annotated_commit ),
493
+ (:GitRebase , :GitRepo , :AbstractGitObject , :git_rebase ),
494
+ (:GitStatus , :GitRepo , :AbstractGitObject , :git_status_list ),
495
+ (:GitBranchIter , :GitRepo , :AbstractGitObject , :git_branch_iterator ),
496
+ (:GitUnknownObject , :GitRepo , :GitObject , :git_object ),
497
+ (:GitCommit , :GitRepo , :GitObject , :git_commit ),
498
+ (:GitBlob , :GitRepo , :GitObject , :git_blob ),
499
+ (:GitTree , :GitRepo , :GitObject , :git_tree ),
500
+ (:GitTag , :GitRepo , :GitObject , :git_tag ),
501
+ (:GitTreeEntry , :GitTree , :AbstractGitObject , :git_tree_entry ),
502
+ ]
503
+
504
+ if owntyp === nothing
504
505
@eval mutable struct $ typ <: $sup
505
506
ptr:: Ptr{Void}
506
- function $typ (ptr:: Ptr{Void} ,fin= true )
507
+ function $typ (ptr:: Ptr{Void} , fin:: Bool = true )
507
508
# fin=false should only be used when the pointer should not be free'd
508
509
# e.g. from within callback functions which are passed a pointer
509
510
@assert ptr != C_NULL
@@ -515,35 +516,25 @@ for (typ, reporef, sup, cname) in [
515
516
return obj
516
517
end
517
518
end
518
- elseif reporef == :Nullable
519
+ else
519
520
@eval mutable struct $ typ <: $sup
520
- nrepo :: Nullable{GitRepo}
521
+ owner :: $owntyp
521
522
ptr:: Ptr{Void}
522
- function $typ (repo:: GitRepo , ptr:: Ptr{Void} )
523
- @assert ptr != C_NULL
524
- obj = new (Nullable (repo), ptr)
525
- Threads. atomic_add! (REFCOUNT, UInt (1 ))
526
- finalizer (obj, Base. close)
527
- return obj
528
- end
529
- function $typ (ptr:: Ptr{Void} )
523
+ function $typ (owner:: $owntyp , ptr:: Ptr{Void} , fin:: Bool = true )
530
524
@assert ptr != C_NULL
531
- obj = new (Nullable {GitRepo} (), ptr)
532
- Threads. atomic_add! (REFCOUNT, UInt (1 ))
533
- finalizer (obj, Base. close)
525
+ obj = new (owner, ptr)
526
+ if fin
527
+ Threads. atomic_add! (REFCOUNT, UInt (1 ))
528
+ finalizer (obj, Base. close)
529
+ end
534
530
return obj
535
531
end
536
532
end
537
- elseif reporef == :GitRepo
538
- @eval mutable struct $ typ <: $sup
539
- repo:: GitRepo
540
- ptr:: Ptr{Void}
541
- function $typ (repo:: GitRepo , ptr:: Ptr{Void} )
542
- @assert ptr != C_NULL
543
- obj = new (repo, ptr)
544
- Threads. atomic_add! (REFCOUNT, UInt (1 ))
545
- finalizer (obj, Base. close)
546
- return obj
533
+ if isa (owntyp, Expr) && owntyp. args[1 ] == :Nullable
534
+ @eval begin
535
+ $ typ (ptr:: Ptr{Void} , fin:: Bool = true ) = $ typ ($ owntyp (), ptr, fin)
536
+ $ typ (owner:: $ (owntyp. args[2 ]), ptr:: Ptr{Void} , fin:: Bool = true ) =
537
+ $ typ ($ owntyp (owner), ptr, fin)
547
538
end
548
539
end
549
540
end
0 commit comments