Fast implementation of Git in pure Go codeberg.org/lindenii/furgit
git go
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

cmd/index-pack: Remove

Runxi Yu aed6b338 ff4f4633

-146
-25
cmd/index-pack/algorithm.go
··· 1 - package main 2 - 3 - import ( 4 - "fmt" 5 - 6 - objectid "codeberg.org/lindenii/furgit/object/id" 7 - "codeberg.org/lindenii/furgit/repository" 8 - ) 9 - 10 - func resolveAlgorithm(repo *repository.Repository, objectFormat string) (objectid.Algorithm, error) { 11 - if objectFormat != "" { 12 - algo, ok := objectid.ParseAlgorithm(objectFormat) 13 - if !ok { 14 - return objectid.AlgorithmUnknown, fmt.Errorf("invalid object format %q", objectFormat) 15 - } 16 - 17 - return algo, nil 18 - } 19 - 20 - if repo != nil { 21 - return repo.Algorithm(), nil 22 - } 23 - 24 - return objectid.AlgorithmSHA1, nil 25 - }
-26
cmd/index-pack/main.go
··· 1 - // Command index-pack ingests one pack stream from stdin and writes .pack/.idx/.rev. 2 - package main 3 - 4 - import ( 5 - "flag" 6 - "log" 7 - ) 8 - 9 - func main() { 10 - repoPath := flag.String("r", "", "path to git dir (.git or bare repo root)") 11 - destinationPath := flag.String("destination", "", "path to destination objects/pack directory") 12 - objectFormat := flag.String("object-format", "", "object format (sha1 or sha256)") 13 - fixThin := flag.Bool("fix-thin", false, "fix thin packs using repository object store") 14 - writeRev := flag.Bool("rev-index", true, "write reverse index (.rev)") 15 - 16 - flag.Parse() 17 - 18 - if *destinationPath == "" { 19 - log.Fatal("must provide -destination <objects/pack>") 20 - } 21 - 22 - err := run(*repoPath, *destinationPath, *objectFormat, *fixThin, *writeRev) 23 - if err != nil { 24 - log.Fatalf("run: %v", err) 25 - } 26 - }
-95
cmd/index-pack/run.go
··· 1 - package main 2 - 3 - import ( 4 - "fmt" 5 - "os" 6 - "path/filepath" 7 - 8 - "codeberg.org/lindenii/furgit/format/packfile/ingest" 9 - objectid "codeberg.org/lindenii/furgit/object/id" 10 - objectstore "codeberg.org/lindenii/furgit/object/store" 11 - "codeberg.org/lindenii/furgit/repository" 12 - ) 13 - 14 - func run(repoPath, destinationPath, objectFormat string, fixThin, writeRev bool) error { 15 - var ( 16 - algo objectid.Algorithm 17 - base objectstore.Reader 18 - repo *repository.Repository 19 - ) 20 - 21 - if repoPath != "" { 22 - repoRoot, err := os.OpenRoot(repoPath) 23 - if err != nil { 24 - return fmt.Errorf("open repo root: %w", err) 25 - } 26 - 27 - defer func() { _ = repoRoot.Close() }() 28 - 29 - repo, err = repository.Open(repoRoot) 30 - if err != nil { 31 - return fmt.Errorf("open repository: %w", err) 32 - } 33 - 34 - defer func() { _ = repo.Close() }() 35 - } 36 - 37 - algo, err := resolveAlgorithm(repo, objectFormat) 38 - if err != nil { 39 - return err 40 - } 41 - 42 - if fixThin { 43 - if repo == nil { 44 - return fmt.Errorf("fix-thin requires -r <repo>") 45 - } 46 - 47 - if repo.Algorithm() != algo { 48 - return fmt.Errorf("algorithm mismatch: repo=%s flag=%s", repo.Algorithm(), algo) 49 - } 50 - 51 - base = repo.Objects() 52 - } 53 - 54 - absDestination, err := filepath.Abs(destinationPath) 55 - if err != nil { 56 - return fmt.Errorf("absolute destination path: %w", err) 57 - } 58 - 59 - destinationRoot, err := os.OpenRoot(absDestination) 60 - if err != nil { 61 - return fmt.Errorf("open destination root: %w", err) 62 - } 63 - 64 - defer func() { _ = destinationRoot.Close() }() 65 - 66 - pending, err := ingest.Ingest(os.Stdin, algo, ingest.Options{ 67 - FixThin: fixThin, 68 - WriteRev: writeRev, 69 - Base: base, 70 - RequireTrailingEOF: true, 71 - }) 72 - if err != nil { 73 - return err 74 - } 75 - 76 - if pending.Header().ObjectCount == 0 { 77 - discarded, err := pending.Discard() 78 - if err != nil { 79 - return err 80 - } 81 - 82 - _, _ = fmt.Fprintf(os.Stdout, "pack\t%s\n", discarded.PackHash.String()) 83 - 84 - return nil 85 - } 86 - 87 - result, err := pending.Continue(destinationRoot) 88 - if err != nil { 89 - return err 90 - } 91 - 92 - _, _ = fmt.Fprintf(os.Stdout, "pack\t%s\n", result.PackHash.String()) 93 - 94 - return nil 95 - }