Adding upstream version 3.10.8.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
37e9b6d587
commit
03bfe4079e
356 changed files with 28857 additions and 0 deletions
97
forges/filesystem/repository.go
Normal file
97
forges/filesystem/repository.go
Normal file
|
@ -0,0 +1,97 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package filesystem
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"code.forgejo.org/f3/gof3/v3/f3"
|
||||
helpers_repository "code.forgejo.org/f3/gof3/v3/forges/helpers/repository"
|
||||
"code.forgejo.org/f3/gof3/v3/id"
|
||||
"code.forgejo.org/f3/gof3/v3/tree/generic"
|
||||
"code.forgejo.org/f3/gof3/v3/util"
|
||||
)
|
||||
|
||||
type repositoryDriver struct {
|
||||
nodeDriver
|
||||
h helpers_repository.Interface
|
||||
}
|
||||
|
||||
func newRepositoryDriver(content f3.Interface) generic.NodeDriverInterface {
|
||||
n := newNodeDriver(content).(*nodeDriver)
|
||||
r := &repositoryDriver{
|
||||
nodeDriver: *n,
|
||||
}
|
||||
r.h = helpers_repository.NewHelper(r)
|
||||
return r
|
||||
}
|
||||
|
||||
func (o *repositoryDriver) ToFormat() f3.Interface {
|
||||
from := o.GetRepositoryURL()
|
||||
o.Trace("%s", from)
|
||||
f := o.nodeDriver.ToFormat().(*f3.Repository)
|
||||
f.FetchFunc = func(ctx context.Context, destination string, internalRefs []string) {
|
||||
o.Trace("git clone %s %s", from, destination)
|
||||
helpers_repository.GitMirror(ctx, o, from, destination, internalRefs)
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
func (o *repositoryDriver) GetHelper() any {
|
||||
return o.h
|
||||
}
|
||||
|
||||
func (o *repositoryDriver) SetFetchFunc(fetchFunc func(ctx context.Context, destination string, internalRefs []string)) {
|
||||
f := o.nodeDriver.content.(*f3.Repository)
|
||||
f.FetchFunc = fetchFunc
|
||||
}
|
||||
|
||||
func (o *repositoryDriver) GetRepositoryURL() string {
|
||||
return o.getBasePath()
|
||||
}
|
||||
|
||||
func (o *repositoryDriver) GetRepositoryPushURL() string {
|
||||
return o.getBasePath()
|
||||
}
|
||||
|
||||
func (o *repositoryDriver) GetRepositoryInternalRefs() []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
func (o *repositoryDriver) ensureRepository(ctx context.Context, directory string) {
|
||||
if !util.FileExists(directory) {
|
||||
if err := os.MkdirAll(directory, 0o700); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
util.Command(ctx, o, "git", "-C", directory, "init", "--bare")
|
||||
}
|
||||
}
|
||||
|
||||
func (o *repositoryDriver) Put(ctx context.Context) id.NodeID {
|
||||
return o.upsert(ctx)
|
||||
}
|
||||
|
||||
func (o *repositoryDriver) Patch(ctx context.Context) {
|
||||
o.upsert(ctx)
|
||||
}
|
||||
|
||||
func (o *repositoryDriver) upsert(ctx context.Context) id.NodeID {
|
||||
o.nodeDriver.upsert(ctx)
|
||||
repoDir := o.GetRepositoryPushURL()
|
||||
o.GetNode().Trace("%s %s", repoDir, o.GetNode().GetID())
|
||||
o.ensureRepository(ctx, repoDir)
|
||||
return o.h.Upsert(ctx, o.content.(*f3.Repository))
|
||||
}
|
||||
|
||||
func (o *repositoryDriver) Get(ctx context.Context) bool {
|
||||
o.nodeDriver.Get(ctx)
|
||||
f := o.nodeDriver.content.(*f3.Repository)
|
||||
f.SetID(o.GetNode().GetID().String())
|
||||
repoDir := o.GetRepositoryURL()
|
||||
o.GetNode().Trace("%s", repoDir)
|
||||
o.h.Get(ctx)
|
||||
return true
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue