diff options
| -rw-r--r-- | hash_test.go | 4 | ||||
| -rw-r--r-- | loose.go | 4 | ||||
| -rw-r--r-- | obj_tree.go | 8 | ||||
| -rw-r--r-- | objects_test.go | 2 | ||||
| -rw-r--r-- | pack_idx.go | 10 | ||||
| -rw-r--r-- | pack_midx.go | 8 | ||||
| -rw-r--r-- | pack_pack.go | 8 | ||||
| -rw-r--r-- | pack_test.go | 2 | ||||
| -rw-r--r-- | refs.go | 2 | ||||
| -rw-r--r-- | repo.go | 14 | ||||
| -rw-r--r-- | repo_test.go | 4 |
11 files changed, 33 insertions, 33 deletions
diff --git a/hash_test.go b/hash_test.go index 89e66fd1..212e5ef2 100644 --- a/hash_test.go +++ b/hash_test.go @@ -9,8 +9,8 @@ func TestParseHashValidAndInvalid(t *testing.T) { pattern := "0123456789abcdef" repeats := (testHashSize*2 + len(pattern) - 1) / len(pattern) hexStr := strings.Repeat(pattern, repeats)[:testHashSize*2] - - repo := &Repository{HashSize: testHashSize} + + repo := &Repository{hashSize: testHashSize} id, err := repo.ParseHash(hexStr) if err != nil { t.Fatalf("ParseHash returned error: %v", err) @@ -14,8 +14,8 @@ const looseHeaderLimit = 4096 // loosePath returns the path for a loose object, validating hash size. func (repo *Repository) loosePath(id Hash) (string, error) { - if id.size != repo.HashSize { - return "", fmt.Errorf("furgit: hash size mismatch: got %d, expected %d", id.size, repo.HashSize) + if id.size != repo.hashSize { + return "", fmt.Errorf("furgit: hash size mismatch: got %d, expected %d", id.size, repo.hashSize) } hex := id.String() return filepath.Join("objects", hex[:2], hex[2:]), nil diff --git a/obj_tree.go b/obj_tree.go index 2ebe8af7..8ba1e26f 100644 --- a/obj_tree.go +++ b/obj_tree.go @@ -45,13 +45,13 @@ func parseTree(id Hash, body []byte, repo *Repository) (*Tree, error) { nameBytes := body[i : i+nul] i += nul + 1 - if i+repo.HashSize > len(body) { + if i+repo.hashSize > len(body) { return nil, errors.New("furgit: tree: truncated child hash") } var child Hash - copy(child.data[:], body[i:i+repo.HashSize]) - child.size = repo.HashSize - i += repo.HashSize + copy(child.data[:], body[i:i+repo.hashSize]) + child.size = repo.hashSize + i += repo.hashSize mode, err := strconv.ParseUint(string(modeBytes), 8, 32) if err != nil { diff --git a/objects_test.go b/objects_test.go index e9e21ac0..8836515c 100644 --- a/objects_test.go +++ b/objects_test.go @@ -10,7 +10,7 @@ import ( func testRepo(t *testing.T) *Repository { t.Helper() - return &Repository{HashSize: testHashSize} + return &Repository{hashSize: testHashSize} } func mustHash(t *testing.T, hex string) Hash { diff --git a/pack_idx.go b/pack_idx.go index 7547777d..03397286 100644 --- a/pack_idx.go +++ b/pack_idx.go @@ -163,7 +163,7 @@ func (pi *packIndex) parse(buf []byte) error { nobj := int(readBE32(pi.fanout[len(pi.fanout)-4:])) namesStart := fanoutEnd - namesEnd := namesStart + nobj*pi.repo.HashSize + namesEnd := namesStart + nobj*pi.repo.hashSize if namesEnd > len(buf) { return ErrInvalidObject } @@ -183,7 +183,7 @@ func (pi *packIndex) parse(buf []byte) error { pi.offset32 = buf[off32Start:off32End] off64Start := off32End - trailerStart := len(buf) - 2*pi.repo.HashSize + trailerStart := len(buf) - 2*pi.repo.hashSize if trailerStart < off64Start { return ErrInvalidObject } @@ -245,8 +245,8 @@ func (pi *packIndex) lookup(id Hash) (packlocation, error) { return packlocation{}, err } // Verify hash size matches repository hash size - if id.size != pi.repo.HashSize { - return packlocation{}, fmt.Errorf("furgit: hash size mismatch: got %d, expected %d", id.size, pi.repo.HashSize) + if id.size != pi.repo.hashSize { + return packlocation{}, fmt.Errorf("furgit: hash size mismatch: got %d, expected %d", id.size, pi.repo.hashSize) } first := int(id.data[0]) var lo int @@ -254,7 +254,7 @@ func (pi *packIndex) lookup(id Hash) (packlocation, error) { lo = int(pi.fanoutEntry(first - 1)) } hi := int(pi.fanoutEntry(first)) - idx, found := bsearchHash(pi.names, pi.repo.HashSize, lo, hi, id) + idx, found := bsearchHash(pi.names, pi.repo.hashSize, lo, hi, id) if !found { return packlocation{}, ErrNotFound } diff --git a/pack_midx.go b/pack_midx.go index 0c4f3213..ec6cb924 100644 --- a/pack_midx.go +++ b/pack_midx.go @@ -198,7 +198,7 @@ func (midx *multiPackIndex) parse(buf []byte) error { if !ok { return ErrInvalidObject } - oidlSize := int64(numObjects) * int64(midx.repo.HashSize) + oidlSize := int64(numObjects) * int64(midx.repo.hashSize) if oidlOffset < 0 || oidlOffset+oidlSize > int64(len(buf)) { return ErrInvalidObject } @@ -247,8 +247,8 @@ func (midx *multiPackIndex) lookup(id Hash) (packlocation, error) { } // Verify hash size matches repository hash size - if id.size != midx.repo.HashSize { - return packlocation{}, fmt.Errorf("furgit: hash size mismatch: got %d, expected %d", id.size, midx.repo.HashSize) + if id.size != midx.repo.hashSize { + return packlocation{}, fmt.Errorf("furgit: hash size mismatch: got %d, expected %d", id.size, midx.repo.hashSize) } first := int(id.data[0]) @@ -258,7 +258,7 @@ func (midx *multiPackIndex) lookup(id Hash) (packlocation, error) { } hi := int(readBE32(midx.fanout[first*4 : (first+1)*4])) - idx, found := bsearchHash(midx.oids, midx.repo.HashSize, lo, hi, id) + idx, found := bsearchHash(midx.oids, midx.repo.hashSize, lo, hi, id) if !found { return packlocation{}, ErrNotFound } diff --git a/pack_pack.go b/pack_pack.go index 54a48521..3ab935cd 100644 --- a/pack_pack.go +++ b/pack_pack.go @@ -269,11 +269,11 @@ func (repo *Repository) packTypeSizeWithin(pf *packFile, ofs uint64, seen map[pa return ty, declaredSize, nil case ObjRefDelta: var base Hash - _, err := io.ReadFull(r, base.data[:repo.HashSize]) + _, err := io.ReadFull(r, base.data[:repo.hashSize]) if err != nil { return ObjInvalid, 0, err } - base.size = repo.HashSize + base.size = repo.hashSize baseTy, _, err := repo.packTypeSizeByID(base, seen) if err != nil { return ObjInvalid, 0, err @@ -316,11 +316,11 @@ func (repo *Repository) packBodyResolveWithin(pf *packFile, ofs uint64) (ObjectT return ty, body, err case ObjRefDelta: var base Hash - _, err := io.ReadFull(r, base.data[:repo.HashSize]) + _, err := io.ReadFull(r, base.data[:repo.hashSize]) if err != nil { return ObjInvalid, borrowedBody{}, err } - base.size = repo.HashSize + base.size = repo.hashSize delta, err := packSectionInflate(r, 0) if err != nil { return ObjInvalid, borrowedBody{}, err diff --git a/pack_test.go b/pack_test.go index e9aac281..c2a3c573 100644 --- a/pack_test.go +++ b/pack_test.go @@ -190,7 +190,7 @@ func buildTestPackIndexBuffer(hash Hash, offset uint32) []byte { func TestPackIndexParse(t *testing.T) { h := hashWithByte(0x11) data := buildTestPackIndexBuffer(h, 0x12345678) - pi := &packIndex{repo: &Repository{HashSize: testHashSize}} + pi := &packIndex{repo: &Repository{hashSize: testHashSize}} if err := pi.parse(data); err != nil { t.Fatalf("parse error: %v", err) } @@ -55,7 +55,7 @@ func (repo *Repository) resolvePackedRef(refname string) (Hash, error) { continue } sp := bytes.IndexByte(line, ' ') - if sp != repo.HashSize*2 { + if sp != repo.hashSize*2 { continue } name := line[sp+1:] @@ -13,7 +13,7 @@ import ( // Repository represents the root of a Git repository. type Repository struct { rootPath string - HashSize int + hashSize int packIdxOnce sync.Once packIdx []*packIndex @@ -72,7 +72,7 @@ func OpenRepository(path string) (*Repository, error) { return nil, fmt.Errorf("furgit: hash algorithm %q is not supported by the hash functions provided by this build", algo) } - return &Repository{rootPath: path, HashSize: hashSize}, nil + return &Repository{rootPath: path, hashSize: hashSize}, nil } func (repo *Repository) Close() error { @@ -133,9 +133,9 @@ func (repo *Repository) ParseHash(s string) (Hash, error) { if len(s)%2 != 0 { return id, fmt.Errorf("furgit: invalid hash length %d, it has to be even at the very least", len(s)) } - expectedLen := repo.HashSize * 2 + expectedLen := repo.hashSize * 2 if len(s) != expectedLen { - return id, fmt.Errorf("furgit: hash length mismatch: got %d chars, expected %d for hash size %d", len(s), expectedLen, repo.HashSize) + return id, fmt.Errorf("furgit: hash length mismatch: got %d chars, expected %d for hash size %d", len(s), expectedLen, repo.hashSize) } data, err := hex.DecodeString(s) if err != nil { @@ -148,13 +148,13 @@ func (repo *Repository) ParseHash(s string) (Hash, error) { // computeRawHash computes a hash from raw data using the repository's hash algorithm. func (repo *Repository) computeRawHash(data []byte) Hash { - hashFunc := hashFuncs[repo.HashSize] + hashFunc := hashFuncs[repo.hashSize] return hashFunc(data) } // verifyRawObject verifies a raw object against its expected hash. func (repo *Repository) verifyRawObject(buf []byte, want Hash) bool { - if want.size != repo.HashSize { + if want.size != repo.hashSize { return false } return repo.computeRawHash(buf) == want @@ -162,7 +162,7 @@ func (repo *Repository) verifyRawObject(buf []byte, want Hash) bool { // verifyTypedObject verifies a typed object against its expected hash. func (repo *Repository) verifyTypedObject(ty ObjectType, body []byte, want Hash) bool { - if want.size != repo.HashSize { + if want.size != repo.hashSize { return false } header, err := headerForType(ty, body) diff --git a/repo_test.go b/repo_test.go index b0d98db0..c8eab26e 100644 --- a/repo_test.go +++ b/repo_test.go @@ -329,7 +329,7 @@ type testPackObject struct { func writeTestPack(t *testing.T, root, name string, objs []testPackObject) []Hash { t.Helper() - repo := &Repository{HashSize: testHashSize} + repo := &Repository{hashSize: testHashSize} packDir := filepath.Join(root, "objects", "pack") err := os.MkdirAll(packDir, 0o750) if err != nil { @@ -418,7 +418,7 @@ func writeTestPack(t *testing.T, root, name string, objs []testPackObject) []Has func writeTestPackIndex(t *testing.T, packDir, name string, ids []Hash, offsets []uint64, packChecksum Hash) { t.Helper() - repo := &Repository{HashSize: testHashSize} + repo := &Repository{hashSize: testHashSize} type idxEntry struct { id Hash offset uint64 |
