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.

*: Lint

Runxi Yu f2922155 6ba7af1f

+243 -192
+14 -7
.golangci.yaml
··· 7 7 - internal/compress/flate 8 8 - internal/compress/internal 9 9 disable: 10 - - depguard # not sensible for us 11 10 - dupword # extremely normal in tests and a pretty unnecessary linter 12 11 - goconst # unnecessary especially for our parsing code; many false positives 13 - - mnd # same as above 14 - - lll # poor standard 15 - - ireturn # not an issue 16 - - perfsprint # silly fmt.Errorf vs errors.New suggestion 12 + - mnd # unnecessary especially for our parsing code; many false positives 13 + - lll # common sense is much better than these sort of rules 17 14 - gosmopolitan # completely normal to have CJK and such in tests 18 - - gochecknoglobals # unlikely to be introduce accidentally and are usually intentional 19 15 - nonamedreturns # named returns are often good for clarity 20 - - errname # ErrXXX is better than XXXError 21 16 - wsl # outdated, use wsl_v5 instead 22 17 - varnamelen # it's rather reasonable to have counters like i, even when it spans quite a bit 23 18 - gocyclo # cyclomatic metrics aren't that good ··· 31 26 - gocognit # tmp: should consider sometime 32 27 33 28 settings: 29 + perfsprint: 30 + errorf: false 31 + depguard: 32 + rules: 33 + Main: 34 + list-mode: strict 35 + files: 36 + - $all 37 + allow: 38 + - $gostd 39 + - codeberg.org/lindenii/furgit 40 + - golang.org/x 34 41 gosec: 35 42 excludes: 36 43 - G301 # UNIX permissions
+4 -4
format/commitgraph/read/bloom.go
··· 38 38 39 39 // BloomFilterAt returns one commit's changed-path Bloom filter. 40 40 // 41 - // Returns ErrBloomUnavailable when this commit graph has no Bloom data. 41 + // Returns BloomUnavailableError when this commit graph has no Bloom data. 42 42 func (reader *Reader) BloomFilterAt(pos Position) (*bloom.Filter, error) { 43 43 layer, err := reader.layerByPosition(pos) 44 44 if err != nil { ··· 46 46 } 47 47 48 48 if layer.chunkBloomIndex == nil || layer.chunkBloomData == nil || layer.bloomSettings == nil { 49 - return nil, &ErrBloomUnavailable{Pos: pos} 49 + return nil, &BloomUnavailableError{Pos: pos} 50 50 } 51 51 52 52 start, end, err := bloomRange(layer, pos.Index) ··· 86 86 } 87 87 88 88 if end < start { 89 - return 0, 0, &ErrMalformed{Path: layer.path, Reason: "invalid BIDX range"} 89 + return 0, 0, &MalformedError{Path: layer.path, Reason: "invalid BIDX range"} 90 90 } 91 91 92 92 bdatLen := len(layer.chunkBloomData) - bloom.DataHeaderSize ··· 97 97 } 98 98 99 99 if end > bdatLenU32 { 100 - return 0, 0, &ErrMalformed{Path: layer.path, Reason: "BIDX range out of BDAT bounds"} 100 + return 0, 0, &MalformedError{Path: layer.path, Reason: "BIDX range out of BDAT bounds"} 101 101 } 102 102 103 103 startInt, err := intconv.Uint64ToInt(uint64(start))
+2 -2
format/commitgraph/read/edges.go
··· 9 9 10 10 func (reader *Reader) decodeExtraEdgeList(layer *layer, edgeStart uint32) ([]Position, error) { 11 11 if len(layer.chunkExtraEdges) == 0 { 12 - return nil, &ErrMalformed{Path: layer.path, Reason: "missing EDGE chunk"} 12 + return nil, &MalformedError{Path: layer.path, Reason: "missing EDGE chunk"} 13 13 } 14 14 15 15 out := make([]Position, 0) ··· 24 24 } 25 25 26 26 if off+4 > len(layer.chunkExtraEdges) { 27 - return nil, &ErrMalformed{Path: layer.path, Reason: "EDGE index out of range"} 27 + return nil, &MalformedError{Path: layer.path, Reason: "EDGE index out of range"} 28 28 } 29 29 30 30 word := binary.BigEndian.Uint32(layer.chunkExtraEdges[off : off+4])
+15 -15
format/commitgraph/read/errors.go
··· 6 6 "codeberg.org/lindenii/furgit/objectid" 7 7 ) 8 8 9 - // ErrNotFound reports a missing commit graph entry by object ID. 10 - type ErrNotFound struct { 9 + // NotFoundError reports a missing commit graph entry by object ID. 10 + type NotFoundError struct { 11 11 OID objectid.ObjectID 12 12 } 13 13 14 14 // Error implements error. 15 - func (err *ErrNotFound) Error() string { 15 + func (err *NotFoundError) Error() string { 16 16 return fmt.Sprintf("format/commitgraph: object not found: %s", err.OID) 17 17 } 18 18 19 - // ErrPositionOutOfRange reports an invalid graph position. 20 - type ErrPositionOutOfRange struct { 19 + // PositionOutOfRangeError reports an invalid graph position. 20 + type PositionOutOfRangeError struct { 21 21 Pos Position 22 22 } 23 23 24 24 // Error implements error. 25 - func (err *ErrPositionOutOfRange) Error() string { 25 + func (err *PositionOutOfRangeError) Error() string { 26 26 return fmt.Sprintf("format/commitgraph: position out of range: graph=%d index=%d", err.Pos.Graph, err.Pos.Index) 27 27 } 28 28 29 - // ErrMalformed reports malformed commit-graph data. 30 - type ErrMalformed struct { 29 + // MalformedError reports malformed commit-graph data. 30 + type MalformedError struct { 31 31 Path string 32 32 Reason string 33 33 } 34 34 35 35 // Error implements error. 36 - func (err *ErrMalformed) Error() string { 36 + func (err *MalformedError) Error() string { 37 37 return fmt.Sprintf("format/commitgraph: malformed %q: %s", err.Path, err.Reason) 38 38 } 39 39 40 - // ErrUnsupportedVersion reports unsupported commit-graph version. 41 - type ErrUnsupportedVersion struct { 40 + // UnsupportedVersionError reports unsupported commit-graph version. 41 + type UnsupportedVersionError struct { 42 42 Version uint8 43 43 } 44 44 45 45 // Error implements error. 46 - func (err *ErrUnsupportedVersion) Error() string { 46 + func (err *UnsupportedVersionError) Error() string { 47 47 return fmt.Sprintf("format/commitgraph: unsupported version %d", err.Version) 48 48 } 49 49 50 - // ErrBloomUnavailable reports missing changed-path bloom data at one position. 51 - type ErrBloomUnavailable struct { 50 + // BloomUnavailableError reports missing changed-path bloom data at one position. 51 + type BloomUnavailableError struct { 52 52 Pos Position 53 53 } 54 54 55 55 // Error implements error. 56 - func (err *ErrBloomUnavailable) Error() string { 56 + func (err *BloomUnavailableError) Error() string { 57 57 return fmt.Sprintf("format/commitgraph: bloom unavailable at position graph=%d index=%d", err.Pos.Graph, err.Pos.Index) 58 58 }
+1 -1
format/commitgraph/read/generation.go
··· 34 34 } 35 35 36 36 if gdo2Off+8 > len(layer.chunkGenerationOv) { 37 - return 0, &ErrMalformed{Path: layer.path, Reason: "GDO2 index out of range"} 37 + return 0, &MalformedError{Path: layer.path, Reason: "GDO2 index out of range"} 38 38 } 39 39 40 40 overflow := binary.BigEndian.Uint64(layer.chunkGenerationOv[gdo2Off : gdo2Off+8])
+5 -5
format/commitgraph/read/hash.go
··· 16 16 func validateChainBaseHashes(algo objectid.Algorithm, chain []string, idx int, graph *layer) error { 17 17 if idx == 0 { 18 18 if len(graph.chunkBaseGraphs) != 0 { 19 - return &ErrMalformed{Path: graph.path, Reason: "unexpected BASE chunk in first graph"} 19 + return &MalformedError{Path: graph.path, Reason: "unexpected BASE chunk in first graph"} 20 20 } 21 21 22 22 return nil ··· 26 26 27 27 expectedLen := idx * hashSize 28 28 if len(graph.chunkBaseGraphs) != expectedLen { 29 - return &ErrMalformed{ 29 + return &MalformedError{ 30 30 Path: graph.path, 31 31 Reason: fmt.Sprintf("BASE chunk length %d does not match expected %d", len(graph.chunkBaseGraphs), expectedLen), 32 32 } ··· 42 42 } 43 43 44 44 if baseHash.String() != chain[i] { 45 - return &ErrMalformed{ 45 + return &MalformedError{ 46 46 Path: graph.path, 47 47 Reason: fmt.Sprintf("BASE chunk mismatch at index %d", i), 48 48 } ··· 55 55 func verifyTrailerHash(data []byte, algo objectid.Algorithm, path string) error { 56 56 hashSize := algo.Size() 57 57 if len(data) < hashSize { 58 - return &ErrMalformed{Path: path, Reason: "file too short for trailer"} 58 + return &MalformedError{Path: path, Reason: "file too short for trailer"} 59 59 } 60 60 61 61 hashImpl, err := algo.New() ··· 72 72 73 73 want := data[len(data)-hashSize:] 74 74 if !bytes.Equal(got, want) { 75 - return &ErrMalformed{Path: path, Reason: "trailer hash mismatch"} 75 + return &MalformedError{Path: path, Reason: "trailer hash mismatch"} 76 76 } 77 77 78 78 return nil
+1 -1
format/commitgraph/read/layer_open.go
··· 26 26 if size < int64(commitgraph.HeaderSize+commitgraph.FanoutSize+algo.Size()) { 27 27 _ = file.Close() 28 28 29 - return nil, &ErrMalformed{Path: relPath, Reason: "file too short"} 29 + return nil, &MalformedError{Path: relPath, Reason: "file too short"} 30 30 } 31 31 32 32 mapLen, err := intconv.Int64ToUint64(size)
+23 -23
format/commitgraph/read/layer_parse.go
··· 11 11 12 12 func parseLayer(layer *layer, algo objectid.Algorithm) error { //nolint:maintidx 13 13 if len(layer.data) < commitgraph.HeaderSize { 14 - return &ErrMalformed{Path: layer.path, Reason: "file too short"} 14 + return &MalformedError{Path: layer.path, Reason: "file too short"} 15 15 } 16 16 17 17 header := layer.data[:commitgraph.HeaderSize] 18 18 19 19 signature := binary.BigEndian.Uint32(header[:4]) 20 20 if signature != commitgraph.FileSignature { 21 - return &ErrMalformed{Path: layer.path, Reason: "invalid signature"} 21 + return &MalformedError{Path: layer.path, Reason: "invalid signature"} 22 22 } 23 23 24 24 version := header[4] 25 25 if version != commitgraph.FileVersion { 26 - return &ErrUnsupportedVersion{Version: version} 26 + return &UnsupportedVersionError{Version: version} 27 27 } 28 28 29 29 expectedHashVersion, err := intconv.Uint32ToUint8(algo.PackHashID()) ··· 33 33 34 34 hashVersion := header[5] 35 35 if hashVersion != expectedHashVersion { 36 - return &ErrMalformed{Path: layer.path, Reason: "hash version does not match object format"} 36 + return &MalformedError{Path: layer.path, Reason: "hash version does not match object format"} 37 37 } 38 38 39 39 numChunks := int(header[6]) ··· 44 44 45 45 tocEnd := tocStart + tocLen 46 46 if tocEnd > len(layer.data) { 47 - return &ErrMalformed{Path: layer.path, Reason: "truncated chunk table"} 47 + return &MalformedError{Path: layer.path, Reason: "truncated chunk table"} 48 48 } 49 49 50 50 type tocEntry struct { ··· 65 65 } 66 66 67 67 if entries[len(entries)-1].id != 0 { 68 - return &ErrMalformed{Path: layer.path, Reason: "missing chunk table terminator"} 68 + return &MalformedError{Path: layer.path, Reason: "missing chunk table terminator"} 69 69 } 70 70 71 71 trailerStart := len(layer.data) - algo.Size() ··· 74 74 for i := range numChunks { 75 75 entry := entries[i] 76 76 if entry.id == 0 { 77 - return &ErrMalformed{Path: layer.path, Reason: "early chunk table terminator"} 77 + return &MalformedError{Path: layer.path, Reason: "early chunk table terminator"} 78 78 } 79 79 80 80 next := entries[i+1] ··· 90 90 } 91 91 92 92 if start < tocEnd || end < start || end > trailerStart { 93 - return &ErrMalformed{Path: layer.path, Reason: "invalid chunk offsets"} 93 + return &MalformedError{Path: layer.path, Reason: "invalid chunk offsets"} 94 94 } 95 95 96 96 if _, exists := chunks[entry.id]; exists { 97 - return &ErrMalformed{Path: layer.path, Reason: "duplicate chunk id"} 97 + return &MalformedError{Path: layer.path, Reason: "duplicate chunk id"} 98 98 } 99 99 100 100 chunks[entry.id] = layer.data[start:end] ··· 102 102 103 103 oidf := chunks[commitgraph.ChunkOIDF] 104 104 if len(oidf) != commitgraph.FanoutSize { 105 - return &ErrMalformed{Path: layer.path, Reason: "invalid OIDF length"} 105 + return &MalformedError{Path: layer.path, Reason: "invalid OIDF length"} 106 106 } 107 107 108 108 layer.chunkOIDFanout = oidf ··· 113 113 114 114 next := binary.BigEndian.Uint32(oidf[(i+1)*4 : (i+2)*4]) 115 115 if cur > next { 116 - return &ErrMalformed{Path: layer.path, Reason: "non-monotonic OIDF fanout"} 116 + return &MalformedError{Path: layer.path, Reason: "non-monotonic OIDF fanout"} 117 117 } 118 118 } 119 119 ··· 133 133 } 134 134 135 135 if len(oidl) != oidlWantLen { 136 - return &ErrMalformed{Path: layer.path, Reason: "invalid OIDL length"} 136 + return &MalformedError{Path: layer.path, Reason: "invalid OIDL length"} 137 137 } 138 138 139 139 layer.chunkOIDLookup = oidl ··· 154 154 } 155 155 156 156 if len(cdat) != cdatWantLen { 157 - return &ErrMalformed{Path: layer.path, Reason: "invalid CDAT length"} 157 + return &MalformedError{Path: layer.path, Reason: "invalid CDAT length"} 158 158 } 159 159 160 160 layer.chunkCommit = cdat ··· 169 169 } 170 170 171 171 if len(gda2) != wantLen { 172 - return &ErrMalformed{Path: layer.path, Reason: "invalid GDA2 length"} 172 + return &MalformedError{Path: layer.path, Reason: "invalid GDA2 length"} 173 173 } 174 174 175 175 layer.chunkGeneration = gda2 ··· 178 178 gdo2 := chunks[commitgraph.ChunkGDO2] 179 179 if len(gdo2) != 0 { 180 180 if len(gdo2)%8 != 0 { 181 - return &ErrMalformed{Path: layer.path, Reason: "invalid GDO2 length"} 181 + return &MalformedError{Path: layer.path, Reason: "invalid GDO2 length"} 182 182 } 183 183 184 184 layer.chunkGenerationOv = gdo2 ··· 187 187 edge := chunks[commitgraph.ChunkEDGE] 188 188 if len(edge) != 0 { 189 189 if len(edge)%4 != 0 { 190 - return &ErrMalformed{Path: layer.path, Reason: "invalid EDGE length"} 190 + return &MalformedError{Path: layer.path, Reason: "invalid EDGE length"} 191 191 } 192 192 193 193 layer.chunkExtraEdges = edge ··· 196 196 base := chunks[commitgraph.ChunkBASE] 197 197 if baseCount == 0 { 198 198 if len(base) != 0 { 199 - return &ErrMalformed{Path: layer.path, Reason: "unexpected BASE chunk"} 199 + return &MalformedError{Path: layer.path, Reason: "unexpected BASE chunk"} 200 200 } 201 201 } else { 202 202 wantLen64 := uint64(baseCount) * hashSizeU64 ··· 207 207 } 208 208 209 209 if len(base) != wantLen { 210 - return &ErrMalformed{Path: layer.path, Reason: "invalid BASE length"} 210 + return &MalformedError{Path: layer.path, Reason: "invalid BASE length"} 211 211 } 212 212 213 213 layer.chunkBaseGraphs = base ··· 220 220 bdat := chunks[commitgraph.ChunkBDAT] 221 221 if len(bidx) != 0 || len(bdat) != 0 { //nolint:nestif 222 222 if len(bidx) == 0 || len(bdat) == 0 { 223 - return &ErrMalformed{Path: layer.path, Reason: "BIDX/BDAT must both be present"} 223 + return &MalformedError{Path: layer.path, Reason: "BIDX/BDAT must both be present"} 224 224 } 225 225 226 226 bidxWantLen64 := uint64(layer.numCommits) * 4 ··· 231 231 } 232 232 233 233 if len(bidx) != bidxWantLen { 234 - return &ErrMalformed{Path: layer.path, Reason: "invalid BIDX length"} 234 + return &MalformedError{Path: layer.path, Reason: "invalid BIDX length"} 235 235 } 236 236 237 237 if len(bdat) < bloom.DataHeaderSize { 238 - return &ErrMalformed{Path: layer.path, Reason: "invalid BDAT length"} 238 + return &MalformedError{Path: layer.path, Reason: "invalid BDAT length"} 239 239 } 240 240 241 241 settings, err := bloom.ParseSettings(bdat) ··· 250 250 251 251 cur := binary.BigEndian.Uint32(bidx[off : off+4]) 252 252 if i > 0 && cur < prev { 253 - return &ErrMalformed{Path: layer.path, Reason: "non-monotonic BIDX"} 253 + return &MalformedError{Path: layer.path, Reason: "non-monotonic BIDX"} 254 254 } 255 255 256 256 bdatDataLen := len(bdat) - bloom.DataHeaderSize ··· 261 261 } 262 262 263 263 if cur > bdatDataLenU32 { 264 - return &ErrMalformed{Path: layer.path, Reason: "BIDX offset out of range"} 264 + return &MalformedError{Path: layer.path, Reason: "BIDX offset out of range"} 265 265 } 266 266 267 267 prev = cur
+2 -2
format/commitgraph/read/layer_pos.go
··· 9 9 } 10 10 11 11 if graphIdx < 0 || graphIdx >= len(reader.layers) { 12 - return nil, &ErrPositionOutOfRange{Pos: pos} 12 + return nil, &PositionOutOfRangeError{Pos: pos} 13 13 } 14 14 15 15 layer := &reader.layers[graphIdx] 16 16 if pos.Index >= layer.numCommits { 17 - return nil, &ErrPositionOutOfRange{Pos: pos} 17 + return nil, &PositionOutOfRangeError{Pos: pos} 18 18 } 19 19 20 20 return layer, nil
+2 -2
format/commitgraph/read/lookup.go
··· 8 8 // Lookup resolves one object ID to one graph position. 9 9 func (reader *Reader) Lookup(oid objectid.ObjectID) (Position, error) { 10 10 if oid.Algorithm() != reader.algo { 11 - return Position{}, &ErrNotFound{OID: oid} 11 + return Position{}, &NotFoundError{OID: oid} 12 12 } 13 13 14 14 for layerIdx := len(reader.layers) - 1; layerIdx >= 0; layerIdx-- { ··· 25 25 } 26 26 } 27 27 28 - return Position{}, &ErrNotFound{OID: oid} 28 + return Position{}, &NotFoundError{OID: oid} 29 29 }
+5 -5
format/commitgraph/read/open_chain.go
··· 17 17 file, err := root.Open(chainPath) 18 18 if err != nil { 19 19 if errors.Is(err, os.ErrNotExist) { 20 - return nil, &ErrMalformed{Path: chainPath, Reason: "missing commit-graph-chain"} 20 + return nil, &MalformedError{Path: chainPath, Reason: "missing commit-graph-chain"} 21 21 } 22 22 23 23 return nil, err ··· 47 47 } 48 48 49 49 if len(hashes) == 0 { 50 - return nil, &ErrMalformed{Path: chainPath, Reason: "empty chain"} 50 + return nil, &MalformedError{Path: chainPath, Reason: "empty chain"} 51 51 } 52 52 53 53 layers := make([]layer, 0, len(hashes)) ··· 70 70 if len(hashHex) != algo.HexLen() { 71 71 closeLayers(layers) 72 72 73 - return nil, &ErrMalformed{ 73 + return nil, &MalformedError{ 74 74 Path: chainPath, 75 75 Reason: fmt.Sprintf("invalid graph hash length at line %d", i+1), 76 76 } ··· 90 90 91 91 closeLayers(layers) 92 92 93 - return nil, &ErrMalformed{ 93 + return nil, &MalformedError{ 94 94 Path: relPath, 95 95 Reason: fmt.Sprintf("BASE count %d does not match chain depth %d", loaded.baseCount, i), 96 96 } ··· 114 114 115 115 closeLayers(layers) 116 116 117 - return nil, &ErrMalformed{Path: relPath, Reason: "total commit count overflow"} 117 + return nil, &MalformedError{Path: relPath, Reason: "total commit count overflow"} 118 118 } 119 119 120 120 total = totalNext
+2 -2
format/commitgraph/read/parents.go
··· 35 35 } 36 36 37 37 if len(parents) == 0 { 38 - return ParentRef{}, ParentRef{}, nil, &ErrMalformed{Path: layer.path, Reason: "empty EDGE list"} 38 + return ParentRef{}, ParentRef{}, nil, &MalformedError{Path: layer.path, Reason: "empty EDGE list"} 39 39 } 40 40 41 41 parent2 := ParentRef{Valid: true, Pos: parents[0]} ··· 52 52 } 53 53 54 54 if raw&commitgraph.ParentExtraMask != 0 { 55 - return ParentRef{}, &ErrMalformed{ 55 + return ParentRef{}, &MalformedError{ 56 56 Path: "commit-graph", 57 57 Reason: "unexpected EDGE marker in single-parent slot", 58 58 }
+1 -1
format/commitgraph/read/position.go
··· 31 31 } 32 32 } 33 33 34 - return Position{}, &ErrMalformed{ 34 + return Position{}, &MalformedError{ 35 35 Path: "commit-graph", 36 36 Reason: fmt.Sprintf("parent global position out of range: %d", global), 37 37 }
+4 -4
format/commitgraph/read/read_test.go
··· 157 157 158 158 _, err = reader.BloomFilterAt(pos) 159 159 if err == nil { 160 - t.Fatal("BloomFilterAt() error = nil, want ErrBloomUnavailable") 160 + t.Fatal("BloomFilterAt() error = nil, want BloomUnavailableError") 161 161 } 162 162 163 - var unavailable *read.ErrBloomUnavailable 163 + var unavailable *read.BloomUnavailableError 164 164 if !errors.As(err, &unavailable) { 165 - t.Fatalf("BloomFilterAt() error type = %T, want *ErrBloomUnavailable", err) 165 + t.Fatalf("BloomFilterAt() error type = %T, want *BloomUnavailableError", err) 166 166 } 167 167 168 168 if unavailable.Pos != pos { 169 - t.Fatalf("ErrBloomUnavailable.Pos = %+v, want %+v", unavailable.Pos, pos) 169 + t.Fatalf("BloomUnavailableError.Pos = %+v, want %+v", unavailable.Pos, pos) 170 170 } 171 171 }) 172 172 }
+5 -5
format/pack/ingest/drain.go
··· 18 18 19 19 reader, err := zlib.NewReader(state.stream) 20 20 if err != nil { 21 - return 0, 0, zero, &ErrMalformedPackEntry{Offset: record.offset, Reason: fmt.Sprintf("open zlib stream: %v", err)} 21 + return 0, 0, zero, &MalformedPackEntryError{Offset: record.offset, Reason: fmt.Sprintf("open zlib stream: %v", err)} 22 22 } 23 23 24 24 defer func() { _ = reader.Close() }() ··· 28 28 if packfmt.IsBaseObjectType(record.packedType) { 29 29 header, ok := objectheader.Encode(record.packedType, record.declaredSize) 30 30 if !ok { 31 - return 0, 0, zero, &ErrMalformedPackEntry{Offset: record.offset, Reason: "encode object header"} 31 + return 0, 0, zero, &MalformedPackEntryError{Offset: record.offset, Reason: "encode object header"} 32 32 } 33 33 34 34 hashImpl, err := state.algo.New() ··· 40 40 41 41 n, err := io.Copy(hashImpl, reader) 42 42 if err != nil { 43 - return 0, 0, zero, &ErrMalformedPackEntry{Offset: record.offset, Reason: fmt.Sprintf("inflate base object: %v", err)} 43 + return 0, 0, zero, &MalformedPackEntryError{Offset: record.offset, Reason: fmt.Sprintf("inflate base object: %v", err)} 44 44 } 45 45 46 46 total = n ··· 56 56 if record.packedType == objecttype.TypeOfsDelta || record.packedType == objecttype.TypeRefDelta { 57 57 n, err := io.Copy(io.Discard, reader) 58 58 if err != nil { 59 - return 0, 0, zero, &ErrMalformedPackEntry{Offset: record.offset, Reason: fmt.Sprintf("inflate delta payload: %v", err)} 59 + return 0, 0, zero, &MalformedPackEntryError{Offset: record.offset, Reason: fmt.Sprintf("inflate delta payload: %v", err)} 60 60 } 61 61 62 62 total = n ··· 64 64 return total, reader.InputConsumed(), zero, nil 65 65 } 66 66 67 - return 0, 0, zero, &ErrMalformedPackEntry{Offset: record.offset, Reason: "unsupported payload type"} 67 + return 0, 0, zero, &MalformedPackEntryError{Offset: record.offset, Reason: "unsupported payload type"} 68 68 }
+3 -3
format/pack/ingest/entry.go
··· 22 22 } 23 23 24 24 if contentLen != record.declaredSize { 25 - return 0, &ErrMalformedPackEntry{ 25 + return 0, &MalformedPackEntryError{ 26 26 Offset: startOffset, 27 27 Reason: fmt.Sprintf("inflated size mismatch got %d want %d", contentLen, record.declaredSize), 28 28 } ··· 30 30 31 31 endOffset := startOffset + uint64(record.headerLen) + consumedInput 32 32 if endOffset > state.stream.consumed { 33 - return 0, &ErrMalformedPackEntry{ 33 + return 0, &MalformedPackEntryError{ 34 34 Offset: startOffset, 35 35 Reason: fmt.Sprintf("entry end offset overflow got %d > stream %d", endOffset, state.stream.consumed), 36 36 } ··· 40 40 41 41 record.dataOffset = startOffset + uint64(record.headerLen) 42 42 if record.packedLen < uint64(record.headerLen) { 43 - return 0, &ErrMalformedPackEntry{Offset: startOffset, Reason: "negative payload span"} 43 + return 0, &MalformedPackEntryError{Offset: startOffset, Reason: "negative payload span"} 44 44 } 45 45 46 46 crc, err := state.stream.endEntryCRC()
+9 -9
format/pack/ingest/entry_prefix.go
··· 16 16 17 17 first, err := state.stream.ReadByte() 18 18 if err != nil { 19 - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: fmt.Sprintf("read first header byte: %v", err)} 19 + return record, &MalformedPackEntryError{Offset: startOffset, Reason: fmt.Sprintf("read first header byte: %v", err)} 20 20 } 21 21 22 22 record.packedType = objecttype.Type((first >> 4) & 0x07) ··· 28 28 for b&0x80 != 0 { 29 29 b, err = state.stream.ReadByte() 30 30 if err != nil { 31 - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: fmt.Sprintf("read size continuation: %v", err)} 31 + return record, &MalformedPackEntryError{Offset: startOffset, Reason: fmt.Sprintf("read size continuation: %v", err)} 32 32 } 33 33 34 34 headerLen++ ··· 37 37 } 38 38 39 39 if size < 0 { 40 - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: "negative declared size"} 40 + return record, &MalformedPackEntryError{Offset: startOffset, Reason: "negative declared size"} 41 41 } 42 42 43 43 record.declaredSize = size ··· 49 49 50 50 err := state.stream.readFull(baseRaw) 51 51 if err != nil { 52 - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: fmt.Sprintf("read ref base: %v", err)} 52 + return record, &MalformedPackEntryError{Offset: startOffset, Reason: fmt.Sprintf("read ref base: %v", err)} 53 53 } 54 54 55 55 baseID, err := objectid.FromBytes(state.algo, baseRaw) 56 56 if err != nil { 57 - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: fmt.Sprintf("parse ref base: %v", err)} 57 + return record, &MalformedPackEntryError{Offset: startOffset, Reason: fmt.Sprintf("parse ref base: %v", err)} 58 58 } 59 59 60 60 record.baseObject = baseID ··· 68 68 case objecttype.TypeOfsDelta: 69 69 dist, consumed, err := readOfsDistanceFromStream(state.stream) 70 70 if err != nil { 71 - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: err.Error()} 71 + return record, &MalformedPackEntryError{Offset: startOffset, Reason: err.Error()} 72 72 } 73 73 74 74 if startOffset <= dist { 75 - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: "ofs base offset out of bounds"} 75 + return record, &MalformedPackEntryError{Offset: startOffset, Reason: "ofs base offset out of bounds"} 76 76 } 77 77 78 78 record.baseOffset = startOffset - dist ··· 84 84 85 85 headerLen += consumedUint32 86 86 case objecttype.TypeInvalid, objecttype.TypeFuture: 87 - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: fmt.Sprintf("unsupported object type %d", record.packedType)} 87 + return record, &MalformedPackEntryError{Offset: startOffset, Reason: fmt.Sprintf("unsupported object type %d", record.packedType)} 88 88 default: 89 - return record, &ErrMalformedPackEntry{Offset: startOffset, Reason: fmt.Sprintf("unsupported object type %d", record.packedType)} 89 + return record, &MalformedPackEntryError{Offset: startOffset, Reason: fmt.Sprintf("unsupported object type %d", record.packedType)} 90 90 } 91 91 92 92 record.headerLen = headerLen
+20 -20
format/pack/ingest/errors.go
··· 5 5 "fmt" 6 6 ) 7 7 8 - // ErrInvalidPackHeader reports an invalid or unsupported pack header. 9 - type ErrInvalidPackHeader struct { 8 + // InvalidPackHeaderError reports an invalid or unsupported pack header. 9 + type InvalidPackHeaderError struct { 10 10 Reason string 11 11 } 12 12 13 13 // Error implements error. 14 - func (err *ErrInvalidPackHeader) Error() string { 15 - return fmt.Sprintf("format/pack/ingest: invalid pack header: %s", err.Reason) 14 + func (err *InvalidPackHeaderError) Error() string { 15 + return "format/pack/ingest: invalid pack header: " + err.Reason 16 16 } 17 17 18 - // ErrPackTrailerMismatch reports a mismatch between computed and trailer pack hash. 19 - type ErrPackTrailerMismatch struct{} 18 + // PackTrailerMismatchError reports a mismatch between computed and trailer pack hash. 19 + type PackTrailerMismatchError struct{} 20 20 21 21 // Error implements error. 22 - func (err *ErrPackTrailerMismatch) Error() string { 22 + func (err *PackTrailerMismatchError) Error() string { 23 23 return "format/pack/ingest: pack trailer hash mismatch" 24 24 } 25 25 26 - // ErrThinPackUnresolved reports unresolved REF deltas when fixThin is disabled 26 + // ThinPackUnresolvedError reports unresolved REF deltas when fixThin is disabled 27 27 // or when required bases cannot be found in base. 28 - type ErrThinPackUnresolved struct { 28 + type ThinPackUnresolvedError struct { 29 29 Count int 30 30 } 31 31 32 32 // Error implements error. 33 - func (err *ErrThinPackUnresolved) Error() string { 33 + func (err *ThinPackUnresolvedError) Error() string { 34 34 return fmt.Sprintf("format/pack/ingest: unresolved thin deltas: %d", err.Count) 35 35 } 36 36 37 - // ErrMalformedPackEntry reports malformed entry encoding at one pack offset. 38 - type ErrMalformedPackEntry struct { 37 + // MalformedPackEntryError reports malformed entry encoding at one pack offset. 38 + type MalformedPackEntryError struct { 39 39 Offset uint64 40 40 Reason string 41 41 } 42 42 43 43 // Error implements error. 44 - func (err *ErrMalformedPackEntry) Error() string { 44 + func (err *MalformedPackEntryError) Error() string { 45 45 return fmt.Sprintf("format/pack/ingest: malformed pack entry at offset %d: %s", err.Offset, err.Reason) 46 46 } 47 47 48 - // ErrDeltaCycle reports a detected cycle in delta dependency resolution. 49 - type ErrDeltaCycle struct { 48 + // DeltaCycleError reports a detected cycle in delta dependency resolution. 49 + type DeltaCycleError struct { 50 50 Offset uint64 51 51 } 52 52 53 53 // Error implements error. 54 - func (err *ErrDeltaCycle) Error() string { 54 + func (err *DeltaCycleError) Error() string { 55 55 return fmt.Sprintf("format/pack/ingest: delta cycle detected at offset %d", err.Offset) 56 56 } 57 57 58 - // ErrDestinationWrite reports destination I/O failures. 59 - type ErrDestinationWrite struct { 58 + // DestinationWriteError reports destination I/O failures. 59 + type DestinationWriteError struct { 60 60 Op string 61 61 } 62 62 63 63 // Error implements error. 64 - func (err *ErrDestinationWrite) Error() string { 65 - return fmt.Sprintf("format/pack/ingest: destination write failure: %s", err.Op) 64 + func (err *DestinationWriteError) Error() string { 65 + return "format/pack/ingest: destination write failure: " + err.Op 66 66 } 67 67 68 68 var errExternalThinBase = errors.New("format/pack/ingest: external thin base required")
+2 -2
format/pack/ingest/flush.go
··· 18 18 for written < scanner.off { 19 19 n, err := scanner.dstFile.Write(scanner.buf[written:scanner.off]) 20 20 if err != nil { 21 - return &ErrDestinationWrite{Op: fmt.Sprintf("write pack: %v", err)} 21 + return &DestinationWriteError{Op: fmt.Sprintf("write pack: %v", err)} 22 22 } 23 23 24 24 if n == 0 { 25 - return &ErrDestinationWrite{Op: "write pack: short write"} 25 + return &DestinationWriteError{Op: "write pack: short write"} 26 26 } 27 27 28 28 written += n
+4 -4
format/pack/ingest/header.go
··· 13 13 14 14 err := state.stream.readFull(hdr[:]) 15 15 if err != nil { 16 - return &ErrInvalidPackHeader{Reason: fmt.Sprintf("read header: %v", err)} 16 + return &InvalidPackHeaderError{Reason: fmt.Sprintf("read header: %v", err)} 17 17 } 18 18 19 19 if binary.BigEndian.Uint32(hdr[:4]) != pack.Signature { 20 - return &ErrInvalidPackHeader{Reason: "signature mismatch"} 20 + return &InvalidPackHeaderError{Reason: "signature mismatch"} 21 21 } 22 22 23 23 version := binary.BigEndian.Uint32(hdr[4:8]) 24 24 if !pack.VersionSupported(version) { 25 - return &ErrInvalidPackHeader{Reason: fmt.Sprintf("unsupported version %d", version)} 25 + return &InvalidPackHeaderError{Reason: fmt.Sprintf("unsupported version %d", version)} 26 26 } 27 27 28 28 state.objectCountHeader = binary.BigEndian.Uint32(hdr[8:12]) 29 29 if state.objectCountHeader == 0 { 30 - return &ErrInvalidPackHeader{Reason: "zero objects"} 30 + return &InvalidPackHeaderError{Reason: "zero objects"} 31 31 } 32 32 33 33 return nil
+2 -2
format/pack/ingest/ingest.go
··· 39 39 } 40 40 41 41 if len(state.unresolvedRefDeltas) > 0 { 42 - return Result{}, &ErrThinPackUnresolved{Count: len(state.unresolvedRefDeltas)} 42 + return Result{}, &ThinPackUnresolvedError{Count: len(state.unresolvedRefDeltas)} 43 43 } 44 44 45 45 err = verifyResolvedRecords(state) ··· 49 49 50 50 err = state.packFile.Sync() 51 51 if err != nil { 52 - return Result{}, &ErrDestinationWrite{Op: fmt.Sprintf("sync pack: %v", err)} 52 + return Result{}, &DestinationWriteError{Op: fmt.Sprintf("sync pack: %v", err)} 53 53 } 54 54 55 55 err = writeIdx(state)
+4 -4
format/pack/ingest/ingest_test.go
··· 246 246 t.Fatal("Ingest error = nil, want error") 247 247 } 248 248 249 - var unresolved *ingest.ErrThinPackUnresolved 249 + var unresolved *ingest.ThinPackUnresolvedError 250 250 if !errors.As(err, &unresolved) { 251 - t.Fatalf("Ingest error type = %T (%v), want *ErrThinPackUnresolved", err, err) 251 + t.Fatalf("Ingest error type = %T (%v), want *ThinPackUnresolvedError", err, err) 252 252 } 253 253 254 254 matches, err := filepath.Glob(filepath.Join(packDir, "pack-*.pack")) ··· 362 362 t.Fatal("Ingest error = nil, want error") 363 363 } 364 364 365 - var mismatch *ingest.ErrPackTrailerMismatch 365 + var mismatch *ingest.PackTrailerMismatchError 366 366 if !errors.As(err, &mismatch) { 367 - t.Fatalf("Ingest error type = %T (%v), want *ErrPackTrailerMismatch", err, err) 367 + t.Fatalf("Ingest error type = %T (%v), want *PackTrailerMismatchError", err, err) 368 368 } 369 369 370 370 matches, err := filepath.Glob(filepath.Join(packDir, "pack-*.pack"))
+1 -1
format/pack/ingest/record_content.go
··· 20 20 } 21 21 22 22 if int64(len(content)) != record.declaredSize { 23 - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ 23 + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ 24 24 Offset: record.offset, 25 25 Reason: fmt.Sprintf("base content size mismatch got %d want %d", len(content), record.declaredSize), 26 26 }
+5 -5
format/pack/ingest/record_delta.go
··· 20 20 } 21 21 22 22 if int64(len(deltaPayload)) != record.declaredSize { 23 - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ 23 + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ 24 24 Offset: record.offset, 25 25 Reason: fmt.Sprintf("delta payload size mismatch got %d want %d", len(deltaPayload), record.declaredSize), 26 26 } ··· 28 28 29 29 srcSize, dstSize, err := readDeltaHeaderSizes(deltaPayload) 30 30 if err != nil { 31 - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ 31 + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ 32 32 Offset: record.offset, 33 33 Reason: fmt.Sprintf("read delta header: %v", err), 34 34 } 35 35 } 36 36 37 37 if srcSize != len(baseContent) { 38 - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ 38 + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ 39 39 Offset: record.offset, 40 40 Reason: fmt.Sprintf("delta source size mismatch got %d want %d", srcSize, len(baseContent)), 41 41 } ··· 43 43 44 44 content, err := deltaapply.Apply(baseContent, deltaPayload) 45 45 if err != nil { 46 - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ 46 + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ 47 47 Offset: record.offset, 48 48 Reason: fmt.Sprintf("apply delta: %v", err), 49 49 } 50 50 } 51 51 52 52 if len(content) != dstSize { 53 - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ 53 + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ 54 54 Offset: record.offset, 55 55 Reason: fmt.Sprintf("delta result size mismatch got %d want %d", len(content), dstSize), 56 56 }
+3 -3
format/pack/ingest/record_inflate.go
··· 12 12 func inflateRecordPayload(state *ingestState, idx int) ([]byte, error) { 13 13 record := state.records[idx] 14 14 if record.packedLen < uint64(record.headerLen) { 15 - return nil, &ErrMalformedPackEntry{Offset: record.offset, Reason: "entry packed span underflow"} 15 + return nil, &MalformedPackEntryError{Offset: record.offset, Reason: "entry packed span underflow"} 16 16 } 17 17 18 18 compressedOffset := record.offset + uint64(record.headerLen) ··· 32 32 33 33 reader, err := zlib.NewReader(section) 34 34 if err != nil { 35 - return nil, &ErrMalformedPackEntry{Offset: record.offset, Reason: fmt.Sprintf("open payload zlib: %v", err)} 35 + return nil, &MalformedPackEntryError{Offset: record.offset, Reason: fmt.Sprintf("open payload zlib: %v", err)} 36 36 } 37 37 38 38 defer func() { _ = reader.Close() }() 39 39 40 40 out, err := io.ReadAll(reader) 41 41 if err != nil { 42 - return nil, &ErrMalformedPackEntry{Offset: record.offset, Reason: fmt.Sprintf("inflate payload: %v", err)} 42 + return nil, &MalformedPackEntryError{Offset: record.offset, Reason: fmt.Sprintf("inflate payload: %v", err)} 43 43 } 44 44 45 45 return out, nil
+4 -4
format/pack/ingest/record_resolve.go
··· 14 14 } 15 15 16 16 if _, ok := visiting[idx]; ok { 17 - return objecttype.TypeInvalid, nil, &ErrDeltaCycle{Offset: state.records[idx].offset} 17 + return objecttype.TypeInvalid, nil, &DeltaCycleError{Offset: state.records[idx].offset} 18 18 } 19 19 20 20 visiting[idx] = struct{}{} ··· 60 60 case objecttype.TypeOfsDelta: 61 61 baseIdx, ok := state.offsetToRecord[record.baseOffset] 62 62 if !ok { 63 - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ 63 + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ 64 64 Offset: record.offset, 65 65 Reason: "missing ofs-delta base entry", 66 66 } ··· 86 86 objecttype.TypeBlob, 87 87 objecttype.TypeTag, 88 88 objecttype.TypeFuture: 89 - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ 89 + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ 90 90 Offset: record.offset, 91 91 Reason: "unsupported delta type", 92 92 } 93 93 default: 94 - return objecttype.TypeInvalid, nil, &ErrMalformedPackEntry{ 94 + return objecttype.TypeInvalid, nil, &MalformedPackEntryError{ 95 95 Offset: record.offset, 96 96 Reason: "unsupported delta type", 97 97 }
+2 -2
format/pack/ingest/thin_fix.go
··· 13 13 } 14 14 15 15 if !state.fixThin { 16 - return &ErrThinPackUnresolved{Count: len(state.unresolvedRefDeltas)} 16 + return &ThinPackUnresolvedError{Count: len(state.unresolvedRefDeltas)} 17 17 } 18 18 19 19 if state.base == nil { 20 - return &ErrThinPackUnresolved{Count: len(state.unresolvedRefDeltas)} 20 + return &ThinPackUnresolvedError{Count: len(state.unresolvedRefDeltas)} 21 21 } 22 22 23 23 hashSize := int64(state.algo.Size())
+2 -2
format/pack/ingest/trailer.go
··· 20 20 21 21 err := scanner.readFull(trailer) 22 22 if err != nil { 23 - return &ErrPackTrailerMismatch{} 23 + return &PackTrailerMismatchError{} 24 24 } 25 25 26 26 scanner.packTrailer = append(scanner.packTrailer[:0], trailer...) ··· 38 38 39 39 computed := scanner.hash.Sum(nil) 40 40 if !bytes.Equal(computed, trailer) { 41 - return &ErrPackTrailerMismatch{} 41 + return &PackTrailerMismatchError{} 42 42 } 43 43 44 44 return nil
+2 -5
format/pktline/errors.go
··· 1 1 package pktline 2 2 3 - import ( 4 - "errors" 5 - "fmt" 6 - ) 3 + import "errors" 7 4 8 5 var ( 9 6 // ErrInvalidLength indicates a malformed 4-byte hexadecimal length header. ··· 30 27 return "pktline: protocol error" 31 28 } 32 29 33 - return fmt.Sprintf("pktline: protocol error: %s", e.Reason) 30 + return "pktline: protocol error: " + e.Reason 34 31 }
+2 -5
format/sideband64k/errors.go
··· 1 1 package sideband64k 2 2 3 - import ( 4 - "errors" 5 - "fmt" 6 - ) 3 + import "errors" 7 4 8 5 var ( 9 6 // ErrTooLarge indicates a payload exceeds configured sideband data limits. ··· 26 23 return "sideband64k: protocol error" 27 24 } 28 25 29 - return fmt.Sprintf("sideband64k: protocol error: %s", e.Reason) 26 + return "sideband64k: protocol error: " + e.Reason 30 27 }
+1
internal/adler32/adler32_amd64.go
··· 14 14 // Size of an Adler-32 checksum in bytes. 15 15 const Size = 4 16 16 17 + //nolint:gochecknoglobals 17 18 var hasAVX2 = cpu.X86.HasAVX2 18 19 19 20 // digest represents the partial evaluation of a checksum.
+1
internal/adler32/bench_test.go
··· 8 8 9 9 const benchmarkSize = 64 * 1024 10 10 11 + //nolint:gochecknoglobals 11 12 var data = make([]byte, benchmarkSize) 12 13 13 14 func init() { //nolint:gochecknoinits
+1
internal/bufpool/class.go
··· 1 1 package bufpool 2 2 3 + //nolint:gochecknoglobals 3 4 var sizeClasses = [...]int{ 4 5 DefaultBufferCap, 5 6 64 << 10,
+1
internal/bufpool/pool.go
··· 2 2 3 3 import "sync" 4 4 5 + //nolint:gochecknoglobals 5 6 var bufferPools = func() []sync.Pool { 6 7 pools := make([]sync.Pool, len(sizeClasses)) 7 8 for i, classCap := range sizeClasses {
+1
internal/compress/zlib/reader.go
··· 58 58 ErrHeader = errors.New("zlib: invalid header") 59 59 ) 60 60 61 + //nolint:gochecknoglobals 61 62 var readerPool = sync.Pool{ 62 63 New: func() any { 63 64 r := new(Reader)
+1
internal/compress/zlib/reader_test.go
··· 24 24 // Compare-to-golden test data was generated by the ZLIB example program at 25 25 // https://www.zlib.net/zpipe.c 26 26 27 + //nolint:gochecknoglobals 27 28 var zlibTests = []zlibTest{ 28 29 { 29 30 "truncated empty",
+1
internal/compress/zlib/writer.go
··· 37 37 wroteHeader bool 38 38 } 39 39 40 + //nolint:gochecknoglobals 40 41 var writerPool = sync.Pool{ 41 42 New: func() any { 42 43 return new(Writer)
+2
internal/compress/zlib/writer_test.go
··· 15 15 "codeberg.org/lindenii/furgit/internal/compress/zlib" 16 16 ) 17 17 18 + //nolint:gochecknoglobals 18 19 var filenames = []string{ 19 20 "../testdata/gettysburg.txt", 20 21 "../testdata/e.txt", 21 22 "../testdata/pi.txt", 22 23 } 23 24 25 + //nolint:gochecknoglobals 24 26 var data = []string{ 25 27 "test a reasonable sized string that can be compressed", 26 28 }
+2
internal/lru/get.go
··· 1 1 package lru 2 2 3 3 // Get returns value for key and marks it most-recently-used. 4 + // 5 + //nolint:ireturn 4 6 func (cache *Cache[K, V]) Get(key K) (V, bool) { 5 7 elem, ok := cache.items[key] 6 8 if !ok {
+2
internal/lru/peek.go
··· 1 1 package lru 2 2 3 3 // Peek returns value for key without changing recency. 4 + // 5 + //nolint:ireturn 4 6 func (cache *Cache[K, V]) Peek(key K) (V, bool) { 5 7 elem, ok := cache.items[key] 6 8 if !ok {
+2
internal/lru/remove.go
··· 3 3 import "container/list" 4 4 5 5 // Remove deletes key from the cache. 6 + // 7 + //nolint:ireturn 6 8 func (cache *Cache[K, V]) Remove(key K) (V, bool) { 7 9 elem, ok := cache.items[key] 8 10 if !ok {
+1 -2
internal/testgit/repo_tag_annotated.go
··· 1 1 package testgit 2 2 3 3 import ( 4 - "fmt" 5 4 "testing" 6 5 7 6 "codeberg.org/lindenii/furgit/objectid" ··· 12 11 tb.Helper() 13 12 testRepo.Run(tb, "tag", "-a", name, target.String(), "-m", message) 14 13 15 - return testRepo.RevParse(tb, fmt.Sprintf("refs/tags/%s", name)) 14 + return testRepo.RevParse(tb, "refs/tags/"+name) 16 15 }
+19 -15
object/parse.go
··· 8 8 "codeberg.org/lindenii/furgit/objecttype" 9 9 ) 10 10 11 + // ParseObjectWithHeader parses a loose object in "type size\x00body" format. 12 + // 13 + //nolint:ireturn 14 + func ParseObjectWithHeader(raw []byte, algo objectid.Algorithm) (Object, error) { 15 + ty, size, headerLen, ok := objectheader.Parse(raw) 16 + if !ok { 17 + return nil, fmt.Errorf("object: malformed object header") 18 + } 19 + 20 + body := raw[headerLen:] 21 + if int64(len(body)) != size { 22 + return nil, fmt.Errorf("object: size mismatch: header says %d bytes, body has %d", size, len(body)) 23 + } 24 + 25 + return ParseObjectWithoutHeader(ty, body, algo) 26 + } 27 + 11 28 // ParseObjectWithoutHeader parses a typed object body. 29 + // 30 + //nolint:ireturn 12 31 func ParseObjectWithoutHeader(ty objecttype.Type, body []byte, algo objectid.Algorithm) (Object, error) { 13 32 switch ty { 14 33 case objecttype.TypeBlob: ··· 25 44 return nil, fmt.Errorf("object: unsupported object type %d", ty) 26 45 } 27 46 } 28 - 29 - // ParseObjectWithHeader parses a loose object in "type size\\x00body" format. 30 - func ParseObjectWithHeader(raw []byte, algo objectid.Algorithm) (Object, error) { 31 - ty, size, headerLen, ok := objectheader.Parse(raw) 32 - if !ok { 33 - return nil, fmt.Errorf("object: malformed object header") 34 - } 35 - 36 - body := raw[headerLen:] 37 - if int64(len(body)) != size { 38 - return nil, fmt.Errorf("object: size mismatch: header says %d bytes, body has %d", size, len(body)) 39 - } 40 - 41 - return ParseObjectWithoutHeader(ty, body, algo) 42 - }
+4 -1
objectid/algorithms.go
··· 26 26 new func() hash.Hash 27 27 } 28 28 29 + //nolint:gochecknoglobals 29 30 var algorithmTable = [...]algorithmDetails{ 30 31 AlgorithmUnknown: {}, 31 32 AlgorithmSHA1: { ··· 61 62 } 62 63 63 64 var ( 64 - algorithmByName = map[string]Algorithm{} 65 + //nolint:gochecknoglobals 66 + algorithmByName = map[string]Algorithm{} 67 + //nolint:gochecknoglobals 65 68 supportedAlgorithms []Algorithm 66 69 ) 67 70
+2
objectstore/mix/mru.go
··· 8 8 next *backendNode 9 9 } 10 10 11 + //nolint:ireturn 11 12 func (mix *Mix) firstBackend() objectstore.Store { 12 13 mix.mu.RLock() 13 14 defer mix.mu.RUnlock() ··· 19 20 return mix.backendHead.backend 20 21 } 21 22 23 + //nolint:ireturn 22 24 func (mix *Mix) nextBackend(current objectstore.Store) objectstore.Store { 23 25 mix.mu.RLock() 24 26 defer mix.mu.RUnlock()
+2
objectstored/blob.go
··· 25 25 } 26 26 27 27 // Object returns the parsed blob as the generic object interface. 28 + // 29 + //nolint:ireturn 28 30 func (stored *StoredBlob) Object() object.Object { 29 31 return stored.blob 30 32 }
+2
objectstored/commit.go
··· 22 22 } 23 23 24 24 // Object returns the parsed commit as the generic object interface. 25 + // 26 + //nolint:ireturn 25 27 func (stored *StoredCommit) Object() object.Object { 26 28 return stored.commit 27 29 }
+2
objectstored/objectstored.go
··· 22 22 } 23 23 24 24 // Object returns the parsed tag as the generic object interface. 25 + // 26 + //nolint:ireturn 25 27 func (stored *StoredTag) Object() object.Object { 26 28 return stored.tag 27 29 }
+2
objectstored/tree.go
··· 22 22 } 23 23 24 24 // Object returns the parsed tree as the generic object interface. 25 + // 26 + //nolint:ireturn 25 27 func (stored *StoredTree) Object() object.Object { 26 28 return stored.tree 27 29 }
+2 -2
reachability/ancestor.go
··· 57 57 58 58 ancestorPos, err := r.graph.Lookup(ancestor) 59 59 if err != nil { 60 - var notFound *commitgraphread.ErrNotFound 60 + var notFound *commitgraphread.NotFoundError 61 61 if errors.As(err, &notFound) { 62 62 return false, false, nil 63 63 } ··· 67 67 68 68 descendantPos, err := r.graph.Lookup(descendant) 69 69 if err != nil { 70 - var notFound *commitgraphread.ErrNotFound 70 + var notFound *commitgraphread.NotFoundError 71 71 if errors.As(err, &notFound) { 72 72 return false, false, nil 73 73 }
+6 -6
reachability/errors.go
··· 7 7 "codeberg.org/lindenii/furgit/objecttype" 8 8 ) 9 9 10 - // ErrObjectMissing indicates that a referenced object is absent from the store. 11 - type ErrObjectMissing struct { 10 + // ObjectMissingError indicates that a referenced object is absent from the store. 11 + type ObjectMissingError struct { 12 12 OID objectid.ObjectID 13 13 } 14 14 15 - func (e *ErrObjectMissing) Error() string { 15 + func (e *ObjectMissingError) Error() string { 16 16 return fmt.Sprintf("reachability: missing object %s", e.OID) 17 17 } 18 18 19 - // ErrObjectType indicates that a referenced object has a different type than 19 + // ObjectTypeError indicates that a referenced object has a different type than 20 20 // what traversal expected on that edge. 21 - type ErrObjectType struct { 21 + type ObjectTypeError struct { 22 22 OID objectid.ObjectID 23 23 Got objecttype.Type 24 24 Want objecttype.Type 25 25 } 26 26 27 - func (e *ErrObjectType) Error() string { 27 + func (e *ObjectTypeError) Error() string { 28 28 gotName, gotOK := objecttype.Name(e.Got) 29 29 if !gotOK { 30 30 gotName = fmt.Sprintf("type(%d)", e.Got)
+2 -2
reachability/helpers.go
··· 39 39 ty, _, err := r.store.ReadHeader(id) 40 40 if err != nil { 41 41 if errors.Is(err, objectstore.ErrObjectNotFound) { 42 - return objecttype.TypeInvalid, &ErrObjectMissing{OID: id} 42 + return objecttype.TypeInvalid, &ObjectMissingError{OID: id} 43 43 } 44 44 45 45 return objecttype.TypeInvalid, err ··· 61 61 _, content, err := r.store.ReadBytesContent(id) 62 62 if err != nil { 63 63 if errors.Is(err, objectstore.ErrObjectNotFound) { 64 - return nil, &ErrObjectMissing{OID: id} 64 + return nil, &ObjectMissingError{OID: id} 65 65 } 66 66 67 67 return nil, err
+2 -2
reachability/integration_test.go
··· 236 236 t.Fatal("expected error") 237 237 } 238 238 239 - var missing *reachability.ErrObjectMissing 239 + var missing *reachability.ObjectMissingError 240 240 if !errors.As(err, &missing) { 241 - t.Fatalf("expected ErrObjectMissing, got %T (%v)", err, err) 241 + t.Fatalf("expected ObjectMissingError, got %T (%v)", err, err) 242 242 } 243 243 244 244 if missing.OID != treeID {
+1 -1
reachability/peel.go
··· 20 20 21 21 if ty != objecttype.TypeTag { 22 22 if domain == DomainCommits && ty != objecttype.TypeCommit { 23 - return objectid.ObjectID{}, &ErrObjectType{OID: id, Got: ty, Want: objecttype.TypeCommit} 23 + return objectid.ObjectID{}, &ObjectTypeError{OID: id, Got: ty, Want: objecttype.TypeCommit} 24 24 } 25 25 26 26 return id, nil
+6 -6
reachability/unit_test.go
··· 233 233 t.Fatal("expected error") 234 234 } 235 235 236 - var typeErr *reachability.ErrObjectType 236 + var typeErr *reachability.ObjectTypeError 237 237 if !errors.As(err, &typeErr) { 238 - t.Fatalf("expected ErrObjectType, got %T (%v)", err, err) 238 + t.Fatalf("expected ObjectTypeError, got %T (%v)", err, err) 239 239 } 240 240 241 241 if typeErr.Got != objecttype.TypeTree || typeErr.Want != objecttype.TypeCommit { ··· 349 349 t.Fatal("expected error") 350 350 } 351 351 352 - var missing *reachability.ErrObjectMissing 352 + var missing *reachability.ObjectMissingError 353 353 if !errors.As(err, &missing) { 354 - t.Fatalf("expected ErrObjectMissing, got %T (%v)", err, err) 354 + t.Fatalf("expected ObjectMissingError, got %T (%v)", err, err) 355 355 } 356 356 357 357 if missing.OID != missingParent { ··· 441 441 t.Fatal("expected error") 442 442 } 443 443 444 - var typeErr *reachability.ErrObjectType 444 + var typeErr *reachability.ObjectTypeError 445 445 if !errors.As(err, &typeErr) { 446 - t.Fatalf("expected ErrObjectType, got %T (%v)", err, err) 446 + t.Fatalf("expected ObjectTypeError, got %T (%v)", err, err) 447 447 } 448 448 }) 449 449 }
+1 -1
reachability/walk_expand_commits.go
··· 63 63 return []walkItem{{id: tag.Target, want: objecttype.TypeInvalid}}, nil 64 64 case objecttype.TypeTree, objecttype.TypeBlob, objecttype.TypeInvalid, 65 65 objecttype.TypeFuture, objecttype.TypeOfsDelta, objecttype.TypeRefDelta: 66 - return nil, &ErrObjectType{OID: item.id, Got: ty, Want: objecttype.TypeCommit} 66 + return nil, &ObjectTypeError{OID: item.id, Got: ty, Want: objecttype.TypeCommit} 67 67 } 68 68 69 69 return nil, fmt.Errorf("reachability: unreachable object type %d", ty)
+1 -1
reachability/walk_expand_commits_graph.go
··· 11 11 func (walk *Walk) expandCommitsFromGraph(id objectid.ObjectID) ([]walkItem, bool, error) { 12 12 pos, err := walk.reachability.graph.Lookup(id) 13 13 if err != nil { 14 - var notFound *commitgraphread.ErrNotFound 14 + var notFound *commitgraphread.NotFoundError 15 15 if errors.As(err, &notFound) { 16 16 return nil, false, nil 17 17 }
+2 -2
reachability/walk_expand_objects.go
··· 14 14 } 15 15 16 16 if item.want != objecttype.TypeInvalid && ty != item.want { 17 - return nil, &ErrObjectType{OID: item.id, Got: ty, Want: item.want} 17 + return nil, &ObjectTypeError{OID: item.id, Got: ty, Want: item.want} 18 18 } 19 19 20 20 switch ty { ··· 76 76 77 77 return []walkItem{{id: tag.Target, want: tag.TargetType}}, nil 78 78 case objecttype.TypeInvalid, objecttype.TypeFuture, objecttype.TypeOfsDelta, objecttype.TypeRefDelta: 79 - return nil, &ErrObjectType{OID: item.id, Got: ty, Want: item.want} 79 + return nil, &ObjectTypeError{OID: item.id, Got: ty, Want: item.want} 80 80 } 81 81 82 82 return nil, fmt.Errorf("reachability: unreachable object type %d", ty)
+1 -1
reachability/walk_verify.go
··· 13 13 } 14 14 15 15 if ty != objecttype.TypeCommit { 16 - return &ErrObjectType{OID: id, Got: ty, Want: objecttype.TypeCommit} 16 + return &ObjectTypeError{OID: id, Got: ty, Want: objecttype.TypeCommit} 17 17 } 18 18 19 19 content, err := walk.readBytesContent(id)
+2
refstore/chain/resolve.go
··· 9 9 ) 10 10 11 11 // Resolve resolves a reference from the first backend that has it. 12 + // 13 + //nolint:ireturn 12 14 func (chain *Chain) Resolve(name string) (ref.Ref, error) { 13 15 for i, backend := range chain.backends { 14 16 if backend == nil {
+4
refstore/loose/resolve.go
··· 12 12 ) 13 13 14 14 // Resolve resolves a loose reference name to symbolic or detached form. 15 + // 16 + //nolint:ireturn 15 17 func (store *Store) Resolve(name string) (ref.Ref, error) { 16 18 if name == "" { 17 19 return nil, refstore.ErrReferenceNotFound ··· 63 65 } 64 66 65 67 // resolveOne resolves one loose ref file without symbolic recursion. 68 + // 69 + //nolint:ireturn 66 70 func (store *Store) resolveOne(name string) (ref.Ref, error) { 67 71 data, err := store.root.ReadFile(name) 68 72 if err != nil {
+2
refstore/packed/resolve.go
··· 6 6 ) 7 7 8 8 // Resolve resolves a packed reference name to a detached ref. 9 + // 10 + //nolint:ireturn 9 11 func (store *Store) Resolve(name string) (ref.Ref, error) { 10 12 detached, ok := store.byName[name] 11 13 if !ok {
+1
refstore/shorten.go
··· 7 7 suffix string 8 8 } 9 9 10 + //nolint:gochecknoglobals 10 11 var shortenRules = [...]shortenRule{ 11 12 {prefix: "", suffix: ""}, 12 13 {prefix: "refs/", suffix: ""},
+3
repository/objects.go
··· 12 12 objectpacked "codeberg.org/lindenii/furgit/objectstore/packed" 13 13 ) 14 14 15 + //nolint:ireturn 15 16 func openObjectStore(root *os.Root, algo objectid.Algorithm) (objectstore.Store, *objectloose.Store, error) { 16 17 objectsRoot, err := root.OpenRoot("objects") 17 18 if err != nil { ··· 64 65 } 65 66 66 67 // Objects returns the configured object store. 68 + // 69 + //nolint:ireturn 67 70 func (repo *Repository) Objects() objectstore.Store { 68 71 return repo.objects 69 72 }
+3
repository/refs.go
··· 12 12 refpacked "codeberg.org/lindenii/furgit/refstore/packed" 13 13 ) 14 14 15 + //nolint:ireturn 15 16 func openRefStore(root *os.Root, algo objectid.Algorithm) (out refstore.Store, err error) { 16 17 looseRoot, err := root.OpenRoot(".") 17 18 if err != nil { ··· 47 48 } 48 49 49 50 // Refs returns the configured ref store. 51 + // 52 + //nolint:ireturn 50 53 func (repo *Repository) Refs() refstore.Store { 51 54 return repo.refs 52 55 }
+4
repository/stored.go
··· 10 10 ) 11 11 12 12 // ReadStored reads, parses, and wraps one object by ID. 13 + // 14 + //nolint:ireturn 13 15 func (repo *Repository) ReadStored(id objectid.ObjectID) (objectstored.StoredObject, error) { 14 16 parsed, err := repo.readParsedObject(id) 15 17 if err != nil { ··· 91 93 } 92 94 93 95 // readParsedObject reads bytes content from storage and parses one object. 96 + // 97 + //nolint:ireturn 94 98 func (repo *Repository) readParsedObject(id objectid.ObjectID) (object.Object, error) { 95 99 ty, content, err := repo.objects.ReadBytesContent(id) 96 100 if err != nil {