Skip to content

Commit 7de0354

Browse files
committed
agh 40byte not 20byte sha
Signed-off-by: Andrew Thornton <[email protected]>
1 parent 44e6741 commit 7de0354

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

modules/git/batch_reader.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func CatFileBatch(repoPath string) (WriteCloserError, *bufio.Reader, func()) {
8282
// ReadBatchLine reads the header line from cat-file --batch
8383
// We expect:
8484
// <sha> SP <type> SP <size> LF
85+
// sha is a 40byte not 20byte here
8586
func ReadBatchLine(rd *bufio.Reader) (sha []byte, typ string, size int64, err error) {
8687
sha, err = rd.ReadBytes(' ')
8788
if err != nil {

modules/git/repo_commit_nogogit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (repo *Repository) getCommit(id SHA1) (*Commit, error) {
118118

119119
// ConvertToSHA1 returns a Hash object from a potential ID string
120120
func (repo *Repository) ConvertToSHA1(commitID string) (SHA1, error) {
121-
if len(commitID) == 40 {
121+
if len(commitID) == 40 && SHAPattern.MatchString(commitID) {
122122
sha1, err := NewIDFromString(commitID)
123123
if err == nil {
124124
return sha1, nil
@@ -139,5 +139,5 @@ func (repo *Repository) ConvertToSHA1(commitID string) (SHA1, error) {
139139
return SHA1{}, err
140140
}
141141

142-
return MustID(sha), nil
142+
return MustIDFromString(string(sha)), nil
143143
}

0 commit comments

Comments
 (0)