Skip to content
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

Fix diff skipping lines #13154

Merged
merged 10 commits into from
Oct 16, 2020

Conversation

zeripath
Copy link
Contributor

ParsePatch previously just skipped all lines that start with "+++ " or "--- "
and makes no attempt to see these lines in context.

This PR rewrites ParsePatch to pay attention to context and position
within a patch, ensuring that --- and +++ are only skipped if
appropriate.

This PR also fixes several issues with incomplete files.

Fix https://codeberg.org/Codeberg/Community/issues/308
Fix #13153

Signed-off-by: Andrew Thornton art27@cantab.net

ParsePatch previously just skipped all lines that start with "+++ " or "--- "
and makes no attempt to see these lines in context.

This PR rewrites ParsePatch to pay attention to context and position
within a patch, ensuring that --- and +++ are only skipped if
appropriate.

This PR also fixes several issues with incomplete files.

Fix https://codeberg.org/Codeberg/Community/issues/308
Fix go-gitea#13153

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath zeripath added this to the 1.14.0 milestone Oct 15, 2020
zeripath added a commit to zeripath/gitea that referenced this pull request Oct 15, 2020
Backport go-gitea#13154

ParsePatch previously just skipped all lines that start with "+++ " or "--- "
and makes no attempt to see these lines in context.

This PR rewrites ParsePatch to pay attention to context and position
within a patch, ensuring that --- and +++ are only skipped if
appropriate.

This PR also fixes several issues with incomplete files.

Fix https://codeberg.org/Codeberg/Community/issues/308
Fix go-gitea#13153

Signed-off-by: Andrew Thornton <art27@cantab.net>
zeripath added a commit to zeripath/gitea that referenced this pull request Oct 15, 2020
Backport go-gitea#13154

ParsePatch previously just skipped all lines that start with "+++ " or "--- "
and makes no attempt to see these lines in context.

This PR rewrites ParsePatch to pay attention to context and position
within a patch, ensuring that --- and +++ are only skipped if
appropriate.

This PR also fixes several issues with incomplete files.

Fix https://codeberg.org/Codeberg/Community/issues/308
Fix go-gitea#13153

Signed-off-by: Andrew Thornton <art27@cantab.net>
Copy link
Member

@techknowlogick techknowlogick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, thank you so much for this PR! I've been afraid of our diff parsing, and so I'm especially appreciative that you took this on. Second, would you hate me if I asked for tests, specifically ones for diffs with files that have lines that start with ++ and --?

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 15, 2020
@zeripath
Copy link
Contributor Author

Oh sorry I've spent so much time making the current tests pass I forgot to add the real one

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath
Copy link
Contributor Author

Done

services/gitdiff/gitdiff.go Outdated Show resolved Hide resolved
zeripath and others added 3 commits October 15, 2020 07:36
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
@codecov-io
Copy link

codecov-io commented Oct 15, 2020

Codecov Report

Merging #13154 into master will decrease coverage by 0.00%.
The diff coverage is 63.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #13154      +/-   ##
==========================================
- Coverage   42.04%   42.03%   -0.01%     
==========================================
  Files         681      681              
  Lines       75170    75220      +50     
==========================================
+ Hits        31605    31619      +14     
- Misses      38410    38438      +28     
- Partials     5155     5163       +8     
Impacted Files Coverage Δ
services/gitdiff/gitdiff.go 68.25% <63.18%> (-6.64%) ⬇️
modules/log/file.go 73.60% <0.00%> (-1.61%) ⬇️
services/pull/pull.go 41.27% <0.00%> (+0.49%) ⬆️
modules/git/repo.go 46.70% <0.00%> (+0.50%) ⬆️
models/gpg_key.go 53.90% <0.00%> (+0.57%) ⬆️
modules/log/event.go 59.90% <0.00%> (+0.94%) ⬆️
modules/git/utils.go 77.04% <0.00%> (+3.27%) ⬆️
modules/indexer/stats/db.go 60.86% <0.00%> (+8.69%) ⬆️

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 b222dbc...58389dc. Read the comment docs.

@lunny
Copy link
Member

lunny commented Oct 15, 2020

How about to use the package https://github.com/bluekeyes/go-gitdiff ?

@zeripath
Copy link
Contributor Author

That's not a backportable change and would require lots of other changes.

This isn't the last change I'm going to make to diff though and it's possible that that library could form part of it.

@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 Oct 16, 2020
@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 Oct 16, 2020
@techknowlogick techknowlogick merged commit 6bab678 into go-gitea:master Oct 16, 2020
@zeripath zeripath deleted the fix-13153-parsepatch-rewrite branch October 16, 2020 17:13
@techknowlogick techknowlogick added the backport/done All backports for this PR have been created label Oct 16, 2020
ivanvc added a commit to ivanvc/gitea that referenced this pull request Oct 16, 2020
…ments-in-pull-request-label-style

* origin/master:
  [skip ci] Updated translations via Crowdin
  Fix diff skipping lines (go-gitea#13154)
  Update go-version v1.2.3 -> v1.2.4 (go-gitea#13169)
  Vendor Update Go Libs (go-gitea#13166)
  Prevent panics with missing storage (go-gitea#13164)
  Improve users management through the CLI (go-gitea#6001) (go-gitea#10492)
  Change order of possible-owner organizations to alphabetical (go-gitea#13160)
  Slightly simplify the queue settings code to help reduce the risk of problems (go-gitea#12976)
  [Vendor] Update go-ldap to v3.2.4 (go-gitea#13163)
  [skip ci] Updated translations via Crowdin
  Update external-renderers.en-us.md (go-gitea#13165)
techknowlogick pushed a commit that referenced this pull request Oct 16, 2020
* Fix diff skipping lines

Backport #13154

ParsePatch previously just skipped all lines that start with "+++ " or "--- "
and makes no attempt to see these lines in context.

This PR rewrites ParsePatch to pay attention to context and position
within a patch, ensuring that --- and +++ are only skipped if
appropriate.

This PR also fixes several issues with incomplete files.

Fix https://codeberg.org/Codeberg/Community/issues/308
Fix #13153

Signed-off-by: Andrew Thornton <art27@cantab.net>

* Add testcase

Signed-off-by: Andrew Thornton <art27@cantab.net>

* fix comment

* simplify error handling

Signed-off-by: Andrew Thornton <art27@cantab.net>

* never return io.EOF

Signed-off-by: Andrew Thornton <art27@cantab.net>
techknowlogick added a commit that referenced this pull request Oct 17, 2020
* Fix diff skipping lines

Backport #13154

ParsePatch previously just skipped all lines that start with "+++ " or "--- "
and makes no attempt to see these lines in context.

This PR rewrites ParsePatch to pay attention to context and position
within a patch, ensuring that --- and +++ are only skipped if
appropriate.

This PR also fixes several issues with incomplete files.

Fix https://codeberg.org/Codeberg/Community/issues/308
Fix #13153

Signed-off-by: Andrew Thornton <art27@cantab.net>

* Add testcase

Signed-off-by: Andrew Thornton <art27@cantab.net>

* fix comment

* simplify error handling

Signed-off-by: Andrew Thornton <art27@cantab.net>

* never return io.EOF

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Diff skips lines starting with '++ ' or '-- '
6 participants