-
Notifications
You must be signed in to change notification settings - Fork 49
Fix parsing of non-extended file headers and lines starting with -- #55
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 parsing of non-extended file headers and lines starting with -- #55
Conversation
This fixes #54 by making the detection of non-extended file headers (which start with `---` directly) that was introduced in #53 more robust. Instead of simply aborting when the current line starts with `---` (which is a valid hunk line, if you, say, remove a line starting with `--`), we confirm that the next line also starts with `+++` by peeking a bit ahead. That's also what `git` does: https://sourcegraph.com/github.com/git/git/-/blob/apply.c#L1574-1576
Codecov Report
@@ Coverage Diff @@
## master #55 +/- ##
==========================================
- Coverage 75.99% 74.10% -1.89%
==========================================
Files 4 4
Lines 454 421 -33
==========================================
- Hits 345 312 -33
+ Misses 63 62 -1
- Partials 46 47 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, 2 inline questions
@@ -1,4 +1,3 @@ | ||
select 1; | ||
--- this is my query | ||
select 2; | ||
select 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1,4 +1,3 @@ | |
select 1; | |
--- this is my query | |
select 2; | |
select 3; | |
@@ -1,4 +1,3 @@ | |
select 1; | |
--- this is my query | |
+++ this could break? | |
select 2; | |
select 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that a case that works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean, with the fix here or in general?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the logic above that checks the next hunk line for +++
and fails if it finds it.
Like when I change a line prefix from --
to ++
, the diff would look like
line
---line
+++line
line
I guess. Would this be parseable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I use this diff, it crashes:
diff --git a/foobar.sql b/foobar.sql
index 9537d7b..f73c856 100644
--- a/foobar.sql
+++ b/foobar.sql
@@ -1,5 +1,5 @@
select 1;
--- this is my query
+++ this is my query
select 2;
select 3;
--- this is the last line
+++ this is the last line
I'll try to see if I can make that work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@keegancsmith @eseliger what do you think of this? #56
It adds a custom type, lineReader
, so we can do two-line lookahead and check whether the ---
and +++
are followed by a @@
, which is what git
does. It's built on top of this PR and all tests pass, including the case raised here by @eseliger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some inline comments, not approving just yet :)
I'm merging this and will take another stab at fixing the |
This fixes #54 by making the detection of non-extended file headers
(which start with
---
directly) that was introduced in #53 morerobust.
Instead of simply aborting when the current line starts with
---
(which is a valid hunk line, if you, say, remove a line starting with
--
), we confirm that the next line also starts with+++
by peeking abit ahead.
That's also what
git
does: https://sourcegraph.com/github.com/git/git/-/blob/apply.c#L1574-1576