@@ -14,10 +14,11 @@ import (
1414// runCatFileBatch uses 'git cat-file --batch' to get the object contents of a
1515// git object, given its sha1. The contents will be decoded into a Git LFS
1616// pointer. Git Blob SHA1s are read from the sha1Ch channel and fed to STDIN.
17- // Results are parsed from STDOUT, and any elegible LFS pointers are sent to
18- // pointerCh. Any errors are sent to errCh. An error is returned if the 'git
19- // cat-file' command fails to start.
20- func runCatFileBatch (pointerCh chan * WrappedPointer , revs * StringChannelWrapper , errCh chan error ) error {
17+ // Results are parsed from STDOUT, and any eligible LFS pointers are sent to
18+ // pointerCh. If a Git Blob is not an LFS pointer, check the lockableSet to see
19+ // if that blob is for a locked file. Any errors are sent to errCh. An error is
20+ // returned if the 'git cat-file' command fails to start.
21+ func runCatFileBatch (pointerCh chan * WrappedPointer , lockableCh chan string , lockableSet * lockableNameSet , revs * StringChannelWrapper , errCh chan error ) error {
2122 cmd , err := startCommand ("git" , "cat-file" , "--batch" )
2223 if err != nil {
2324 return err
@@ -28,12 +29,15 @@ func runCatFileBatch(pointerCh chan *WrappedPointer, revs *StringChannelWrapper,
2829 for r := range revs .Results {
2930 cmd .Stdin .Write ([]byte (r + "\n " ))
3031 canScan := scanner .Scan ()
31- if p := scanner .Pointer (); p != nil {
32- pointerCh <- p
33- }
3432
3533 if err := scanner .Err (); err != nil {
3634 errCh <- err
35+ } else if p := scanner .Pointer (); p != nil {
36+ pointerCh <- p
37+ } else if b := scanner .BlobSHA (); len (b ) == 40 {
38+ if name , ok := lockableSet .Check (b ); ok {
39+ lockableCh <- name
40+ }
3741 }
3842
3943 if ! canScan {
@@ -55,17 +59,23 @@ func runCatFileBatch(pointerCh chan *WrappedPointer, revs *StringChannelWrapper,
5559
5660 close (pointerCh )
5761 close (errCh )
62+ close (lockableCh )
5863 }()
5964
6065 return nil
6166}
6267
6368type catFileBatchScanner struct {
6469 r * bufio.Reader
70+ blobSha string
6571 pointer * WrappedPointer
6672 err error
6773}
6874
75+ func (s * catFileBatchScanner ) BlobSHA () string {
76+ return s .blobSha
77+ }
78+
6979func (s * catFileBatchScanner ) Pointer () * WrappedPointer {
7080 return s .pointer
7181}
@@ -76,7 +86,8 @@ func (s *catFileBatchScanner) Err() error {
7686
7787func (s * catFileBatchScanner ) Scan () bool {
7888 s .pointer , s .err = nil , nil
79- p , err := s .next ()
89+ b , p , err := s .next ()
90+ s .blobSha = b
8091 s .pointer = p
8192
8293 if err != nil {
@@ -89,39 +100,40 @@ func (s *catFileBatchScanner) Scan() bool {
89100 return true
90101}
91102
92- func (s * catFileBatchScanner ) next () (* WrappedPointer , error ) {
103+ func (s * catFileBatchScanner ) next () (string , * WrappedPointer , error ) {
93104 l , err := s .r .ReadBytes ('\n' )
94105 if err != nil {
95- return nil , err
106+ return "" , nil , err
96107 }
97108
98109 // Line is formatted:
99110 // <sha1> <type> <size>
100111 fields := bytes .Fields (l )
101112 if len (fields ) < 3 {
102- return nil , errors .Wrap (fmt .Errorf ("Invalid: %q" , string (l )), "git cat-file --batch" )
113+ return "" , nil , errors .Wrap (fmt .Errorf ("Invalid: %q" , string (l )), "git cat-file --batch" )
103114 }
104115
116+ blobSha := string (fields [0 ])
105117 size , _ := strconv .Atoi (string (fields [2 ]))
106118 buf := make ([]byte , size )
107119 read , err := io .ReadFull (s .r , buf )
108120 if err != nil {
109- return nil , err
121+ return blobSha , nil , err
110122 }
111123
112124 if size != read {
113- return nil , fmt .Errorf ("expected %d bytes, read %d bytes" , size , read )
125+ return blobSha , nil , fmt .Errorf ("expected %d bytes, read %d bytes" , size , read )
114126 }
115127
116128 p , err := DecodePointer (bytes .NewBuffer (buf [:read ]))
117129 var pointer * WrappedPointer
118130 if err == nil {
119131 pointer = & WrappedPointer {
120- Sha1 : string ( fields [ 0 ]) ,
132+ Sha1 : blobSha ,
121133 Pointer : p ,
122134 }
123135 }
124136
125137 _ , err = s .r .ReadBytes ('\n' ) // Extra \n inserted by cat-file
126- return pointer , err
138+ return blobSha , pointer , err
127139}
0 commit comments