mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
57 lines
1.9 KiB
Go
57 lines
1.9 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repository
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hanzoai/git/modules/util"
|
|
git_ctx "github.com/hanzoai/git/services/context"
|
|
)
|
|
|
|
type ContainedLinks struct { // TODO: better name?
|
|
Branches []*namedLink `json:"branches"`
|
|
Tags []*namedLink `json:"tags"`
|
|
DefaultBranch string `json:"default_branch"`
|
|
}
|
|
|
|
type namedLink struct { // TODO: better name?
|
|
Name string `json:"name"`
|
|
WebLink string `json:"web_link"`
|
|
}
|
|
|
|
// LoadBranchesAndTags creates a new repository branch
|
|
func LoadBranchesAndTags(ctx context.Context, baseRepo *git_ctx.Repository, commitSHA string) (*ContainedLinks, error) {
|
|
containedTags, err := baseRepo.GitRepo.ListOccurrences(ctx, "tag", commitSHA)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("encountered a problem while querying %s: %w", "tags", err)
|
|
}
|
|
containedBranches, err := baseRepo.GitRepo.ListOccurrences(ctx, "branch", commitSHA)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("encountered a problem while querying %s: %w", "branches", err)
|
|
}
|
|
|
|
result := &ContainedLinks{
|
|
DefaultBranch: baseRepo.Repository.DefaultBranch,
|
|
Branches: make([]*namedLink, 0, len(containedBranches)),
|
|
Tags: make([]*namedLink, 0, len(containedTags)),
|
|
}
|
|
for _, tag := range containedTags {
|
|
// TODO: Use a common method to get the link to a branch/tag instead of hard-coding it here
|
|
result.Tags = append(result.Tags, &namedLink{
|
|
Name: tag,
|
|
WebLink: fmt.Sprintf("%s/src/tag/%s", baseRepo.RepoLink, util.PathEscapeSegments(tag)),
|
|
})
|
|
}
|
|
for _, branch := range containedBranches {
|
|
result.Branches = append(result.Branches, &namedLink{
|
|
Name: branch,
|
|
WebLink: fmt.Sprintf("%s/src/branch/%s", baseRepo.RepoLink, util.PathEscapeSegments(branch)),
|
|
})
|
|
}
|
|
return result, nil
|
|
}
|