gout

A static git page generator
git clone https://git.bracken.jp/gout.git
Log | Files | Refs | README | LICENSE

commit a5aa70a985c9856e7be9cd0efa2acf4ab66ad5b9
parent 493193d1c0a72a8d91b9c3cfcca7059bff36a25f
Author: Chris Bracken <chris@bracken.jp>
Date:   Tue, 17 Feb 2026 18:31:34 +0900

reference: make shorthand an owned copy

Diffstat:
Msrc/git/reference.c | 23+++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/src/git/reference.c b/src/git/reference.c @@ -14,10 +14,8 @@ struct GitReference { RefType type; - const char* shorthand; + char* shorthand; GitCommit* commit; - - git_reference* ref; }; GitReference* gitreference_create(git_repository* repo, @@ -34,19 +32,19 @@ GitReference* gitreference_create(git_repository* repo, if (!git_reference_target(git_ref)) { errx(1, "git_reference_target"); } - ref->ref = git_ref; // Set type. - if (git_reference_is_branch(ref->ref)) { + if (git_reference_is_branch(git_ref)) { ref->type = kReftypeBranch; - } else if (git_reference_is_tag(ref->ref)) { + } else if (git_reference_is_tag(git_ref)) { ref->type = kReftypeTag; } else { errx(1, "not a branch or tag"); } // Set shorthand. - ref->shorthand = git_reference_shorthand(ref->ref); + const char* shorthand = git_reference_shorthand(git_ref); + ref->shorthand = shorthand ? estrdup(shorthand) : NULL; // Create a GitCommit from the object. git_object* obj = NULL; @@ -57,6 +55,8 @@ GitReference* gitreference_create(git_repository* repo, errx(1, "git_object_id"); } ref->commit = gitcommit_create(id, repo); + + git_reference_free(git_ref); return ref; } @@ -64,8 +64,8 @@ void gitreference_free(GitReference* ref) { if (!ref) { return; } - git_reference_free(ref->ref); - ref->ref = NULL; + free(ref->shorthand); + ref->shorthand = NULL; gitcommit_free(ref->commit); ref->commit = NULL; free(ref); @@ -86,7 +86,7 @@ GitCommit* gitreference_commit(const GitReference* r) { int gitreference_compare(const void* a, const void* b) { GitReference* r1 = *(GitReference**)a; GitReference* r2 = *(GitReference**)b; - int r = git_reference_is_tag(r1->ref) - git_reference_is_tag(r2->ref); + int r = (r1->type == kReftypeTag) - (r2->type == kReftypeTag); if (r != 0) { return r; } @@ -99,6 +99,5 @@ int gitreference_compare(const void* a, const void* b) { if (t1 < t2) { return 1; } - return strcmp(git_reference_shorthand(r1->ref), - git_reference_shorthand(r2->ref)); + return strcmp(r1->shorthand, r2->shorthand); }