aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/sourcegraph/go-diff/diff/diff.go
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/diff/diff.go
parent298a69c38dd5c8a9bbd7a022e88f4ddbcf885e16 (diff)
vendor/github.com/golangci/golangci-lint: update to v1.31
Diffstat (limited to 'vendor/github.com/sourcegraph/go-diff/diff/diff.go')
-rw-r--r--vendor/github.com/sourcegraph/go-diff/diff/diff.go64
1 files changed, 60 insertions, 4 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.