Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Chunk stats calculation has wrong line count for additions and deletions #1074

Closed
lafriks opened this issue Feb 25, 2019 · 1 comment · Fixed by #1088
Closed

Chunk stats calculation has wrong line count for additions and deletions #1074

lafriks opened this issue Feb 25, 2019 · 1 comment · Fixed by #1088

Comments

@lafriks
Copy link

lafriks commented Feb 25, 2019

Current code in patch.go has:

		for _, chunk := range fp.Chunks() {
			switch chunk.Type() {
			case fdiff.Add:
				cs.Addition += strings.Count(chunk.Content(), "\n")
			case fdiff.Delete:
				cs.Deletion += strings.Count(chunk.Content(), "\n")
			}
		}

That will have wrong count as if chunk content is line1\nline2 that is 2 additions/deletions not one.

Looks like this calculation is wrong only if there is no newline at the end of file

@lafriks
Copy link
Author

lafriks commented Feb 25, 2019

For such commit:

commit 6e93d441908e22b1a07d9584b7d3d5364b727c8d (HEAD -> master, origin/master, origin/HEAD)
Author: user1 <[email protected]>
Date:   Sat Feb 23 17:16:03 2019 +0200

    Update 'main.go'

diff --git a/main.go b/main.go
index d1c9dc53f..4fd03354a 100644
--- a/main.go
+++ b/main.go
@@ -1 +1,7 @@
-Q!
\ No newline at end of file
+Fdfsdf
+
+
+sdfdsf
+sdf
+sd
+f
\ No newline at end of file

git show --stats will return:

 main.go | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

while current src-d/go-git code 6 additions and 0 deletions

overshom added a commit to overshom/go-git that referenced this issue Mar 14, 2019
…end. Fixes src-d#1074

Signed-off-by: Oleksii Shnyra <oleksii@global>
sapk pushed a commit to sapk-fork/go-git that referenced this issue Apr 24, 2019
…end. Fixes src-d#1074

Signed-off-by: Oleksii Shnyra <oleksii@global>
sapk pushed a commit to sapk-fork/go-git that referenced this issue Apr 24, 2019
…end. Fixes src-d#1074

Signed-off-by: Oleksii Shnyra <oleksii@global>
Signed-off-by: Antoine GIRARD <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant