-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
base: main
Are you sure you want to change the base?
Changes from 12 commits
32c1128
c8c1b33
816761b
4045bcb
7946a57
191c8a1
05eafb1
3ec59c3
96cb19e
64de337
e531f6c
e3e36af
e1b807f
6bf3c18
5f324be
6c44240
48cb4dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,22 +205,29 @@ func (repo *Repository) FileChangedBetweenCommits(filename, id1, id2 string) (bo | |
} | ||
|
||
// FileCommitsCount return the number of files at a revision | ||
func (repo *Repository) FileCommitsCount(revision, file string) (int64, error) { | ||
func (repo *Repository) FileCommitsCount(revision, file string, followRename ...bool) (int64, error) { | ||
_followRename := false | ||
if len(followRename) > 0 { | ||
_followRename = followRename[0] | ||
} | ||
|
||
return CommitsCount(repo.Ctx, | ||
CommitsCountOptions{ | ||
RepoPath: repo.Path, | ||
Revision: []string{revision}, | ||
RelPath: []string{file}, | ||
RepoPath: repo.Path, | ||
Revision: []string{revision}, | ||
RelPath: []string{file}, | ||
FollowRename: _followRename, | ||
}) | ||
} | ||
|
||
type CommitsByFileAndRangeOptions struct { | ||
Revision string | ||
File string | ||
Not string | ||
Page int | ||
Since string | ||
Until string | ||
Revision string | ||
File string | ||
Not string | ||
Page int | ||
Since string | ||
Until string | ||
FollowRename bool | ||
} | ||
|
||
// CommitsByFileAndRange return the commits according revision file and the page | ||
|
@@ -232,9 +239,13 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions) | |
}() | ||
go func() { | ||
stderr := strings.Builder{} | ||
gitCmd := NewCommand("rev-list"). | ||
gitCmd := NewCommand("--no-pager", "log"). | ||
AddOptionFormat("--pretty=format:%%H"). | ||
AddOptionFormat("--max-count=%d", setting.Git.CommitsRangeSize). | ||
AddOptionFormat("--skip=%d", (opts.Page-1)*setting.Git.CommitsRangeSize) | ||
if opts.FollowRename { | ||
gitCmd.AddOptionValues("--follow") | ||
} | ||
gitCmd.AddDynamicArguments(opts.Revision) | ||
|
||
if opts.Not != "" { | ||
|
@@ -253,7 +264,7 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions) | |
Stdout: stdoutWriter, | ||
Stderr: &stderr, | ||
}) | ||
if err != nil { | ||
if err != nil && err != io.ErrUnexpectedEOF { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why checking There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 (
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wxiaoguang So, do I need to change something, or ErrUnexpectedEOF is fine ? |
||
_ = stdoutWriter.CloseWithError(ConcatenateError(err, (&stderr).String())) | ||
} else { | ||
_ = stdoutWriter.Close() | ||
|
@@ -270,7 +281,7 @@ func (repo *Repository) CommitsByFileAndRange(opts CommitsByFileAndRangeOptions) | |
shaline := make([]byte, length+1) | ||
for { | ||
n, err := io.ReadFull(stdoutReader, shaline) | ||
if err != nil || n < length { | ||
if (err != nil && err != io.ErrUnexpectedEOF) || n < length { | ||
if err == io.EOF { | ||
err = nil | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.