mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-12 02:24:21 -05:00
Show sloc count on file pages #4110
Open
opened 2025-11-02 05:38:34 -06:00 by GiteaMirror
·
18 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.16.3
v1.16.2
v1.16.1
v1.16.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.3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#4110
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @boyter on GitHub (Oct 14, 2019).
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.Spliton 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.tmplandoptions/locale/locale_en-US.inito 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.
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.
@lunny commented on GitHub (Oct 14, 2019):
@boyter Could you send a PR to fix this?
@boyter commented on GitHub (Oct 14, 2019):
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
sccis no great chore.Ill clean it up and send a PR.
@stale[bot] commented on GitHub (Dec 13, 2019):
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.
@boyter commented on GitHub (Jan 5, 2020):
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.
@nuno-silva commented on GitHub (Dec 29, 2021):
friendly ping on this :)
@wxiaoguang commented on GitHub (Apr 25, 2023):
Oops, sorry for wrong close
@yardenshoham commented on GitHub (Apr 29, 2023):
Is
slocjustlocminus number of empty lines?@wxiaoguang commented on GitHub (Apr 29, 2023):
https://github.com/wxiaoguang/playground/blob/main/test-highlight.cpp
69-line comments, 69 sloc.
But I don't understand whether it is helpful to end users (why people should care about it and how could it help readers).
I never paid attention on the sloc ....
@boyter commented on GitHub (Apr 30, 2023):
I guess it can be helpful to judge if a file is worthy of close inspection.
Its just another data point. However if you are going to include it you should attempt to have it as accurate as possible.
@wxiaoguang commented on GitHub (Apr 30, 2023):
Could you elaborate about how to "judge if a file is worthy of close inspection"? It's better to show some real cases. Personally I can't imagine a case how the SLoC works to help ..... because IMO people seldom fill a file with plenty of new lines, then SLoC roughly equals to LoC, the same magnitude.
@boyter commented on GitHub (May 1, 2023):
You are of course welcome to your opinion. My point remains however, if you are going to display sloc, it should be as accurate as you can get it since some people do get value out of it.
@wxiaoguang commented on GitHub (May 1, 2023):
I just like to learn from real cases, without a real case, it's difficult to understand the real world.
@boyter commented on GitHub (May 1, 2023):
@wxiaoguang I personally use it as another data point.
Ideally if you have it with the count of lines/comments/code/blanks you actually get more information. I think github displays the sloc because it gives an idea of how dense the file is. For example a file with lots of comments should have a lower sloc. Or a file with sloc matching the number of lines indicates a very dense file.
Its actually more useful if you can see it in a list, as you can help pinpoint files that might be worth refactoring or investigating compared to others in a codebase.
@wxiaoguang commented on GitHub (May 1, 2023):
Nope, see my test: https://github.com/wxiaoguang/playground/blob/main/test-highlight.cpp : 69-line comments, 69 sloc.
Since the "view file" is not a list page, so I can't get the point how it helps ....
@boyter commented on GitHub (May 1, 2023):
@wxiaoguang That's just an indicator of poor implementation by github. It would be far more useful for it to show the code count which is 0 for that case. You could then know without needing to scroll on a large file if there was any point to it.
@wxiaoguang commented on GitHub (May 1, 2023):
Actually, there is no standard definition for SLoC, or LoC, I do not think GitHub's implementation is poor.
https://en.wikipedia.org/wiki/Source_lines_of_code
There are a lot of arguments about how to count SLoC, eg: should comment be counted? http://www.projectcodemeter.com/cost_estimation/help/GL_sloc.htm
And some articles just suggest to include comments: https://pvs-studio.com/en/blog/terms/0086/
And stackoverflow says : https://stackoverflow.com/questions/3769716/how-bad-is-sloc-source-lines-of-code-as-a-metric
Especially, for many languages, the comment does its work, for example, PHP (annotation), and even Golang: https://cs.opensource.google/go/x/exp/+/master:ebnflint/doc.go (and including:
//go:build,//go:generate)So, IMO, in most cases, the SLoC is just for fun, only used for large projects to know "how large it is": millions SLoC, etc. It doesn't bring real benefit for code viewing or review.
@boyter commented on GitHub (May 1, 2023):
@wxiaoguang I disagree with your assessment but your opinion is just as valid as anyone else's.
@GiteaBot commented on GitHub (Sep 8, 2023):
We close issues that need feedback from the author if there were no new comments for a month. 🍵