Adjust the given line number (one-based) according to the current patch. The patch is supposed to be a diff of an old file state against the working directory; the line number is a line number in that old file, and the function returns the corresponding line number in the working directory file.
(lineNumber int)
| 181 | // directory; the line number is a line number in that old file, and the |
| 182 | // function returns the corresponding line number in the working directory file. |
| 183 | func (self *Patch) AdjustLineNumber(lineNumber int) int { |
| 184 | adjustedLineNumber := lineNumber |
| 185 | for _, hunk := range self.hunks { |
| 186 | if hunk.oldStart >= lineNumber { |
| 187 | break |
| 188 | } |
| 189 | |
| 190 | if hunk.oldStart+hunk.oldLength() > lineNumber { |
| 191 | return hunk.newStart |
| 192 | } |
| 193 | |
| 194 | adjustedLineNumber += hunk.newLength() - hunk.oldLength() |
| 195 | } |
| 196 | |
| 197 | return adjustedLineNumber |
| 198 | } |
| 199 | |
| 200 | func (self *Patch) IsSingleHunkForWholeFile() bool { |
| 201 | if len(self.hunks) != 1 { |