Temporary rename info/alternates so --batch-all-objects doesn't follow it (#2039)

pull/3519/head
Darko Draskovic 2024-05-20 18:43:52 +00:00 committed by Harness
parent 6da5c93706
commit d4ca33b82d
4 changed files with 22 additions and 14 deletions

View File

@ -93,18 +93,13 @@ func (c *Controller) PreReceive(
return hook.Output{}, fmt.Errorf("failed to extend pre-receive hook: %w", err) return hook.Output{}, fmt.Errorf("failed to extend pre-receive hook: %w", err)
} }
// File size check currently checks all the blobs in alternate as well in the original repo dirs. err = c.checkFileSizeLimit(ctx, rgit, repo, in, &output)
// We want to check file size only in alternate dirs. if output.Error != nil {
// Temporarily comment out file size check until the solution is found. return output, nil
// TODO: find the way to check the blob size only in alternate dirs. }
if err != nil {
// err = c.checkFileSizeLimit(ctx, rgit, repo, in, &output) return hook.Output{}, err
// if output.Error != nil { }
// return output, nil
// }
// if err != nil {
// return hook.Output{}, err
// }
return output, nil return output, nil
} }

View File

@ -26,7 +26,6 @@ import (
"github.com/gotidy/ptr" "github.com/gotidy/ptr"
) )
// nolint:unused
func (c *Controller) checkFileSizeLimit( func (c *Controller) checkFileSizeLimit(
ctx context.Context, ctx context.Context,
rgit RestrictedGIT, rgit RestrictedGIT,

View File

@ -104,7 +104,6 @@ func FMTDuration(d time.Duration) string {
return d.String() return d.String()
} }
// nolint:unused
func printOversizeFiles( func printOversizeFiles(
output *hook.Output, output *hook.Output,
oversizeFiles []git.FileInfo, oversizeFiles []git.FileInfo,

View File

@ -18,6 +18,7 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"os"
"time" "time"
"github.com/harness/gitness/errors" "github.com/harness/gitness/errors"
@ -306,6 +307,16 @@ func catFileBatchCheckAllObjects(
repoPath string, repoPath string,
gitObjDir string, gitObjDir string,
) ([]parser.BatchCheckObject, error) { ) ([]parser.BatchCheckObject, error) {
// "info/alternates" points to the original repository.
const oldFilename = "/info/alternates"
const newFilename = "/info/alternates.bkp"
// --batch-all-objects reports objects in the current repository and in all alternate directories.
// We want to report objects in the current repository only.
if err := os.Rename(gitObjDir+oldFilename, gitObjDir+newFilename); err != nil && !os.IsNotExist(err) {
return nil, fmt.Errorf("failed to rename %s to %s: %w", oldFilename, newFilename, err)
}
cmd := command.New("cat-file", cmd := command.New("cat-file",
command.WithFlag("--batch-check"), command.WithFlag("--batch-check"),
command.WithFlag("--batch-all-objects"), command.WithFlag("--batch-all-objects"),
@ -328,5 +339,9 @@ func catFileBatchCheckAllObjects(
return nil, fmt.Errorf("failed to parse output of cat-file batch check all objects: %w", err) return nil, fmt.Errorf("failed to parse output of cat-file batch check all objects: %w", err)
} }
if err := os.Rename(gitObjDir+newFilename, gitObjDir+oldFilename); err != nil && !os.IsNotExist(err) {
return nil, fmt.Errorf("failed to rename %s to %s: %w", newFilename, oldFilename, err)
}
return objects, nil return objects, nil
} }