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]>
54 lines
2.0 KiB
Go
54 lines
2.0 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package git
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
)
|
|
|
|
type BufferedReader interface {
|
|
io.Reader
|
|
Buffered() int
|
|
Peek(n int) ([]byte, error)
|
|
Discard(n int) (int, error)
|
|
ReadString(sep byte) (string, error)
|
|
ReadSlice(sep byte) ([]byte, error)
|
|
ReadBytes(sep byte) ([]byte, error)
|
|
}
|
|
|
|
type CatFileObject struct {
|
|
ID string
|
|
Type string
|
|
Size int64
|
|
}
|
|
|
|
type CatFileBatch interface {
|
|
// QueryInfo queries the object info from the git repository by its object name using "git cat-file --batch" family commands.
|
|
// "git cat-file" accepts "<rev>" for the object name, it can be a ref name, object id, etc. https://git-scm.com/docs/gitrevisions
|
|
// In Gitea, we only use the simple ref name or object id, no other complex rev syntax like "suffix" or "git describe" although they are supported by git.
|
|
QueryInfo(obj string) (*CatFileObject, error)
|
|
|
|
// QueryContent is similar to QueryInfo, it queries the object info and additionally returns a reader for its content.
|
|
// FIXME: this design still follows the old pattern: the returned BufferedReader is very fragile,
|
|
// callers should carefully maintain its lifecycle and discard all unread data.
|
|
// TODO: It needs to be refactored to a fully managed Reader stream in the future, don't let callers manually Close or Discard
|
|
QueryContent(obj string) (*CatFileObject, BufferedReader, error)
|
|
}
|
|
|
|
type CatFileBatchCloser interface {
|
|
CatFileBatch
|
|
Close()
|
|
}
|
|
|
|
// NewBatch creates a "batch object provider (CatFileBatch)" for the given repository path to retrieve object info and content efficiently.
|
|
// The CatFileBatch and the readers create by it should only be used in the same goroutine.
|
|
func NewBatch(ctx context.Context, repoPath string) (CatFileBatchCloser, error) {
|
|
if DefaultFeatures().SupportCatFileBatchCommand {
|
|
return newCatFileBatchCommand(ctx, repoPath)
|
|
}
|
|
return newCatFileBatchLegacy(ctx, repoPath)
|
|
}
|