mirror of
https://gitcode.com/gitea/gitea.git
synced 2025-06-09 06:14:56 +08:00
.devcontainer
.gitea
.github
assets
build
cmd
contrib
custom
docker
docs
models
modules
actions
activitypub
analyze
assetfs
auth
avatar
badge
base
cache
charset
container
csv
emoji
eventsource
generate
git
foreachref
internal
pipeline
catfile.go
lfs.go
lfs_nogogit.go
namerev.go
revlist.go
tests
url
README.md
attribute.go
batch_reader.go
blame.go
blame_sha256_test.go
blame_test.go
blob.go
blob_gogit.go
blob_nogogit.go
blob_test.go
command.go
command_race_test.go
command_test.go
commit.go
commit_convert_gogit.go
commit_info.go
commit_info_gogit.go
commit_info_nogogit.go
commit_info_test.go
commit_reader.go
commit_sha256_test.go
commit_test.go
diff.go
diff_test.go
error.go
git.go
git_test.go
hook.go
last_commit_cache.go
last_commit_cache_gogit.go
last_commit_cache_nogogit.go
log_name_status.go
notes.go
notes_gogit.go
notes_nogogit.go
notes_test.go
object_format.go
object_id.go
object_id_gogit.go
object_id_test.go
parse_gogit.go
parse_gogit_test.go
parse_nogogit.go
parse_nogogit_test.go
ref.go
ref_test.go
remote.go
repo.go
repo_archive.go
repo_attribute.go
repo_attribute_test.go
repo_base.go
repo_base_gogit.go
repo_base_nogogit.go
repo_blame.go
repo_blob.go
repo_blob_gogit.go
repo_blob_nogogit.go
repo_blob_test.go
repo_branch.go
repo_branch_gogit.go
repo_branch_nogogit.go
repo_branch_test.go
repo_commit.go
repo_commit_gogit.go
repo_commit_nogogit.go
repo_commit_test.go
repo_commitgraph.go
repo_commitgraph_gogit.go
repo_compare.go
repo_compare_test.go
repo_gpg.go
repo_hook.go
repo_index.go
repo_language_stats.go
repo_language_stats_gogit.go
repo_language_stats_nogogit.go
repo_language_stats_test.go
repo_object.go
repo_ref.go
repo_ref_gogit.go
repo_ref_nogogit.go
repo_ref_test.go
repo_stats.go
repo_stats_test.go
repo_tag.go
repo_tag_gogit.go
repo_tag_nogogit.go
repo_tag_test.go
repo_test.go
repo_tree.go
repo_tree_gogit.go
repo_tree_nogogit.go
signature.go
signature_gogit.go
signature_nogogit.go
signature_test.go
submodule.go
submodule_test.go
tag.go
tag_test.go
tree.go
tree_blob.go
tree_blob_gogit.go
tree_blob_nogogit.go
tree_entry.go
tree_entry_gogit.go
tree_entry_mode.go
tree_entry_nogogit.go
tree_entry_test.go
tree_gogit.go
tree_nogogit.go
tree_test.go
utils.go
gitgraph
gitrepo
graceful
hcaptcha
highlight
hostmatcher
html
httpcache
httplib
indexer
issue
json
label
lfs
log
markup
mcaptcha
metrics
migration
nosql
optional
options
packages
paginator
pprof
private
process
proxy
proxyprotocol
public
queue
recaptcha
references
regexplru
repository
secret
session
setting
sitemap
ssh
storage
structs
svg
sync
system
templates
test
testlogger
timeutil
translation
turnstile
typesniffer
updatechecker
uri
user
util
validation
web
webhook
options
public
routers
services
snap
templates
tests
web_src
.air.toml
.changelog.yml
.dockerignore
.editorconfig
.eslintrc.yaml
.gitattributes
.gitignore
.gitpod.yml
.golangci.yml
.ignore
.markdownlint.yaml
.npmrc
.spectral.yaml
.stylelintrc.yaml
.yamllint.yaml
BSDmakefile
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
DCO
Dockerfile
Dockerfile.rootless
LICENSE
MAINTAINERS
Makefile
README.md
README_ZH.md
SECURITY.md
build.go
go.mod
go.sum
main.go
package-lock.json
package.json
playwright.config.js
poetry.lock
poetry.toml
pyproject.toml
tailwind.config.js
updates.config.js
vitest.config.js
webpack.config.js

