mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 14:28:17 +03:00
metadata_diff: fix off by one error in added_lines_count for newly added files
Summary: For files that end in newline, the number of newlines is equal to the number of lines. For files that don't end in new line, the number of newlines plus one for the last line, is equal to the number of lines. Reviewed By: RajivTS Differential Revision: D49054968 fbshipit-source-id: 202ab964db39e6bd896582c2b3dde4026ebd2546
This commit is contained in:
parent
3d14fc8248
commit
a105b6e031
@ -281,15 +281,13 @@ impl TextFile {
|
||||
})
|
||||
}
|
||||
|
||||
/// This method replaces text.lines().count() and use the metadata to get
|
||||
/// that information. The behavior should be identical in most cases except
|
||||
/// when the text ends in a newline. The lines().count() method does not consider
|
||||
/// the last newline in that case but it would still be counted in metadata.newline_count.
|
||||
fn lines(&self) -> usize {
|
||||
if self.metadata.ends_in_newline {
|
||||
(self.metadata.newline_count - 1) as usize
|
||||
} else {
|
||||
// For files that end in newline, the number of lines is equal to the number of newlines.
|
||||
self.metadata.newline_count as usize
|
||||
} else {
|
||||
// For files that don't end in a newline, the number of lines is equal to the number of newlines plus one for the last line.
|
||||
(self.metadata.newline_count + 1) as usize
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user