MCPcopy Index your code
hub / github.com/google/git-appraise / splitBatchCatFileOutput

Function splitBatchCatFileOutput

repository/git.go:745–791  ·  view source on GitHub ↗

splitBatchCatFileOutput parses the output of a 'git cat-file --batch=...' command. The output is expected to be formatted as a series of entries, with each entry consisting of: 1. The SHA1 hash of the git object being output, followed by a newline. 2. The size of the object's contents in bytes, fol

(out *bytes.Buffer)

Source from the content-addressed store, hash-verified

743// To generate this format, make sure that the 'git cat-file' command includes
744// the argument '--batch=%(objectname)\n%(objectsize)'.
745func splitBatchCatFileOutput(out *bytes.Buffer) (map[string][]byte, error) {
746 contentsMap := make(map[string][]byte)
747 reader := bufio.NewReader(out)
748 for {
749 nameLine, err := reader.ReadString(byte('\n'))
750 if strings.HasSuffix(nameLine, "\n") {
751 nameLine = strings.TrimSuffix(nameLine, "\n")
752 }
753 if err == io.EOF {
754 return contentsMap, nil
755 }
756 if err != nil {
757 return nil, fmt.Errorf("Failure while reading the next object name: %v", err)
758 }
759 sizeLine, err := reader.ReadString(byte('\n'))
760 if strings.HasSuffix(sizeLine, "\n") {
761 sizeLine = strings.TrimSuffix(sizeLine, "\n")
762 }
763 if err != nil {
764 return nil, fmt.Errorf("Failure while reading the next object size: %q - %v", nameLine, err)
765 }
766 size, err := strconv.Atoi(sizeLine)
767 if err != nil {
768 return nil, fmt.Errorf("Failure while parsing the next object size: %q - %v", nameLine, err)
769 }
770 contentBytes := make([]byte, size, size)
771 readDest := contentBytes
772 len := 0
773 err = nil
774 for err == nil && len < size {
775 nextLen := 0
776 nextLen, err = reader.Read(readDest)
777 len += nextLen
778 readDest = contentBytes[len:]
779 }
780 contentsMap[nameLine] = contentBytes
781 if err == io.EOF {
782 return contentsMap, nil
783 }
784 if err != nil {
785 return nil, err
786 }
787 for bs, err := reader.Peek(1); err == nil && bs[0] == byte('\n'); bs, err = reader.Peek(1) {
788 reader.ReadByte()
789 }
790 }
791}
792
793// notesMapping represents the association between a git object and the notes for that object.
794type notesMapping struct {

Callers 2

getNoteContentsMapMethod · 0.85

Calls

no outgoing calls

Tested by 1