Skip to content

Count removed SQL comment lines in software map diff counts - #1554

Open
connorburgess wants to merge 2 commits into
devdotfast:mainfrom
connorburgess:fix/software-map-dash-comments
Open

connorburgess wants to merge 2 commits into
devdotfast:mainfrom
connorburgess:fix/software-map-dash-comments

Conversation

@connorburgess

Copy link
Copy Markdown

I found this while reading how the software map turns a diff into per-element counts. A removed SQL, Lua or Haskell comment line such as -- old comment shows up in a git diff as --- old comment, and an added line that starts with ++ shows up as +++ .... splitGitDiff in packages/review/src/software-map-diff-counts.ts (lines 469-470) checks every line of a file section for --- and +++ , including lines inside hunks, so those rows were taken as file headers. With git diff -U0 of a file q.sql that removes -- old comment and adds ++ not really, q.sql got no counts on either side. With a hunk of -select 1;, --- c, +select 9;, the head side counted one deletion instead of two and the base side put the change on a file called c.

Now --- and +++ are only read as file names before the section's first @@ hunk header. Once a hunk starts, its +, -, space and \ rows stay hunk content until a line that is none of those (the next diff --git, or any other section start), so the headers of the following file are still read as headers.

The new test "counts hunk lines whose content starts with -- or ++ as changes" in software-map-diff-counts.test.ts uses that real git diff -U0 output followed by a second file, and checks both sides. It fails on main 4793780 (expected [ 'src/example.ts' ] to deeply equal [ 'q.sql', 'src/example.ts' ]) and passes on this branch. Checks on this branch: pnpm lint (Found 0 warnings and 0 errors), pnpm format:check (All matched files use the correct format), the CI typecheck pnpm -r --filter '!@dev.fast/review-desktop' --filter '!./diffr/**' --if-present typecheck (exit 0), and pnpm --filter @dev.fast/whiteboard test (Test Files 132 passed | 2 skipped, Tests 1352 passed | 8 skipped). Reproduced with real git output on macOS; covered by a Node test.

The desktop build (pnpm run ci) was not run here; CI runs it. This was not checked in an isolated Desktop.

Comment on lines +471 to +473
// Inside a hunk, "--- " and "+++ " are removed "-- " and added "++ "
// lines (SQL or Lua comments), not file headers.
current.inHunk = line.startsWith("@@")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this looks whack

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@thesiti92 assuming you mean the regex? yeah it's overkill. headers only show up before the first @@, so it can just be a flag that flips on there:

if (line.startsWith("@@")) current.inHunk = true;

the actual bug it's fixing is that a deleted SQL comment (-- foo) shows up in the diff as --- foo, and the parser was reading that as a file header and dropping/misattributing the change. happy to push that cleanup if you want the fix, or we can close it out

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

simplified in 3f55abc

…ader

File headers only appear before a file's first hunk, so the per-line
check for hunk-shaped content never changed the result.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants