commit 5461355bc99ff364affb0af6cf83e4e853e369cc
parent 0d029fbdf90feb11f139f84b86be63aee65e6805
Author: Leah (ctucx) <leah@ctu.cx>
Date: Tue, 16 Mar 2021 15:35:39 +0100
parent 0d029fbdf90feb11f139f84b86be63aee65e6805
Author: Leah (ctucx) <leah@ctu.cx>
Date: Tue, 16 Mar 2021 15:35:39 +0100
reference.nim: split resolveTarget into own proc
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/nimgit/reference.nim b/nimgit/reference.nim @@ -22,17 +22,22 @@ proc getRepo* (reference: GitReference): GitRepository = reference.getOwner() proc getType* (reference: GitReference): GitReferenceType = cast[GitReferenceType](git_reference_type(reference)) +proc resolveTarget(reference: GitReference): GitReference = + if reference.getType() != referenceSymbolic: + raise newException(ValueError, "Not a symbolic reference!") + + let error = git_reference_resolve(addr result, reference) + + if error != 0: + free(result) + raise newException(CatchableError, "Cannot lookup symbolic reference: " & $error.getResultCode) + proc getTarget* (reference: GitReference): GitObjectId = case reference.getType(): of referenceDirect: result = git_reference_target(reference) of referenceSymbolic: - var targetReference: GitReference - let error = git_reference_resolve(addr targetReference, reference) - - if error != 0: - raise newException(CatchableError, "Cannot lookup symbolic reference: " & $error.getResultCode) - + var targetReference = reference.resolveTarget() result = git_reference_target(targetReference) free(targetReference)