Skip to content

Commit

Permalink
fix: remove fallthrough switch statement (#1247)
Browse files Browse the repository at this point in the history
* chore: fix broken link in README.md (#1154)

* fix(react-native): fix for "<Intermediate Value>.stream is not a function" errors in React Native (#1156)

* chore: remove fallthrough switch statement

* docs: add @mmkal as a contributor

* docs: add @mmkal as a contributor

Co-authored-by: Xavier Francisco <xavier.n.francisco@gmail.com>
Co-authored-by: Corbin Crutchley <crutchcorn@gmail.com>
  • Loading branch information
3 people committed Jul 1, 2021
1 parent fca0a80 commit 04fa3d9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,15 @@
"code"
]
},
{
"login": "mmkal",
"name": "Misha Kaletsky",
"avatar_url": "https://avatars2.githubusercontent.com/u/15040698?v=4",
"profile": "https://github.com/mmkal",
"contributions": [
"code"
]
},
{
"login": "rczulch",
"name": "Richard C. Zulch",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
<td align="center"><a href="https://github.com/willstott101"><img src="https://avatars2.githubusercontent.com/u/335152?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Will Stott</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=willstott101" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=willstott101" title="Tests">⚠️</a></td>
<td align="center"><a href="http://mtnspring.org/"><img src="https://avatars2.githubusercontent.com/u/223277?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Seth Nickell</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/issues?q=author%3Asnickell" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://www.alextitarenko.me/"><img src="https://avatars0.githubusercontent.com/u/3290313?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Alex Titarenko</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=alex-titarenko" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/mmkal"><img src="https://avatars2.githubusercontent.com/u/15040698?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Misha Kaletsky</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=mmkal" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/rczulch"><img src="https://avatars1.githubusercontent.com/u/54646976?v=4?s=60" width="60px;" alt=""/><br /><sub><b>Richard C. Zulch</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=rczulch" title="Code">💻</a> <a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=rczulch" title="Documentation">📖</a></td>
<td align="center"><a href="https://scrapbox.io/mkizka/README"><img src="https://avatars.githubusercontent.com/u/30231179?v=4?s=60" width="60px;" alt=""/><br /><sub><b>mkizka</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/commits?author=mkizka" title="Code">💻</a></td>
<td align="center"><a href="https://ryotak.me/"><img src="https://avatars.githubusercontent.com/u/49341894?v=4?s=60" width="60px;" alt=""/><br /><sub><b>RyotaK</b></sub></a><br /><a href="https://github.com/isomorphic-git/isomorphic-git/issues?q=author%3ARy0taK" title="Bug reports">🐛</a></td>
Expand Down
53 changes: 24 additions & 29 deletions src/storage/readObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,31 @@ export async function _readObject({
return result
}

// BEHOLD! THE ONLY TIME I'VE EVER WANTED TO USE A CASE STATEMENT WITH FOLLOWTHROUGH!
// eslint-ignore
/* eslint-disable no-fallthrough */
switch (result.format) {
case 'deflated': {
result.object = Buffer.from(await inflate(result.object))
result.format = 'wrapped'
}
case 'wrapped': {
if (format === 'wrapped' && result.format === 'wrapped') {
return result
}
const sha = await shasum(result.object)
if (sha !== oid) {
throw new InternalError(
`SHA check failed! Expected ${oid}, computed ${sha}`
)
}
const { object, type } = GitObject.unwrap(result.object)
result.type = type
result.object = object
result.format = 'content'
}
case 'content': {
if (format === 'content') return result
break
if (result.format === 'deflated') {
result.object = Buffer.from(await inflate(result.object))
result.format = 'wrapped'
}

if (result.format === 'wrapped') {
if (format === 'wrapped' && result.format === 'wrapped') {
return result
}
default: {
throw new InternalError(`invalid format "${result.format}"`)
const sha = await shasum(result.object)
if (sha !== oid) {
throw new InternalError(
`SHA check failed! Expected ${oid}, computed ${sha}`
)
}
const { object, type } = GitObject.unwrap(result.object)
result.type = type
result.object = object
result.format = 'content'
}
/* eslint-enable no-fallthrough */

if (result.format === 'content') {
if (format === 'content') return result
return
}

throw new InternalError(`invalid format "${result.format}"`)
}

0 comments on commit 04fa3d9

Please sign in to comment.