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]>
91 lines
2.7 KiB
Go
91 lines
2.7 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package git
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/hanzoai/git/modules/git/gitcmd"
|
|
"github.com/hanzoai/git/modules/setting"
|
|
"github.com/hanzoai/git/modules/util"
|
|
)
|
|
|
|
// catFileBatchLegacy implements the CatFileBatch interface using the "cat-file --batch" command and "cat-file --batch-check" command
|
|
// for git version < 2.36
|
|
// to align with "--batch-command", it creates the two commands for querying object contents and object info separately
|
|
// ref: https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt---batch
|
|
type catFileBatchLegacy struct {
|
|
ctx context.Context
|
|
repoPath string
|
|
batchContent *catFileBatchCommunicator
|
|
batchCheck *catFileBatchCommunicator
|
|
}
|
|
|
|
var _ CatFileBatchCloser = (*catFileBatchLegacy)(nil)
|
|
|
|
func newCatFileBatchLegacy(ctx context.Context, repoPath string) (*catFileBatchLegacy, error) {
|
|
if _, err := os.Stat(repoPath); err != nil {
|
|
return nil, util.NewNotExistErrorf("repo %q doesn't exist", filepath.Base(repoPath))
|
|
}
|
|
return &catFileBatchLegacy{ctx: ctx, repoPath: repoPath}, nil
|
|
}
|
|
|
|
func (b *catFileBatchLegacy) getBatchContent() *catFileBatchCommunicator {
|
|
if b.batchContent != nil {
|
|
return b.batchContent
|
|
}
|
|
b.batchContent = newCatFileBatch(b.ctx, b.repoPath, gitcmd.NewCommand("cat-file", "--batch"))
|
|
return b.batchContent
|
|
}
|
|
|
|
func (b *catFileBatchLegacy) getBatchCheck() *catFileBatchCommunicator {
|
|
if b.batchCheck != nil {
|
|
return b.batchCheck
|
|
}
|
|
b.batchCheck = newCatFileBatch(b.ctx, b.repoPath, gitcmd.NewCommand("cat-file", "--batch-check"))
|
|
return b.batchCheck
|
|
}
|
|
|
|
func (b *catFileBatchLegacy) QueryContent(obj string) (*CatFileObject, BufferedReader, error) {
|
|
if strings.Contains(obj, "\n") {
|
|
setting.PanicInDevOrTesting("invalid object name with newline: %q", obj)
|
|
}
|
|
_, err := io.WriteString(b.getBatchContent().reqWriter, obj+"\n")
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
info, err := catFileBatchParseInfoLine(b.getBatchContent().respReader)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
return info, b.getBatchContent().respReader, nil
|
|
}
|
|
|
|
func (b *catFileBatchLegacy) QueryInfo(obj string) (*CatFileObject, error) {
|
|
if strings.Contains(obj, "\n") {
|
|
setting.PanicInDevOrTesting("invalid object name with newline: %q", obj)
|
|
}
|
|
_, err := io.WriteString(b.getBatchCheck().reqWriter, obj+"\n")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return catFileBatchParseInfoLine(b.getBatchCheck().respReader)
|
|
}
|
|
|
|
func (b *catFileBatchLegacy) Close() {
|
|
if b.batchContent != nil {
|
|
b.batchContent.Close()
|
|
b.batchContent = nil
|
|
}
|
|
if b.batchCheck != nil {
|
|
b.batchCheck.Close()
|
|
b.batchCheck = nil
|
|
}
|
|
}
|