cpp-linter / cpp-linter-action

A Github Action for linting C/C++ code integrating clang-tidy and clang-format to collect feedback provided in the form of file-annotations, thread-comments, workflow step-summary, and Pull Request reviews.

Home Page:https://cpp-linter.github.io/cpp-linter-action/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG][v2.7.4] _pygit2.GitError: trailing data at line 3734

edunad opened this issue · comments

I just updated the version of the linter to the latest (v2.7.4) and it's giving out python errors

Traceback (most recent call last):
    File "/runner/_work/_actions/cpp-linter/cpp-linter-action/v2.7.4/venv/bin/cpp-linter", line 8, in <module>
      sys.exit(main())
               ^^^^^^
    File "/runner/_work/_actions/cpp-linter/cpp-linter-action/v2.7.4/venv/lib/python3.11/site-packages/cpp_linter/run.py", line 705, in main
      get_list_of_changed_files()
    File "/runner/_work/_actions/cpp-linter/cpp-linter-action/v2.7.4/venv/lib/python3.11/site-packages/cpp_linter/run.py", line 153, in get_list_of_changed_files
      Globals.FILES = parse_diff(Globals.response_buffer.text)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/runner/_work/_actions/cpp-linter/cpp-linter-action/v2.7.4/venv/lib/python3.11/site-packages/cpp_linter/git.py", line 89, in parse_diff
      diff_obj = Diff.parse_diff(diff_obj)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  _pygit2.GitError: trailing data at line 3734

https://github.com/edunad/rawrbox/pull/108/checks#step:9:641

the diff being parsed
full_pr.diff.txt

the diff chunk in question is:

diff --git a/render/content/fonts/SIL Open Font License.txt b/rawrbox.render/assets/fonts/SIL Open Font License.txt
similarity index 100%
rename from render/content/fonts/SIL Open Font License.txt
rename to rawrbox.render/assets/fonts/SIL Open Font License.txt

It looks like pygit2 (python wrapper for libgit2) doesn't like the spaces in this line:

rename from render/content/fonts/SIL Open Font License.txt

My first instinct is to massage the diff before passing it to pygit2.Diff.Parse_diff(), but that seems labor intensive (because of brute force using regular expression substitution).

I'm curious how git diff would output for commit edunad/rawrbox@efbcb07
I'm wondering

  1. Is github excluding quotes for file paths with spaces in the diff?
  2. Is libgit2 actually ill prepared to deal with filenames that have spaces?
  3. Is this problem even related to spaces in the file path/name? I need the git diff output to play with this more.

My first instinct is to massage the diff before passing it to pygit2.Diff.Parse_diff(), but that seems labor intensive (because of brute force using regular expression substitution).

I'm curious how git diff would output for commit edunad/rawrbox@efbcb07 I'm wondering

  1. Is github excluding quotes for file paths with spaces in the diff?
  2. Is libgit2 actually ill prepared to deal with filenames that have spaces?
  3. Is this problem even related to spaces in the file path/name? I need the git diff output to play with this more.

Here's the git diff of that commit, hope it helps

efbcb07664e4fdce2249d1a15bbaded39454b6ce.txt

@edunad This might take me a while to diagnose and resolve. You can roll back to v2.7.2 as we switched to pygit2 in v2.7.3.

Caution

Any version before v2.7.3 might not work well with custom docker images. It usually shows as a pip error about installing to "system packages" in Linux...

@edunad This might take me a while to diagnose and resolve. You can roll back to v2.7.2 as we switched to pygit2 in v2.7.3.

[!CAUTION]
Any version before v2.7.3 might not work well with custom docker images. It usually shows as a pip error about installing to "system packages" in Linux...

Will do, thanks for the quick support! <3

I couldn't find that line in a local git diff output (for edunad/rawrbox@efbcb07). So, I just cloned the repo and did (in bash)

git diff bbb25e4474a56c6ffdcd0c85a8f79c16fc3ef5e5...HEAD > renamed.diff

The resulting did not add quotes around that line's filename, so the GitError was raised again.

I raised this issue upstream at libgit2/pygit2#1260.

I tried to parse the diff in the rust binding git2-rs and got the same error, so I think this a problem with libgit2 C library itself.

Does it only happen with renamed files? I can also confirm that downgrading to v2.7.2 works

As far as I can tell, yes.

v2.7.2 and earlier parsed the diff manually using pure python regex patterns. I don't want to go back to that (as a fall back approach), but if the response from libgit2 devs is too slow (or nonexistent) then I will.

v2.7.5 reintroduces the legacy approach (pure python regex) for parsing diff when pygit2 fails.

The workflow's logs will show when pygit2 fails and legacy parsing is used as a fallback.

I'm still tracking this bug... I have a unit test will fail when the bug is fixed. And there's the issue I raised upstream.