Skip to content

File history for renamed files, with '--follow' equivalent to show the complete history #34686

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

Chi-Iroh
Copy link

@Chi-Iroh Chi-Iroh commented Jun 10, 2025

Fixes #28253

Added a checkbox in the file history, so that we can toggle following renames.

I made a test repo, with a first commit creating a file, and a second one renaming it.
Here is what the history looks.

Rename following disabled :
image

Rename following enabled :
image

As a reminder, here's what it looks like now :
image

However, I have a question: I inserted a small spacing between the text and the checkbox, and as 1em and 1rem looked too big, I put 5px instead. Is it OK to use an absolute size in this context ?

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 10, 2025
@github-actions github-actions bot added modifies/translation modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/frontend labels Jun 10, 2025
Copy link
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

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

Thank you very much for the PR.

Although it needs more improvements to follow Gitea's code guideline, the idea is good enough.

I can help to make future improvements, before making more changes, I have some questions, see below.

}

// CommitsCount returns number of total commits of until given revision.
func CommitsCount(ctx context.Context, opts CommitsCountOptions) (int64, error) {
cmd := NewCommand("rev-list", "--count")
cmd := NewCommand("--no-pager", "log", "--pretty=format:%H")
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC "rev-list --count" was used intentionally because "log" is much slower (especially on a file with many commits)?

Copy link
Author

Choose a reason for hiding this comment

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

I indeed saw commit 58a4407 which made the change, but its comment says --follow is slow, and not git log on its own, so I assumed git log was OK. If not, I'll gladly use rev-list by default.

Copy link
Contributor

Choose a reason for hiding this comment

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

If "rev-list --count" works, please use it as much as possible.

Copy link
Author

@Chi-Iroh Chi-Iroh Jun 11, 2025

Choose a reason for hiding this comment

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

Fixed in 6bf3c18
With lint fixes in 5f324be

@@ -253,7 +264,7 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions)
Stdout: stdoutWriter,
Stderr: &stderr,
})
if err != nil {
if err != nil && err != io.ErrUnexpectedEOF {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why checking ErrUnexpectedEOF? When it would happen?

Copy link
Author

Choose a reason for hiding this comment

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

git log --pretty=format:%H output lacks a newline at the end, whereas git rev-list doesn't. So that's the fix I found to avoid error 500, please tell me if something better is needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think ErrUnexpectedEOF is right, ErrUnexpectedEOF only means something wrong happens, so it needs a clear fix.

Copy link
Author

@Chi-Iroh Chi-Iroh Jun 11, 2025

Choose a reason for hiding this comment

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

I guess the core issue is in modules/git/repo_commit.go:279-281 :

length := objectFormat.FullLength()
commits := []*Commit{}
shaline := make([]byte, length+1)

From what I understand, shaline is expected to have a length of the hash's length + 1, presumably for the newline. So at line 283 (n, err := io.ReadFull(stdoutReader, shaline)), when the last output line is reached, only length bytes are read, instead of the expected length + 1 bytes, so it triggers ErrUnexpectedEOF.

If an EOF happens after reading some but not all the bytes, ReadFull returns ErrUnexpectedEOF.
https://pkg.go.dev/io#ReadFull

@wxiaoguang
Copy link
Contributor

The commit history became a mess. Please follow git's manual to maintain the commits, and then force-push after fixing the problems.

And one more thing, when review starts and there is no special requirement, please avoid rebase&force-push.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/frontend modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/translation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File history for renamed files, with '--follow' equivalent to show the complete history
5 participants