Change all license headers to comply with REUSE specification. Fix #16132 Co-authored-by: flynnnnnnnnnn <flynnnnnnnnnn@github> Co-authored-by: John Olheiser <john.olheiser@gmail.com>
109 lines
3.3 KiB
Go
109 lines
3.3 KiB
Go
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package pipeline
|
|
|
|
import (
|
|
"bufio"
|
|
"bytes"
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"strconv"
|
|
"strings"
|
|
"sync"
|
|
|
|
"code.gitea.io/gitea/modules/git"
|
|
"code.gitea.io/gitea/modules/log"
|
|
)
|
|
|
|
// CatFileBatchCheck runs cat-file with --batch-check
|
|
func CatFileBatchCheck(ctx context.Context, shasToCheckReader *io.PipeReader, catFileCheckWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath string) {
|
|
defer wg.Done()
|
|
defer shasToCheckReader.Close()
|
|
defer catFileCheckWriter.Close()
|
|
|
|
stderr := new(bytes.Buffer)
|
|
var errbuf strings.Builder
|
|
cmd := git.NewCommand(ctx, "cat-file", "--batch-check")
|
|
if err := cmd.Run(&git.RunOpts{
|
|
Dir: tmpBasePath,
|
|
Stdin: shasToCheckReader,
|
|
Stdout: catFileCheckWriter,
|
|
Stderr: stderr,
|
|
}); err != nil {
|
|
_ = catFileCheckWriter.CloseWithError(fmt.Errorf("git cat-file --batch-check [%s]: %w - %s", tmpBasePath, err, errbuf.String()))
|
|
}
|
|
}
|
|
|
|
// CatFileBatchCheckAllObjects runs cat-file with --batch-check --batch-all
|
|
func CatFileBatchCheckAllObjects(ctx context.Context, catFileCheckWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath string, errChan chan<- error) {
|
|
defer wg.Done()
|
|
defer catFileCheckWriter.Close()
|
|
|
|
stderr := new(bytes.Buffer)
|
|
var errbuf strings.Builder
|
|
cmd := git.NewCommand(ctx, "cat-file", "--batch-check", "--batch-all-objects")
|
|
if err := cmd.Run(&git.RunOpts{
|
|
Dir: tmpBasePath,
|
|
Stdout: catFileCheckWriter,
|
|
Stderr: stderr,
|
|
}); err != nil {
|
|
log.Error("git cat-file --batch-check --batch-all-object [%s]: %v - %s", tmpBasePath, err, errbuf.String())
|
|
err = fmt.Errorf("git cat-file --batch-check --batch-all-object [%s]: %w - %s", tmpBasePath, err, errbuf.String())
|
|
_ = catFileCheckWriter.CloseWithError(err)
|
|
errChan <- err
|
|
}
|
|
}
|
|
|
|
// CatFileBatch runs cat-file --batch
|
|
func CatFileBatch(ctx context.Context, shasToBatchReader *io.PipeReader, catFileBatchWriter *io.PipeWriter, wg *sync.WaitGroup, tmpBasePath string) {
|
|
defer wg.Done()
|
|
defer shasToBatchReader.Close()
|
|
defer catFileBatchWriter.Close()
|
|
|
|
stderr := new(bytes.Buffer)
|
|
var errbuf strings.Builder
|
|
if err := git.NewCommand(ctx, "cat-file", "--batch").Run(&git.RunOpts{
|
|
Dir: tmpBasePath,
|
|
Stdout: catFileBatchWriter,
|
|
Stdin: shasToBatchReader,
|
|
Stderr: stderr,
|
|
}); err != nil {
|
|
_ = shasToBatchReader.CloseWithError(fmt.Errorf("git rev-list [%s]: %w - %s", tmpBasePath, err, errbuf.String()))
|
|
}
|
|
}
|
|
|
|
// BlobsLessThan1024FromCatFileBatchCheck reads a pipeline from cat-file --batch-check and returns the blobs <1024 in size
|
|
func BlobsLessThan1024FromCatFileBatchCheck(catFileCheckReader *io.PipeReader, shasToBatchWriter *io.PipeWriter, wg *sync.WaitGroup) {
|
|
defer wg.Done()
|
|
defer catFileCheckReader.Close()
|
|
scanner := bufio.NewScanner(catFileCheckReader)
|
|
defer func() {
|
|
_ = shasToBatchWriter.CloseWithError(scanner.Err())
|
|
}()
|
|
for scanner.Scan() {
|
|
line := scanner.Text()
|
|
if len(line) == 0 {
|
|
continue
|
|
}
|
|
fields := strings.Split(line, " ")
|
|
if len(fields) < 3 || fields[1] != "blob" {
|
|
continue
|
|
}
|
|
size, _ := strconv.Atoi(fields[2])
|
|
if size > 1024 {
|
|
continue
|
|
}
|
|
toWrite := []byte(fields[0] + "\n")
|
|
for len(toWrite) > 0 {
|
|
n, err := shasToBatchWriter.Write(toWrite)
|
|
if err != nil {
|
|
_ = catFileCheckReader.CloseWithError(err)
|
|
break
|
|
}
|
|
toWrite = toWrite[n:]
|
|
}
|
|
}
|
|
}
|