Gitea: Show sloc count on file pages

Created on 14 Oct 2019  路  4Comments  路  Source: go-gitea/gitea

Description

Showing the SLoC (source lines of code) count for pages similar to how GitHub does would be very useful. This is in addition to the existing LoC (lines of code) count the same at GitHub.

Doing this in an accurate way is possible using https://github.com/boyter/scc/ and since it counts the LoC and SLoC in a single pass there is no performance impact. In fact since gitea currently does a strings.Split on newlines to get this metric it should be considerably faster.

I tried a quick implementation of this and it was reasonably simple to add the above functionality (see screenshots) but you could get additional count's of comments and blank lines as well. All I had to do was import the library, modify routers/repo/view.go, templates/repo/view_file.tmpl and options/locale/locale_en-US.ini to get this going. Although I suspect sloc is something that does not need to be internationalised(?)

Id be happy to assist with this and get it to PR status. I think it would be a good addition into gitea and brings its functionality into line with github. The code may also be useful to assist with guessing languages, but I have no looked at how that currently works so cannot comment in depth.

Screenshots

Example of how this looks in github. Note github gets the line count wrong because of how it deals with newlines.

image

The below is a quick example I put together using gitea and scc, please note that the line count matches the existing functionality, but includes the SLoC.

image

kinenhancement revieweconfirmed

Most helpful comment

Yes. I already have done 90% of the work. The only catch is that I could not see any way to get the name of the language. No idea if that is in there somewhere, but running it though the one in scc is no great chore.

Ill clean it up and send a PR.

All 4 comments

@boyter Could you send a PR to fix this?

Yes. I already have done 90% of the work. The only catch is that I could not see any way to get the name of the language. No idea if that is in there somewhere, but running it though the one in scc is no great chore.

Ill clean it up and send a PR.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

Ah the joy of talking a long break. Everything you were working on gets closed :)

Ill start work on this again in a few days.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BRMateus2 picture BRMateus2  路  3Comments

internalfx picture internalfx  路  3Comments

jorise7 picture jorise7  路  3Comments

tuxfanou picture tuxfanou  路  3Comments

lunny picture lunny  路  3Comments