this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add parameter to fix line numbers in errors

In certain cases, the error is generated from the peeked next line or a
line that was read in the past. The delta flag corrects for this,
producing accurate error messages.

+9 -10
+6 -6
gitdiff/file_header.go
··· 13 13 header = strings.TrimPrefix(header, fileHeaderPrefix) 14 14 defaultName, err := parseGitHeaderName(header) 15 15 if err != nil { 16 - return p.Errorf("git file header: %v", err) 16 + return p.Errorf(0, "git file header: %v", err) 17 17 } 18 18 19 19 for { ··· 26 26 27 27 end, err := parseGitHeaderData(f, line, defaultName) 28 28 if err != nil { 29 - return p.Errorf("git file header: %v", err) 29 + return p.Errorf(1, "git file header: %v", err) 30 30 } 31 31 if end { 32 32 break ··· 36 36 37 37 if f.OldName == "" && f.NewName == "" { 38 38 if defaultName == "" { 39 - return p.Errorf("git file header: missing filename information") 39 + return p.Errorf(0, "git file header: missing filename information") 40 40 } 41 41 f.OldName = defaultName 42 42 f.NewName = defaultName 43 43 } 44 44 45 45 if (f.NewName == "" && !f.IsDelete) || (f.OldName == "" && !f.IsNew) { 46 - return p.Errorf("git file header: missing filename information") 46 + return p.Errorf(0, "git file header: missing filename information") 47 47 } 48 48 49 49 return nil ··· 52 52 func (p *parser) ParseTraditionalFileHeader(f *File, oldLine, newLine string) error { 53 53 oldName, _, err := parseName(strings.TrimPrefix(oldLine, oldFilePrefix), '\t', 0) 54 54 if err != nil { 55 - return p.Errorf("file header: %v", err) 55 + return p.Errorf(-1, "file header: %v", err) 56 56 } 57 57 58 58 newName, _, err := parseName(strings.TrimPrefix(newLine, newFilePrefix), '\t', 0) 59 59 if err != nil { 60 - return p.Errorf("file header: %v", err) 60 + return p.Errorf(0, "file header: %v", err) 61 61 } 62 62 63 63 switch {
+3 -4
gitdiff/parser.go
··· 85 85 // not a valid header, nothing to worry about 86 86 continue 87 87 } 88 - return nil, p.Errorf("patch fragment without header: %s", line) 88 + return nil, p.Errorf(0, "patch fragment without header: %s", line) 89 89 } 90 90 91 91 // check for a git-generated patch ··· 157 157 } 158 158 159 159 // Errorf generates an error and appends the current line information. 160 - // TODO(bkeyes): add linedelta to allow changing lineno per-error 161 - func (p *parser) Errorf(msg string, args ...interface{}) error { 162 - return fmt.Errorf("gitdiff: line %d: %s", p.lineno, fmt.Sprintf(msg, args...)) 160 + func (p *parser) Errorf(delta int64, msg string, args ...interface{}) error { 161 + return fmt.Errorf("gitdiff: line %d: %s", p.lineno+delta, fmt.Sprintf(msg, args...)) 163 162 } 164 163 165 164 func isMaybeFragmentHeader(line string) bool {