Skip to content

Display specific message if diff is not displayed because of too long line #15611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Loutro
Copy link
Contributor

@Loutro Loutro commented Apr 24, 2021

If file diff incomplete because one line is too long, display specific message

Fix #7184

@Loutro Loutro changed the title 7184- message if line too long #7184 - file incomplete, specific message if because of too long line Apr 24, 2021
@codecov-commenter
Copy link

codecov-commenter commented Apr 24, 2021

Codecov Report

Merging #15611 (b356a52) into master (1cd3017) will decrease coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #15611      +/-   ##
==========================================
- Coverage   43.89%   43.82%   -0.07%     
==========================================
  Files         678      678              
  Lines       81878    81881       +3     
==========================================
- Hits        35941    35886      -55     
- Misses      40087    40153      +66     
+ Partials     5850     5842       -8     
Impacted Files Coverage Δ
services/gitdiff/gitdiff.go 73.76% <100.00%> (+1.52%) ⬆️
modules/notification/ui/ui.go 58.97% <0.00%> (-6.84%) ⬇️
models/issue_comment.go 45.97% <0.00%> (-6.61%) ⬇️
modules/notification/mail/mail.go 33.67% <0.00%> (-5.11%) ⬇️
modules/notification/base/null.go 76.31% <0.00%> (-2.64%) ⬇️
modules/notification/notification.go 85.12% <0.00%> (-2.48%) ⬇️
modules/process/manager.go 72.83% <0.00%> (-2.47%) ⬇️
modules/queue/workerpool.go 51.64% <0.00%> (-1.10%) ⬇️
models/notification.go 65.18% <0.00%> (-0.89%) ⬇️
services/pull/pull.go 42.92% <0.00%> (-0.46%) ⬇️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1cd3017...b356a52. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 24, 2021
@a1012112796 a1012112796 added the topic/ui Change the appearance of the Gitea UI label Apr 25, 2021
@silverwind
Copy link
Member

silverwind commented Apr 26, 2021

Tested, did not work for me with this file because I think there is a off-by-one error in the code. So the code initializes a reader

readerSize := maxLineCharacters
input := bufio.NewReaderSize(reader, readerSize)

This reader is passed to parseHunks which then reads a chunk of maxLineCharacters characters and I think the if condition below can probably never be true because len(line) will at most be equal to maxLineCharacters.

lineBytes, isFragment, err = input.ReadLine()
line := string(lineBytes)

if len(line) > maxLineCharacters {

I think we need to use >=.

cc: @zeripath

@zeripath zeripath changed the title #7184 - file incomplete, specific message if because of too long line Display specific message if diff is not displayed because of too long line Apr 26, 2021
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 26, 2021
@Loutro
Copy link
Contributor Author

Loutro commented Apr 26, 2021

Tested, did not work for me with this file because I think there is a off-by-one error in the code. So the code initializes a reader

readerSize := maxLineCharacters
input := bufio.NewReaderSize(reader, readerSize)

This reader is passed to parseHunks which then reads a chunk of maxLineCharacters characters and I think the if condition below can probably never be true because len(line) will at most be equal to maxLineCharacters.

lineBytes, isFragment, err = input.ReadLine()
line := string(lineBytes)

if len(line) > maxLineCharacters {

I think we need to use >=.

cc: @zeripath

Thanks for the test.
Can we go with something like that:

readerSize := maxLineCharacters
	if readerSize < 4096 {
		readerSize = 4096
	} else {
		readerSize++
	}

If the line's length is superior to maxLineCharacters we get the new message.
But if length is equal, we display the file.

@zeripath
Copy link
Contributor

zeripath commented May 1, 2021

agh sorry I had thought that the OP had tried this so just looked at the proposed PR and thought it looked alright.

@zeripath
Copy link
Contributor

zeripath commented May 1, 2021

Right we want to look at how too long a line could cause IsIncomplete set. So the easiest thing to do is to look at all the places where IsIncomplete is set and see why that would occur:

if len(diff.Files) >= maxFiles {
diff.IsIncomplete = true

This is due to maxFiles - so this one is fine.

for {
for isFragment {
curFile.IsIncomplete = true
_, isFragment, err = input.ReadLine()
if err != nil {
// Now by the definition of ReadLine this cannot be io.EOF
err = fmt.Errorf("Unable to ReadLine: %v", err)
return
}
}

This one is due to a line that is so long that it is larger than the buffer can buffer. So this is one that needs to have the IncompleteLine flag set.

if curFileLinesCount >= maxLines {
curFile.IsIncomplete = true
continue
}

if curFileLinesCount >= maxLines {
curFile.IsIncomplete = true
continue
}

if curFileLinesCount >= maxLines {
curFile.IsIncomplete = true
continue
}

if curFileLinesCount >= maxLines {
curFile.IsIncomplete = true
continue

curFileLinesCount++
if curFileLinesCount >= maxLines {
curFile.IsIncomplete = true
continue

these are too many lines - so is fine.

if isFragment {
curFile.IsIncomplete = true
for isFragment {
lineBytes, isFragment, err = input.ReadLine()
if err != nil {
// Now by the definition of ReadLine this cannot be io.EOF
err = fmt.Errorf("Unable to ReadLine: %v", err)
return
}
}
}

This one is due to a line that is so long that it is larger than the buffer can buffer. So this is one that needs to have the IncompleteLine flag set.

if len(line) > maxLineCharacters {
curFile.IsIncomplete = true
line = line[:maxLineCharacters]
}

This is a line that although less than the buffer is still too long for the maxLineCharacters setting so it needs the flag.

@Loutro there are therefore two other places you need to set this flag - which I have set in 263f33c

Signed-off-by: Andrew Thornton <[email protected]>
@zeripath
Copy link
Contributor

zeripath commented May 1, 2021

I've just pushed those two missing cases up to your branch.

@silverwind please feel free to test again.

@Loutro
Copy link
Contributor Author

Loutro commented May 3, 2021

@zeripath , If i understand well, The cases you added are useful if you are in error because you will never go on this check:
if len(line) > maxLineCharacters
But i suppose an error could occur for many things, not only a buffer problem. if it's why we want here it's ok, or we could provide a specific message to the user ("an error occured patati patata").

If there is no error in reading the file, the solution i provided works.

	if readerSize < 4096 {
		readerSize = 4096
	} else {
		readerSize++
	}


@silverwind
Copy link
Member

Current solution works for me now with my test case.

@zeripath
Copy link
Contributor

zeripath commented May 4, 2021

@Loutro I don't think you need that change - I don't understand how it is supposed to help.

@Loutro
Copy link
Contributor Author

Loutro commented May 4, 2021

@Loutro I don't think you need that change - I don't understand how it is supposed to help.

it help because on the condition below, your len(line) is maxLineCharacters + 1 if line too long.
if len(line) > maxLineCharacters {

Has i previously said, If the line's length is superior to maxLineCharacters we get the new message.
But if length is equal to maxLineCharacters (and that the important part) , we display the file.

I tested it and it worked for the test case of @silverwind.

But your solution seems ok, and perhap's seems cleaner to you.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels May 4, 2021
@zeripath zeripath merged commit 34b2162 into go-gitea:master May 4, 2021
@zeripath zeripath added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label May 4, 2021
@go-gitea go-gitea locked and limited conversation to collaborators Jun 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. topic/ui Change the appearance of the Gitea UI type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File diff suppressed because it is too large on a 82 line code file
6 participants