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.
Example of how this looks in github. Note github gets the line count wrong because of how it deals with newlines.
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.
@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.
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.