aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/sourcegraph/go-diff
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-09-15 18:05:35 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-09-15 19:34:30 +0200
commit712de1c63d9db97c81af68cd0dc4372c53d2e57a (patch)
treeae1761fec52c3ae4ddd003a4130ddbda8d0a2d69 /vendor/github.com/sourcegraph/go-diff
parent298a69c38dd5c8a9bbd7a022e88f4ddbcf885e16 (diff)
vendor/github.com/golangci/golangci-lint: update to v1.31
Diffstat (limited to 'vendor/github.com/sourcegraph/go-diff')
-rw-r--r--vendor/github.com/sourcegraph/go-diff/diff/diff.go64
-rw-r--r--vendor/github.com/sourcegraph/go-diff/diff/diff.pb.go1059
-rw-r--r--vendor/github.com/sourcegraph/go-diff/diff/diff.proto81
-rw-r--r--vendor/github.com/sourcegraph/go-diff/diff/parse.go119
-rw-r--r--vendor/github.com/sourcegraph/go-diff/diff/print.go25
5 files changed, 169 insertions, 1179 deletions
diff --git a/vendor/github.com/sourcegraph/go-diff/diff/diff.go b/vendor/github.com/sourcegraph/go-diff/diff/diff.go
index 646602a6c..0f465b9e2 100644
--- a/vendor/github.com/sourcegraph/go-diff/diff/diff.go
+++ b/vendor/github.com/sourcegraph/go-diff/diff/diff.go
@@ -1,10 +1,64 @@
package diff
-import "bytes"
+import (
+ "bytes"
+ "time"
+)
-// NOTE: types are code-generated in diff.pb.go.
+// A FileDiff represents a unified diff for a single file.
+//
+// A file unified diff has a header that resembles the following:
+//
+// --- oldname 2009-10-11 15:12:20.000000000 -0700
+// +++ newname 2009-10-11 15:12:30.000000000 -0700
+type FileDiff struct {
+ // the original name of the file
+ OrigName string
+ // the original timestamp (nil if not present)
+ OrigTime *time.Time
+ // the new name of the file (often same as OrigName)
+ NewName string
+ // the new timestamp (nil if not present)
+ NewTime *time.Time
+ // extended header lines (e.g., git's "new mode <mode>", "rename from <path>", etc.)
+ Extended []string
+ // hunks that were changed from orig to new
+ Hunks []*Hunk
+}
-//go:generate protoc -I../../../.. -I ../../../../github.com/gogo/protobuf/protobuf -I. --gogo_out=. diff.proto
+// A Hunk represents a series of changes (additions or deletions) in a file's
+// unified diff.
+type Hunk struct {
+ // starting line number in original file
+ OrigStartLine int32
+ // number of lines the hunk applies to in the original file
+ OrigLines int32
+ // if > 0, then the original file had a 'No newline at end of file' mark at this offset
+ OrigNoNewlineAt int32
+ // starting line number in new file
+ NewStartLine int32
+ // number of lines the hunk applies to in the new file
+ NewLines int32
+ // optional section heading
+ Section string
+ // 0-indexed line offset in unified file diff (including section headers); this is
+ // only set when Hunks are read from entire file diff (i.e., when ReadAllHunks is
+ // called) This accounts for hunk headers, too, so the StartPosition of the first
+ // hunk will be 1.
+ StartPosition int32
+ // hunk body (lines prefixed with '-', '+', or ' ')
+ Body []byte
+}
+
+// A Stat is a diff stat that represents the number of lines added/changed/deleted.
+type Stat struct {
+ // number of lines added
+ Added int32
+ // number of lines changed
+ Changed int32
+ // number of lines deleted
+ Deleted int32
+}
// Stat computes the number of lines added/changed/deleted in all
// hunks in this file's diff.
@@ -54,10 +108,12 @@ func (h *Hunk) Stat() Stat {
}
var (
- hunkPrefix = []byte("@@ ")
+ hunkPrefix = []byte("@@ ")
+ onlyInMessagePrefix = []byte("Only in ")
)
const hunkHeader = "@@ -%d,%d +%d,%d @@"
+const onlyInMessage = "Only in %s: %s\n"
// diffTimeParseLayout is the layout used to parse the time in unified diff file
// header timestamps.
diff --git a/vendor/github.com/sourcegraph/go-diff/diff/diff.pb.go b/vendor/github.com/sourcegraph/go-diff/diff/diff.pb.go
deleted file mode 100644
index 2e7c27fb4..000000000
--- a/vendor/github.com/sourcegraph/go-diff/diff/diff.pb.go
+++ /dev/null
@@ -1,1059 +0,0 @@
-// Code generated by protoc-gen-gogo.
-// source: diff.proto
-// DO NOT EDIT!
-
-/*
- Package diff is a generated protocol buffer package.
-
- It is generated from these files:
- diff.proto
-
- It has these top-level messages:
- FileDiff
- Hunk
- Stat
-*/
-package diff
-
-import proto "github.com/gogo/protobuf/proto"
-import fmt "fmt"
-import math "math"
-
-// discarding unused import gogoproto "github.com/gogo/protobuf/gogoproto"
-import pbtypes "sourcegraph.com/sqs/pbtypes"
-
-import io "io"
-
-// Reference imports to suppress errors if they are not otherwise used.
-var _ = proto.Marshal
-var _ = fmt.Errorf
-var _ = math.Inf
-
-// A FileDiff represents a unified diff for a single file.
-//
-// A file unified diff has a header that resembles the following:
-//
-// --- oldname 2009-10-11 15:12:20.000000000 -0700
-// +++ newname 2009-10-11 15:12:30.000000000 -0700
-type FileDiff struct {
- // the original name of the file
- OrigName string `protobuf:"bytes,1,opt,name=OrigName,proto3" json:"OrigName,omitempty"`
- // the original timestamp (nil if not present)
- OrigTime *pbtypes.Timestamp `protobuf:"bytes,2,opt,name=OrigTime" json:"OrigTime,omitempty"`
- // the new name of the file (often same as OrigName)
- NewName string `protobuf:"bytes,3,opt,name=NewName,proto3" json:"NewName,omitempty"`
- // the new timestamp (nil if not present)
- NewTime *pbtypes.Timestamp `protobuf:"bytes,4,opt,name=NewTime" json:"NewTime,omitempty"`
- // extended header lines (e.g., git's "new mode <mode>", "rename from <path>", etc.)
- Extended []string `protobuf:"bytes,5,rep,name=Extended" json:"Extended,omitempty"`
- // hunks that were changed from orig to new
- Hunks []*Hunk `protobuf:"bytes,6,rep,name=Hunks" json:"Hunks,omitempty"`
-}
-
-func (m *FileDiff) Reset() { *m = FileDiff{} }
-func (m *FileDiff) String() string { return proto.CompactTextString(m) }
-func (*FileDiff) ProtoMessage() {}
-
-// A Hunk represents a series of changes (additions or deletions) in a file's
-// unified diff.
-type Hunk struct {
- // starting line number in original file
- OrigStartLine int32 `protobuf:"varint,1,opt,name=OrigStartLine,proto3" json:"OrigStartLine,omitempty"`
- // number of lines the hunk applies to in the original file
- OrigLines int32 `protobuf:"varint,2,opt,name=OrigLines,proto3" json:"OrigLines,omitempty"`
- // if > 0, then the original file had a 'No newline at end of file' mark at this offset
- OrigNoNewlineAt int32 `protobuf:"varint,3,opt,name=OrigNoNewlineAt,proto3" json:"OrigNoNewlineAt,omitempty"`
- // starting line number in new file
- NewStartLine int32 `protobuf:"varint,4,opt,name=NewStartLine,proto3" json:"NewStartLine,omitempty"`
- // number of lines the hunk applies to in the new file
- NewLines int32 `protobuf:"varint,5,opt,name=NewLines,proto3" json:"NewLines,omitempty"`
- // optional section heading
- Section string `protobuf:"bytes,6,opt,name=Section,proto3" json:"Section,omitempty"`
- // 0-indexed line offset in unified file diff (including section headers); this is
- // only set when Hunks are read from entire file diff (i.e., when ReadAllHunks is
- // called) This accounts for hunk headers, too, so the StartPosition of the first
- // hunk will be 1.
- StartPosition int32 `protobuf:"varint,7,opt,name=StartPosition,proto3" json:"StartPosition,omitempty"`
- // hunk body (lines prefixed with '-', '+', or ' ')
- Body []byte `protobuf:"bytes,8,opt,name=Body,proto3" json:"Body,omitempty"`
-}
-
-func (m *Hunk) Reset() { *m = Hunk{} }
-func (m *Hunk) String() string { return proto.CompactTextString(m) }
-func (*Hunk) ProtoMessage() {}
-
-// A Stat is a diff stat that represents the number of lines added/changed/deleted.
-type Stat struct {
- // number of lines added
- Added int32 `protobuf:"varint,1,opt,name=Added,proto3" json:""`
- // number of lines changed
- Changed int32 `protobuf:"varint,2,opt,name=Changed,proto3" json:""`
- // number of lines deleted
- Deleted int32 `protobuf:"varint,3,opt,name=Deleted,proto3" json:""`
-}
-
-func (m *Stat) Reset() { *m = Stat{} }
-func (m *Stat) String() string { return proto.CompactTextString(m) }
-func (*Stat) ProtoMessage() {}
-
-func (m *FileDiff) Marshal() (data []byte, err error) {
- size := m.Size()
- data = make([]byte, size)
- n, err := m.MarshalTo(data)
- if err != nil {
- return nil, err
- }
- return data[:n], nil
-}
-
-func (m *FileDiff) MarshalTo(data []byte) (int, error) {
- var i int
- _ = i
- var l int
- _ = l
- if len(m.OrigName) > 0 {
- data[i] = 0xa
- i++
- i = encodeVarintDiff(data, i, uint64(len(m.OrigName)))
- i += copy(data[i:], m.OrigName)
- }
- if m.OrigTime != nil {
- data[i] = 0x12
- i++
- i = encodeVarintDiff(data, i, uint64(m.OrigTime.Size()))
- n1, err := m.OrigTime.MarshalTo(data[i:])
- if err != nil {
- return 0, err
- }
- i += n1
- }
- if len(m.NewName) > 0 {
- data[i] = 0x1a
- i++
- i = encodeVarintDiff(data, i, uint64(len(m.NewName)))
- i += copy(data[i:], m.NewName)
- }
- if m.NewTime != nil {
- data[i] = 0x22
- i++
- i = encodeVarintDiff(data, i, uint64(m.NewTime.Size()))
- n2, err := m.NewTime.MarshalTo(data[i:])
- if err != nil {
- return 0, err
- }
- i += n2
- }
- if len(m.Extended) > 0 {
- for _, s := range m.Extended {
- data[i] = 0x2a
- i++
- l = len(s)
- for l >= 1<<7 {
- data[i] = uint8(uint64(l)&0x7f | 0x80)
- l >>= 7
- i++
- }
- data[i] = uint8(l)
- i++
- i += copy(data[i:], s)
- }
- }
- if len(m.Hunks) > 0 {
- for _, msg := range m.Hunks {
- data[i] = 0x32
- i++
- i = encodeVarintDiff(data, i, uint64(msg.Size()))
- n, err := msg.MarshalTo(data[i:])
- if err != nil {
- return 0, err
- }
- i += n
- }
- }
- return i, nil
-}
-
-func (m *Hunk) Marshal() (data []byte, err error) {
- size := m.Size()
- data = make([]byte, size)
- n, err := m.MarshalTo(data)
- if err != nil {
- return nil, err
- }
- return data[:n], nil
-}
-
-func (m *Hunk) MarshalTo(data []byte) (int, error) {
- var i int
- _ = i
- var l int
- _ = l
- if m.OrigStartLine != 0 {
- data[i] = 0x8
- i++
- i = encodeVarintDiff(data, i, uint64(m.OrigStartLine))
- }
- if m.OrigLines != 0 {
- data[i] = 0x10
- i++
- i = encodeVarintDiff(data, i, uint64(m.OrigLines))
- }
- if m.OrigNoNewlineAt != 0 {
- data[i] = 0x18
- i++
- i = encodeVarintDiff(data, i, uint64(m.OrigNoNewlineAt))
- }
- if m.NewStartLine != 0 {
- data[i] = 0x20
- i++
- i = encodeVarintDiff(data, i, uint64(m.NewStartLine))
- }
- if m.NewLines != 0 {
- data[i] = 0x28
- i++
- i = encodeVarintDiff(data, i, uint64(m.NewLines))
- }
- if len(m.Section) > 0 {
- data[i] = 0x32
- i++
- i = encodeVarintDiff(data, i, uint64(len(m.Section)))
- i += copy(data[i:], m.Section)
- }
- if m.StartPosition != 0 {
- data[i] = 0x38
- i++
- i = encodeVarintDiff(data, i, uint64(m.StartPosition))
- }
- if m.Body != nil {
- if len(m.Body) > 0 {
- data[i] = 0x42
- i++
- i = encodeVarintDiff(data, i, uint64(len(m.Body)))
- i += copy(data[i:], m.Body)
- }
- }
- return i, nil
-}
-
-func (m *Stat) Marshal() (data []byte, err error) {
- size := m.Size()
- data = make([]byte, size)
- n, err := m.MarshalTo(data)
- if err != nil {
- return nil, err
- }
- return data[:n], nil
-}
-
-func (m *Stat) MarshalTo(data []byte) (int, error) {
- var i int
- _ = i
- var l int
- _ = l
- if m.Added != 0 {
- data[i] = 0x8
- i++
- i = encodeVarintDiff(data, i, uint64(m.Added))
- }
- if m.Changed != 0 {
- data[i] = 0x10
- i++
- i = encodeVarintDiff(data, i, uint64(m.Changed))
- }
- if m.Deleted != 0 {
- data[i] = 0x18
- i++
- i = encodeVarintDiff(data, i, uint64(m.Deleted))
- }
- return i, nil
-}
-
-func encodeFixed64Diff(data []byte, offset int, v uint64) int {
- data[offset] = uint8(v)
- data[offset+1] = uint8(v >> 8)
- data[offset+2] = uint8(v >> 16)
- data[offset+3] = uint8(v >> 24)
- data[offset+4] = uint8(v >> 32)
- data[offset+5] = uint8(v >> 40)
- data[offset+6] = uint8(v >> 48)
- data[offset+7] = uint8(v >> 56)
- return offset + 8
-}
-func encodeFixed32Diff(data []byte, offset int, v uint32) int {
- data[offset] = uint8(v)
- data[offset+1] = uint8(v >> 8)
- data[offset+2] = uint8(v >> 16)
- data[offset+3] = uint8(v >> 24)
- return offset + 4
-}
-func encodeVarintDiff(data []byte, offset int, v uint64) int {
- for v >= 1<<7 {
- data[offset] = uint8(v&0x7f | 0x80)
- v >>= 7
- offset++
- }
- data[offset] = uint8(v)
- return offset + 1
-}
-func (m *FileDiff) Size() (n int) {
- var l int
- _ = l
- l = len(m.OrigName)
- if l > 0 {
- n += 1 + l + sovDiff(uint64(l))
- }
- if m.OrigTime != nil {
- l = m.OrigTime.Size()
- n += 1 + l + sovDiff(uint64(l))
- }
- l = len(m.NewName)
- if l > 0 {
- n += 1 + l + sovDiff(uint64(l))
- }
- if m.NewTime != nil {
- l = m.NewTime.Size()
- n += 1 + l + sovDiff(uint64(l))
- }
- if len(m.Extended) > 0 {
- for _, s := range m.Extended {
- l = len(s)
- n += 1 + l + sovDiff(uint64(l))
- }
- }
- if len(m.Hunks) > 0 {
- for _, e := range m.Hunks {
- l = e.Size()
- n += 1 + l + sovDiff(uint64(l))
- }
- }
- return n
-}
-
-func (m *Hunk) Size() (n int) {
- var l int
- _ = l
- if m.OrigStartLine != 0 {
- n += 1 + sovDiff(uint64(m.OrigStartLine))
- }
- if m.OrigLines != 0 {
- n += 1 + sovDiff(uint64(m.OrigLines))
- }
- if m.OrigNoNewlineAt != 0 {
- n += 1 + sovDiff(uint64(m.OrigNoNewlineAt))
- }
- if m.NewStartLine != 0 {
- n += 1 + sovDiff(uint64(m.NewStartLine))
- }
- if m.NewLines != 0 {
- n += 1 + sovDiff(uint64(m.NewLines))
- }
- l = len(m.Section)
- if l > 0 {
- n += 1 + l + sovDiff(uint64(l))
- }
- if m.StartPosition != 0 {
- n += 1 + sovDiff(uint64(m.StartPosition))
- }
- if m.Body != nil {
- l = len(m.Body)
- if l > 0 {
- n += 1 + l + sovDiff(uint64(l))
- }
- }
- return n
-}
-
-func (m *Stat) Size() (n int) {
- var l int
- _ = l
- if m.Added != 0 {
- n += 1 + sovDiff(uint64(m.Added))
- }
- if m.Changed != 0 {
- n += 1 + sovDiff(uint64(m.Changed))
- }
- if m.Deleted != 0 {
- n += 1 + sovDiff(uint64(m.Deleted))
- }
- return n
-}
-
-func sovDiff(x uint64) (n int) {
- for {
- n++
- x >>= 7
- if x == 0 {
- break
- }
- }
- return n
-}
-func sozDiff(x uint64) (n int) {
- return sovDiff(uint64((x << 1) ^ uint64((int64(x) >> 63))))
-}
-func (m *FileDiff) Unmarshal(data []byte) error {
- l := len(data)
- iNdEx := 0
- for iNdEx < l {
- preIndex := iNdEx
- var wire uint64
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- wire |= (uint64(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- fieldNum := int32(wire >> 3)
- wireType := int(wire & 0x7)
- if wireType == 4 {
- return fmt.Errorf("proto: FileDiff: wiretype end group for non-group")
- }
- if fieldNum <= 0 {
- return fmt.Errorf("proto: FileDiff: illegal tag %d (wire type %d)", fieldNum, wire)
- }
- switch fieldNum {
- case 1:
- if wireType != 2 {
- return fmt.Errorf("proto: wrong wireType = %d for field OrigName", wireType)
- }
- var stringLen uint64
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- stringLen |= (uint64(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- intStringLen := int(stringLen)
- if intStringLen < 0 {
- return ErrInvalidLengthDiff
- }
- postIndex := iNdEx + intStringLen
- if postIndex > l {
- return io.ErrUnexpectedEOF
- }
- m.OrigName = string(data[iNdEx:postIndex])
- iNdEx = postIndex
- case 2:
- if wireType != 2 {
- return fmt.Errorf("proto: wrong wireType = %d for field OrigTime", wireType)
- }
- var msglen int
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- msglen |= (int(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- if msglen < 0 {
- return ErrInvalidLengthDiff
- }
- postIndex := iNdEx + msglen
- if postIndex > l {
- return io.ErrUnexpectedEOF
- }
- if m.OrigTime == nil {
- m.OrigTime = &pbtypes.Timestamp{}
- }
- if err := m.OrigTime.Unmarshal(data[iNdEx:postIndex]); err != nil {
- return err
- }
- iNdEx = postIndex
- case 3:
- if wireType != 2 {
- return fmt.Errorf("proto: wrong wireType = %d for field NewName", wireType)
- }
- var stringLen uint64
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- stringLen |= (uint64(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- intStringLen := int(stringLen)
- if intStringLen < 0 {
- return ErrInvalidLengthDiff
- }
- postIndex := iNdEx + intStringLen
- if postIndex > l {
- return io.ErrUnexpectedEOF
- }
- m.NewName = string(data[iNdEx:postIndex])
- iNdEx = postIndex
- case 4:
- if wireType != 2 {
- return fmt.Errorf("proto: wrong wireType = %d for field NewTime", wireType)
- }
- var msglen int
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- msglen |= (int(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- if msglen < 0 {
- return ErrInvalidLengthDiff
- }
- postIndex := iNdEx + msglen
- if postIndex > l {
- return io.ErrUnexpectedEOF
- }
- if m.NewTime == nil {
- m.NewTime = &pbtypes.Timestamp{}
- }
- if err := m.NewTime.Unmarshal(data[iNdEx:postIndex]); err != nil {
- return err
- }
- iNdEx = postIndex
- case 5:
- if wireType != 2 {
- return fmt.Errorf("proto: wrong wireType = %d for field Extended", wireType)
- }
- var stringLen uint64
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- stringLen |= (uint64(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- intStringLen := int(stringLen)
- if intStringLen < 0 {
- return ErrInvalidLengthDiff
- }
- postIndex := iNdEx + intStringLen
- if postIndex > l {
- return io.ErrUnexpectedEOF
- }
- m.Extended = append(m.Extended, string(data[iNdEx:postIndex]))
- iNdEx = postIndex
- case 6:
- if wireType != 2 {
- return fmt.Errorf("proto: wrong wireType = %d for field Hunks", wireType)
- }
- var msglen int
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- msglen |= (int(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- if msglen < 0 {
- return ErrInvalidLengthDiff
- }
- postIndex := iNdEx + msglen
- if postIndex > l {
- return io.ErrUnexpectedEOF
- }
- m.Hunks = append(m.Hunks, &Hunk{})
- if err := m.Hunks[len(m.Hunks)-1].Unmarshal(data[iNdEx:postIndex]); err != nil {
- return err
- }
- iNdEx = postIndex
- default:
- iNdEx = preIndex
- skippy, err := skipDiff(data[iNdEx:])
- if err != nil {
- return err
- }
- if skippy < 0 {
- return ErrInvalidLengthDiff
- }
- if (iNdEx + skippy) > l {
- return io.ErrUnexpectedEOF
- }
- iNdEx += skippy
- }
- }
-
- if iNdEx > l {
- return io.ErrUnexpectedEOF
- }
- return nil
-}
-func (m *Hunk) Unmarshal(data []byte) error {
- l := len(data)
- iNdEx := 0
- for iNdEx < l {
- preIndex := iNdEx
- var wire uint64
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- wire |= (uint64(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- fieldNum := int32(wire >> 3)
- wireType := int(wire & 0x7)
- if wireType == 4 {
- return fmt.Errorf("proto: Hunk: wiretype end group for non-group")
- }
- if fieldNum <= 0 {
- return fmt.Errorf("proto: Hunk: illegal tag %d (wire type %d)", fieldNum, wire)
- }
- switch fieldNum {
- case 1:
- if wireType != 0 {
- return fmt.Errorf("proto: wrong wireType = %d for field OrigStartLine", wireType)
- }
- m.OrigStartLine = 0
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- m.OrigStartLine |= (int32(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- case 2:
- if wireType != 0 {
- return fmt.Errorf("proto: wrong wireType = %d for field OrigLines", wireType)
- }
- m.OrigLines = 0
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- m.OrigLines |= (int32(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- case 3:
- if wireType != 0 {
- return fmt.Errorf("proto: wrong wireType = %d for field OrigNoNewlineAt", wireType)
- }
- m.OrigNoNewlineAt = 0
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- m.OrigNoNewlineAt |= (int32(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- case 4:
- if wireType != 0 {
- return fmt.Errorf("proto: wrong wireType = %d for field NewStartLine", wireType)
- }
- m.NewStartLine = 0
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- m.NewStartLine |= (int32(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- case 5:
- if wireType != 0 {
- return fmt.Errorf("proto: wrong wireType = %d for field NewLines", wireType)
- }
- m.NewLines = 0
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- m.NewLines |= (int32(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- case 6:
- if wireType != 2 {
- return fmt.Errorf("proto: wrong wireType = %d for field Section", wireType)
- }
- var stringLen uint64
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- stringLen |= (uint64(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- intStringLen := int(stringLen)
- if intStringLen < 0 {
- return ErrInvalidLengthDiff
- }
- postIndex := iNdEx + intStringLen
- if postIndex > l {
- return io.ErrUnexpectedEOF
- }
- m.Section = string(data[iNdEx:postIndex])
- iNdEx = postIndex
- case 7:
- if wireType != 0 {
- return fmt.Errorf("proto: wrong wireType = %d for field StartPosition", wireType)
- }
- m.StartPosition = 0
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- m.StartPosition |= (int32(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- case 8:
- if wireType != 2 {
- return fmt.Errorf("proto: wrong wireType = %d for field Body", wireType)
- }
- var byteLen int
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- byteLen |= (int(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- if byteLen < 0 {
- return ErrInvalidLengthDiff
- }
- postIndex := iNdEx + byteLen
- if postIndex > l {
- return io.ErrUnexpectedEOF
- }
- m.Body = append([]byte{}, data[iNdEx:postIndex]...)
- iNdEx = postIndex
- default:
- iNdEx = preIndex
- skippy, err := skipDiff(data[iNdEx:])
- if err != nil {
- return err
- }
- if skippy < 0 {
- return ErrInvalidLengthDiff
- }
- if (iNdEx + skippy) > l {
- return io.ErrUnexpectedEOF
- }
- iNdEx += skippy
- }
- }
-
- if iNdEx > l {
- return io.ErrUnexpectedEOF
- }
- return nil
-}
-func (m *Stat) Unmarshal(data []byte) error {
- l := len(data)
- iNdEx := 0
- for iNdEx < l {
- preIndex := iNdEx
- var wire uint64
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- wire |= (uint64(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- fieldNum := int32(wire >> 3)
- wireType := int(wire & 0x7)
- if wireType == 4 {
- return fmt.Errorf("proto: Stat: wiretype end group for non-group")
- }
- if fieldNum <= 0 {
- return fmt.Errorf("proto: Stat: illegal tag %d (wire type %d)", fieldNum, wire)
- }
- switch fieldNum {
- case 1:
- if wireType != 0 {
- return fmt.Errorf("proto: wrong wireType = %d for field Added", wireType)
- }
- m.Added = 0
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- m.Added |= (int32(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- case 2:
- if wireType != 0 {
- return fmt.Errorf("proto: wrong wireType = %d for field Changed", wireType)
- }
- m.Changed = 0
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- m.Changed |= (int32(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- case 3:
- if wireType != 0 {
- return fmt.Errorf("proto: wrong wireType = %d for field Deleted", wireType)
- }
- m.Deleted = 0
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- m.Deleted |= (int32(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- default:
- iNdEx = preIndex
- skippy, err := skipDiff(data[iNdEx:])
- if err != nil {
- return err
- }
- if skippy < 0 {
- return ErrInvalidLengthDiff
- }
- if (iNdEx + skippy) > l {
- return io.ErrUnexpectedEOF
- }
- iNdEx += skippy
- }
- }
-
- if iNdEx > l {
- return io.ErrUnexpectedEOF
- }
- return nil
-}
-func skipDiff(data []byte) (n int, err error) {
- l := len(data)
- iNdEx := 0
- for iNdEx < l {
- var wire uint64
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return 0, ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return 0, io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- wire |= (uint64(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- wireType := int(wire & 0x7)
- switch wireType {
- case 0:
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return 0, ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return 0, io.ErrUnexpectedEOF
- }
- iNdEx++
- if data[iNdEx-1] < 0x80 {
- break
- }
- }
- return iNdEx, nil
- case 1:
- iNdEx += 8
- return iNdEx, nil
- case 2:
- var length int
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return 0, ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return 0, io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- length |= (int(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- iNdEx += length
- if length < 0 {
- return 0, ErrInvalidLengthDiff
- }
- return iNdEx, nil
- case 3:
- for {
- var innerWire uint64
- var start int = iNdEx
- for shift := uint(0); ; shift += 7 {
- if shift >= 64 {
- return 0, ErrIntOverflowDiff
- }
- if iNdEx >= l {
- return 0, io.ErrUnexpectedEOF
- }
- b := data[iNdEx]
- iNdEx++
- innerWire |= (uint64(b) & 0x7F) << shift
- if b < 0x80 {
- break
- }
- }
- innerWireType := int(innerWire & 0x7)
- if innerWireType == 4 {
- break
- }
- next, err := skipDiff(data[start:])
- if err != nil {
- return 0, err
- }
- iNdEx = start + next
- }
- return iNdEx, nil
- case 4:
- return iNdEx, nil
- case 5:
- iNdEx += 4
- return iNdEx, nil
- default:
- return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
- }
- }
- panic("unreachable")
-}
-
-var (
- ErrInvalidLengthDiff = fmt.Errorf("proto: negative length found during unmarshaling")
- ErrIntOverflowDiff = fmt.Errorf("proto: integer overflow")
-)
diff --git a/vendor/github.com/sourcegraph/go-diff/diff/diff.proto b/vendor/github.com/sourcegraph/go-diff/diff/diff.proto
deleted file mode 100644
index 8868970f6..000000000
--- a/vendor/github.com/sourcegraph/go-diff/diff/diff.proto
+++ /dev/null
@@ -1,81 +0,0 @@
-syntax = "proto3";
-package diff;
-
-import "github.com/gogo/protobuf/gogoproto/gogo.proto";
-import "sourcegraph.com/sqs/pbtypes/timestamp.proto";
-
-option (gogoproto.goproto_getters_all) = false;
-option (gogoproto.unmarshaler_all) = true;
-option (gogoproto.marshaler_all) = true;
-option (gogoproto.sizer_all) = true;
-
-// A FileDiff represents a unified diff for a single file.
-//
-// A file unified diff has a header that resembles the following:
-//
-// --- oldname 2009-10-11 15:12:20.000000000 -0700
-// +++ newname 2009-10-11 15:12:30.000000000 -0700
-message FileDiff {
- // the original name of the file
- string OrigName = 1;
-
- // the original timestamp (nil if not present)
- pbtypes.Timestamp OrigTime = 2;
-
- // the new name of the file (often same as OrigName)
- string NewName = 3;
-
- // the new timestamp (nil if not present)
- pbtypes.Timestamp NewTime = 4;
-
- // extended header lines (e.g., git's "new mode <mode>", "rename from <path>", etc.)
- repeated string Extended = 5;
-
- // hunks that were changed from orig to new
- repeated Hunk Hunks = 6;
-}
-
-
-// A Hunk represents a series of changes (additions or deletions) in a file's
-// unified diff.
-message Hunk {
- // starting line number in original file
- int32 OrigStartLine = 1;
-
- // number of lines the hunk applies to in the original file
- int32 OrigLines = 2;
-
- // if > 0, then the original file had a 'No newline at end of file' mark at this offset
- int32 OrigNoNewlineAt = 3;
-
- // starting line number in new file
- int32 NewStartLine = 4;
-
- // number of lines the hunk applies to in the new file
- int32 NewLines = 5;
-
- // optional section heading
- string Section = 6;
-
- // 0-indexed line offset in unified file diff (including section headers); this is
- // only set when Hunks are read from entire file diff (i.e., when ReadAllHunks is
- // called) This accounts for hunk headers, too, so the StartPosition of the first
- // hunk will be 1.
- int32 StartPosition = 7;
-
- // hunk body (lines prefixed with '-', '+', or ' ')
- bytes Body = 8;
-}
-
-// A Stat is a diff stat that represents the number of lines added/changed/deleted.
-message Stat {
- // number of lines added
- int32 Added = 1 [(gogoproto.jsontag) = ""];
-
- // number of lines changed
- int32 Changed = 2 [(gogoproto.jsontag) = ""];
-
- // number of lines deleted
- int32 Deleted = 3 [(gogoproto.jsontag) = ""];
-}
-
diff --git a/vendor/github.com/sourcegraph/go-diff/diff/parse.go b/vendor/github.com/sourcegraph/go-diff/diff/parse.go
index 1e77df48f..674350230 100644
--- a/vendor/github.com/sourcegraph/go-diff/diff/parse.go
+++ b/vendor/github.com/sourcegraph/go-diff/diff/parse.go
@@ -6,15 +6,16 @@ import (
"errors"
"fmt"
"io"
+ "path/filepath"
+ "strconv"
"strings"
"time"
-
- "sourcegraph.com/sqs/pbtypes"
)
-// ParseMultiFileDiff parses a multi-file unified diff. It returns an error if parsing failed as a whole, but does its
-// best to parse as many files in the case of per-file errors. In the case of non-fatal per-file errors, the error
-// return value is null and the Errs field in the returned MultiFileDiff is set.
+// ParseMultiFileDiff parses a multi-file unified diff. It returns an error if
+// parsing failed as a whole, but does its best to parse as many files in the
+// case of per-file errors. If it cannot detect when the diff of the next file
+// begins, the hunks are added to the FileDiff of the previous file.
func ParseMultiFileDiff(diff []byte) ([]*FileDiff, error) {
return NewMultiFileDiffReader(bytes.NewReader(diff)).ReadAllFiles()
}
@@ -70,6 +71,12 @@ func (r *MultiFileDiffReader) ReadFile() (*FileDiff, error) {
}
}
+ // FileDiff is added/deleted file
+ // No further collection of hunks needed
+ if fd.NewName == "" {
+ return fd, nil
+ }
+
// Before reading hunks, check to see if there are any. If there
// aren't any, and there's another file after this file in the
// diff, then the hunks reader will complain ErrNoHunkHeader. It's
@@ -78,7 +85,7 @@ func (r *MultiFileDiffReader) ReadFile() (*FileDiff, error) {
// need to perform the check here.
hr := fr.HunksReader()
line, err := readLine(r.reader)
- if err != nil {
+ if err != nil && err != io.EOF {
return fd, err
}
line = bytes.TrimSuffix(line, []byte{'\n'})
@@ -196,12 +203,10 @@ func (r *FileDiffReader) ReadAllHeaders() (*FileDiff, error) {
return nil, err
}
if origTime != nil {
- ts := pbtypes.NewTimestamp(*origTime)
- fd.OrigTime = &ts
+ fd.OrigTime = origTime
}
if newTime != nil {
- ts := pbtypes.NewTimestamp(*newTime)
- fd.NewTime = &ts
+ fd.NewTime = newTime
}
return fd, nil
@@ -221,8 +226,16 @@ func (r *FileDiffReader) HunksReader() *HunksReader {
// ReadFileHeaders reads the unified file diff header (the lines that
// start with "---" and "+++" with the orig/new file names and
-// timestamps).
+// timestamps). Or which starts with "Only in " with dir path and filename.
+// "Only in" message is supported in POSIX locale: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/diff.html#tag_20_34_10
func (r *FileDiffReader) ReadFileHeaders() (origName, newName string, origTimestamp, newTimestamp *time.Time, err error) {
+ if r.fileHeaderLine != nil {
+ if isOnlyMessage, source, filename := parseOnlyInMessage(r.fileHeaderLine); isOnlyMessage {
+ return filepath.Join(string(source), string(filename)),
+ "", nil, nil, nil
+ }
+ }
+
origName, origTimestamp, err = r.readOneFileHeader([]byte("--- "))
if err != nil {
return "", "", nil, nil, err
@@ -233,6 +246,15 @@ func (r *FileDiffReader) ReadFileHeaders() (origName, newName string, origTimest
return "", "", nil, nil, err
}
+ unquotedOrigName, err := strconv.Unquote(origName)
+ if err == nil {
+ origName = unquotedOrigName
+ }
+ unquotedNewName, err := strconv.Unquote(newName)
+ if err == nil {
+ newName = unquotedNewName
+ }
+
return origName, newName, origTimestamp, newTimestamp, nil
}
@@ -282,7 +304,7 @@ func (r *FileDiffReader) readOneFileHeader(prefix []byte) (filename string, time
type OverflowError string
func (e OverflowError) Error() string {
- return fmt.Sprintf("overflowed into next file: %s", e)
+ return fmt.Sprintf("overflowed into next file: %s", string(e))
}
// ReadExtendedHeaders reads the extended header lines, if any, from a
@@ -319,6 +341,12 @@ func (r *FileDiffReader) ReadExtendedHeaders() ([]string, error) {
return xheaders, nil
}
+ // Reached message that file is added/deleted
+ if isOnlyInMessage, _, _ := parseOnlyInMessage(line); isOnlyInMessage {
+ r.fileHeaderLine = line // pass to readOneFileHeader (see fileHeaderLine field doc)
+ return xheaders, nil
+ }
+
r.line++
r.offset += int64(len(line))
xheaders = append(xheaders, string(line))
@@ -328,31 +356,59 @@ func (r *FileDiffReader) ReadExtendedHeaders() ([]string, error) {
// handleEmpty detects when FileDiff was an empty diff and will not have any hunks
// that follow. It updates fd fields from the parsed extended headers.
func handleEmpty(fd *FileDiff) (wasEmpty bool) {
+ var err error
+ lineCount := len(fd.Extended)
+ if lineCount > 0 && !strings.HasPrefix(fd.Extended[0], "diff --git ") {
+ return false
+ }
switch {
- case (len(fd.Extended) == 3 || len(fd.Extended) == 4 && strings.HasPrefix(fd.Extended[3], "Binary files ")) &&
- strings.HasPrefix(fd.Extended[1], "new file mode ") && strings.HasPrefix(fd.Extended[0], "diff --git "):
+ case (lineCount == 3 || lineCount == 4 && strings.HasPrefix(fd.Extended[3], "Binary files ") || lineCount > 4 && strings.HasPrefix(fd.Extended[3], "GIT binary patch")) &&
+ strings.HasPrefix(fd.Extended[1], "new file mode "):
names := strings.SplitN(fd.Extended[0][len("diff --git "):], " ", 2)
fd.OrigName = "/dev/null"
- fd.NewName = names[1]
+ fd.NewName, err = strconv.Unquote(names[1])
+ if err != nil {
+ fd.NewName = names[1]
+ }
return true
- case (len(fd.Extended) == 3 || len(fd.Extended) == 4 && strings.HasPrefix(fd.Extended[3], "Binary files ")) &&
- strings.HasPrefix(fd.Extended[1], "deleted file mode ") && strings.HasPrefix(fd.Extended[0], "diff --git "):
+ case (lineCount == 3 || lineCount == 4 && strings.HasPrefix(fd.Extended[3], "Binary files ") || lineCount > 4 && strings.HasPrefix(fd.Extended[3], "GIT binary patch")) &&
+ strings.HasPrefix(fd.Extended[1], "deleted file mode "):
names := strings.SplitN(fd.Extended[0][len("diff --git "):], " ", 2)
- fd.OrigName = names[0]
+ fd.OrigName, err = strconv.Unquote(names[0])
+ if err != nil {
+ fd.OrigName = names[0]
+ }
fd.NewName = "/dev/null"
return true
- case len(fd.Extended) == 4 && strings.HasPrefix(fd.Extended[2], "rename from ") && strings.HasPrefix(fd.Extended[3], "rename to ") && strings.HasPrefix(fd.Extended[0], "diff --git "):
+ case lineCount == 4 && strings.HasPrefix(fd.Extended[2], "rename from ") && strings.HasPrefix(fd.Extended[3], "rename to "):
names := strings.SplitN(fd.Extended[0][len("diff --git "):], " ", 2)
- fd.OrigName = names[0]
- fd.NewName = names[1]
+ fd.OrigName, err = strconv.Unquote(names[0])
+ if err != nil {
+ fd.OrigName = names[0]
+ }
+ fd.NewName, err = strconv.Unquote(names[1])
+ if err != nil {
+ fd.NewName = names[1]
+ }
return true
- case len(fd.Extended) == 3 && strings.HasPrefix(fd.Extended[2], "Binary files ") && strings.HasPrefix(fd.Extended[0], "diff --git "):
+ case lineCount == 6 && strings.HasPrefix(fd.Extended[5], "Binary files ") && strings.HasPrefix(fd.Extended[2], "rename from ") && strings.HasPrefix(fd.Extended[3], "rename to "):
names := strings.SplitN(fd.Extended[0][len("diff --git "):], " ", 2)
fd.OrigName = names[0]
fd.NewName = names[1]
return true
+ case lineCount == 3 && strings.HasPrefix(fd.Extended[2], "Binary files ") || lineCount > 3 && strings.HasPrefix(fd.Extended[2], "GIT binary patch"):
+ names := strings.SplitN(fd.Extended[0][len("diff --git "):], " ", 2)
+ fd.OrigName, err = strconv.Unquote(names[0])
+ if err != nil {
+ fd.OrigName = names[0]
+ }
+ fd.NewName, err = strconv.Unquote(names[1])
+ if err != nil {
+ fd.NewName = names[1]
+ }
+ return true
default:
return false
}
@@ -369,6 +425,10 @@ var (
// ErrExtendedHeadersEOF is when an EOF was encountered while reading extended file headers, which means that there were no ---/+++ headers encountered before hunks (if any) began.
ErrExtendedHeadersEOF = errors.New("expected file header while reading extended headers, got EOF")
+
+ // ErrBadOnlyInMessage is when a file have a malformed `only in` message
+ // Should be in format `Only in {source}: {filename}`
+ ErrBadOnlyInMessage = errors.New("bad 'only in' message")
)
// ParseHunks parses hunks from a unified diff. The diff must consist
@@ -467,7 +527,7 @@ func (r *HunksReader) ReadHunk() (*Hunk, error) {
return r.hunk, nil
}
- if len(line) >= 1 && !linePrefix(line[0]) {
+ if len(line) >= 1 && (!linePrefix(line[0]) || bytes.HasPrefix(line, []byte("--- "))) {
// Bad hunk header line. If we're reading a multi-file
// diff, this may be the end of the current
// file. Return a "rich" error that lets our caller
@@ -578,6 +638,19 @@ func (r *HunksReader) ReadAllHunks() ([]*Hunk, error) {
}
}
+// parseOnlyInMessage checks if line is a "Only in {source}: {filename}" and returns source and filename
+func parseOnlyInMessage(line []byte) (bool, []byte, []byte) {
+ if !bytes.HasPrefix(line, onlyInMessagePrefix) {
+ return false, nil, nil
+ }
+ line = line[len(onlyInMessagePrefix):]
+ idx := bytes.Index(line, []byte(": "))
+ if idx < 0 {
+ return false, nil, nil
+ }
+ return true, line[:idx], line[idx+2:]
+}
+
// A ParseError is a description of a unified diff syntax error.
type ParseError struct {
Line int // Line where the error occurred
diff --git a/vendor/github.com/sourcegraph/go-diff/diff/print.go b/vendor/github.com/sourcegraph/go-diff/diff/print.go
index d440cb9ad..012651a33 100644
--- a/vendor/github.com/sourcegraph/go-diff/diff/print.go
+++ b/vendor/github.com/sourcegraph/go-diff/diff/print.go
@@ -4,9 +4,8 @@ import (
"bytes"
"fmt"
"io"
+ "path/filepath"
"time"
-
- "sourcegraph.com/sqs/pbtypes"
)
// PrintMultiFileDiff prints a multi-file diff in unified diff format.
@@ -36,14 +35,24 @@ func PrintFileDiff(d *FileDiff) ([]byte, error) {
}
}
+ // FileDiff is added/deleted file
+ // No further hunks printing needed
+ if d.NewName == "" {
+ _, err := fmt.Fprintf(&buf, onlyInMessage, filepath.Dir(d.OrigName), filepath.Base(d.OrigName))
+ if err != nil {
+ return nil, err
+ }
+ return buf.Bytes(), nil
+ }
+
if d.Hunks == nil {
return buf.Bytes(), nil
}
- if err := printFileHeader(&buf, "--- ", d.OrigName, timePtr(d.OrigTime)); err != nil {
+ if err := printFileHeader(&buf, "--- ", d.OrigName, d.OrigTime); err != nil {
return nil, err
}
- if err := printFileHeader(&buf, "+++ ", d.NewName, timePtr(d.NewTime)); err != nil {
+ if err := printFileHeader(&buf, "+++ ", d.NewName, d.NewTime); err != nil {
return nil, err
}
@@ -58,14 +67,6 @@ func PrintFileDiff(d *FileDiff) ([]byte, error) {
return buf.Bytes(), nil
}
-func timePtr(ts *pbtypes.Timestamp) *time.Time {
- if ts == nil {
- return nil
- }
- t := ts.Time()
- return &t
-}
-
func printFileHeader(w io.Writer, prefix string, filename string, timestamp *time.Time) error {
if _, err := fmt.Fprint(w, prefix, filename); err != nil {
return err