Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion cmd/gogit/show-index.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package main

import (
"bytes"
"crypto"
"errors"
"fmt"
"io"
"io/fs"
"time"

"github.com/go-git/go-git/v6/plumbing/format/idxfile"
"github.com/go-git/go-git/v6/plumbing/hash"
Expand All @@ -29,7 +32,12 @@ var showIndexCmd = &cobra.Command{

func showIndexRun(in io.Reader, out io.Writer) error {
idx := idxfile.NewMemoryIndex(crypto.SHA1.Size())
dec := idxfile.NewDecoder(in, hash.New(crypto.SHA1))
idxIn, err := idxInput(in)
if err != nil {
return err
}

dec := idxfile.NewDecoder(idxIn, hash.New(crypto.SHA1))

if err := dec.Decode(idx); err != nil {
return fmt.Errorf("decode idx: %w", err)
Expand All @@ -56,3 +64,35 @@ func showIndexRun(in io.Reader, out io.Writer) error {

return nil
}

func idxInput(in io.Reader) (idxfile.Input, error) {
b, err := io.ReadAll(in)
if err != nil {
return nil, fmt.Errorf("read idx input: %w", err)
}

return &memoryIdxInput{
Reader: bytes.NewReader(b),
size: int64(len(b)),
}, nil
}

type memoryIdxInput struct {
*bytes.Reader
size int64
}

func (in *memoryIdxInput) Stat() (fs.FileInfo, error) {
return memoryIdxFileInfo{size: in.size}, nil
}

type memoryIdxFileInfo struct {
size int64
}

func (fi memoryIdxFileInfo) Name() string { return "" }
func (fi memoryIdxFileInfo) Size() int64 { return fi.size }
func (fi memoryIdxFileInfo) Mode() fs.FileMode { return 0 }
func (fi memoryIdxFileInfo) ModTime() time.Time { return time.Time{} }
func (fi memoryIdxFileInfo) IsDir() bool { return false }
func (fi memoryIdxFileInfo) Sys() any { return nil }
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.25.10
require (
github.com/go-git/go-billy/v6 v6.0.0-alpha.1
github.com/go-git/go-git-fixtures/v6 v6.0.0-alpha.1
github.com/go-git/go-git/v6 v6.0.0-alpha.3.0.20260512141313-533ba09d9588
github.com/go-git/go-git/v6 v6.0.0-alpha.4
github.com/spf13/cobra v1.10.2
golang.org/x/crypto v0.52.0
golang.org/x/term v0.43.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ github.com/go-git/go-billy/v6 v6.0.0-alpha.1 h1:xVjAR4oUvrKy7/Xuw/lLlV3gkxR3KO2H
github.com/go-git/go-billy/v6 v6.0.0-alpha.1/go.mod h1:eaCUpHbedW7//EwcYmUDfJe2N6sJC9O12AT0OTqJR1E=
github.com/go-git/go-git-fixtures/v6 v6.0.0-alpha.1 h1:gmqi2jvsreu0s8JMLylYDFq4sbjHwwlhktMw0DUg3mA=
github.com/go-git/go-git-fixtures/v6 v6.0.0-alpha.1/go.mod h1:ECf1MqJlBdYpKggBrOXjo/0EnvRZx6D++I86UYjPgAQ=
github.com/go-git/go-git/v6 v6.0.0-alpha.3.0.20260512141313-533ba09d9588 h1:TgVntrlBTW1A2HAoPljPLhP8rxmLzI4mUPv2Aq7r4KQ=
github.com/go-git/go-git/v6 v6.0.0-alpha.3.0.20260512141313-533ba09d9588/go.mod h1:4ODa/G7hPWrh4Y+7lmt59Ij3zW38IEfvRoAZxLYYBhc=
github.com/go-git/go-git/v6 v6.0.0-alpha.4 h1:aDTc2UGanmaE7FkGLSlBEB9nohMnQ+RKXcfq/D+esDQ=
github.com/go-git/go-git/v6 v6.0.0-alpha.4/go.mod h1:4ODa/G7hPWrh4Y+7lmt59Ij3zW38IEfvRoAZxLYYBhc=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kevinburke/ssh_config v1.6.0 h1:J1FBfmuVosPHf5GRdltRLhPJtJpTlMdKTBjRgTaQBFY=
Expand Down
Loading