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: chalk not parsing some git ref objects #241

Merged
merged 3 commits into from Mar 15, 2024
Merged

fix: chalk not parsing some git ref objects #241

merged 3 commits into from Mar 15, 2024

Conversation

miki725
Copy link
Contributor

@miki725 miki725 commented Mar 15, 2024

Issue

flaky tests such as https://github.com/crashappsec/chalk/actions/runs/8282914433/job/22664882760

Description

root was was there was unnecessary .strip() and sometimes git objects end with \n which is part of a compressed data-stream hence by removing it zips checksum wasnt able to validate which is why it was making some tests flaky which were asserting git plugin keys

Testing

looks like chalk v0.3.3 tag ends with newline so interact with chalk repo with that tag being present:

➜ cat .git/refs/tags/v0.3.3
fe750922dda1d33c407b41a7aeae7b17acdae78c

➜ cat .git/objects/fe/750922dda1d33c407b41a7aeae7b17acdae78c | hexdump -C | tail -n3
000002f0  c4 33 f5 7d af be 23 df  7d 1a f3 91 df 63 50 ac  |.3.}..#.}....cP.|
00000300  f3 df 26 f2 13 db 38 3e  0a                       |..&...8>.|
00000309

root was was there was unnecessary .strip() and sometimes git objects
end with `\n` which is part of a compressed data-stream hence by
removing it zips checksum wasnt able to validate which is why
it was making some tests flaky which were asserting git plugin keys
Copy link
Contributor

@ee7 ee7 left a comment

Choose a reason for hiding this comment

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

Looks good, although I still see one warning locally when just running nimble build. Do you? Any idea what's going on there?

Before this PR:

$ nimble build
[...]
warn:  unable to retrieve Git ref data: 045c6e2d6f357040991d2dd165e92dabafc0b6b0
warn:  unable to retrieve Git ref data: fe750922dda1d33c407b41a7aeae7b17acdae78c

With this PR:

$ nimble build
[...]
warn:  unable to retrieve Git ref data: 045c6e2d6f357040991d2dd165e92dabafc0b6b0 due to: invalid commit object
$ git show 045c6e2d6f357040991d2dd165e92dabafc0b6b0 | head
tag v0.2.1
Tagger: John Viega <john@zork.org>
Date:   Wed Oct 25 13:37:20 2023 -0400

Patch release.

commit bb1d5b0e10ffc692eb1e6945316a02a5e5f826eb
Author: John Viega <viega@users.noreply.github.com>
Date:   Wed Oct 25 13:32:55 2023 -0400

@miki725
Copy link
Contributor Author

miki725 commented Mar 15, 2024

hmm interesting. I dont get any warnings on this branch. let me try that commit directly

@miki725
Copy link
Contributor Author

miki725 commented Mar 15, 2024

invalid commit object only happens when that object is already packed. mine prolly isnt

viega
viega previously approved these changes Mar 15, 2024
ee7
ee7 previously approved these changes Mar 15, 2024
Copy link
Contributor

@ee7 ee7 left a comment

Choose a reason for hiding this comment

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

Yeah, I don't see either warning if I nimble build on a fresh git clone of this repo.

@miki725 miki725 dismissed stale reviews from ee7 and viega via a9925bd March 15, 2024 15:46
@miki725
Copy link
Contributor Author

miki725 commented Mar 15, 2024

@ee7 can you try with a9925bd (#241)

should work now

Copy link
Contributor

@ee7 ee7 left a comment

Choose a reason for hiding this comment

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

Yup, that resolves the remaining warning on my end. Thanks.

data = stream.readStr(initialReadSize)
byte = uint8(data[0])
objType = ((byte shr 4) and 7)
if not (objType == gitObjCommit or objType == gitObjTag):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if not (objType == gitObjCommit or objType == gitObjTag):
if objType notin [gitObjCommit, gitObjTag]:

Non-blocking suggestion: I personally find this more readable.

I also find that more readable than:

if objType != gitObjCommit and objType != gitObjTag:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

notin didnt seem to work with uint8 and int comparison although either way this is faster as it can do direct boolean logic vs scanning a list

cc @drraid we actually spoke about it with him while pairing on a fix as he wrote all the original logic for the packed files

Copy link
Contributor

@ee7 ee7 Mar 15, 2024

Choose a reason for hiding this comment

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

notin didnt seem to work with uint8 and int comparison

Oh, yes. We should probably have writen:

  gitObjCommit     = 1'u8
  gitObjTag        = 4'u8

or have a gitObjKind enum with values.

either way this is faster as it can do direct boolean logic vs scanning a list

Just FYI: The compiler can optimize it. But even in debug mode, the performance overhead there is orders of magnitude less than that of the unnecessary heap allocations in this file.

Consider:

const
  a = 1
  b = 4

proc foo(n: int): bool =
  n notin [a, b]

proc bar(n: int): bool =
  n != a and n != b

Compiling with -d:release, I see foo producing the instructions:

 endbr64
 cmp    rdi,0x1
 je     12 <foo+0x12>
 cmp    rdi,0x4
 setne  al
 ret
 xor    eax,eax
 ret
 data16 cs nop WORD PTR [rax+rax*1+0x0]

and bar producing:

 endbr64
 xor    eax,eax
 cmp    rdi,0x1
 je     33 <bar+0x13>
 cmp    rdi,0x4
 setne  al
 ret
 data16 cs nop WORD PTR [rax+rax*1+0x0]
 nop

@miki725 miki725 merged commit db8d129 into main Mar 15, 2024
2 checks passed
@miki725 miki725 deleted the ms/git branch March 15, 2024 16:08
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.

None yet

3 participants