-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Support displaying diff stats in PR tab bar #25387
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
Changes from 11 commits
789f4f9
d022a65
afb787d
f6301bf
2b8f325
26ec455
7f9a3e6
ec5a1cf
2093549
e59f3ae
eed9e57
7b34480
3c6004d
683396c
904c5e5
81978ad
b260c71
85cdc8d
4dee1d5
75ccb4f
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 |
---|---|---|
|
@@ -1229,6 +1229,42 @@ func GetDiff(gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff | |
return diff, nil | ||
} | ||
|
||
type PullDiffStats struct { | ||
TotalAddition, TotalDeletion int | ||
} | ||
|
||
// GetPullDiffStats | ||
func GetPullDiffStats(gitRepo *git.Repository, opts *DiffOptions) (*PullDiffStats, error) { | ||
repoPath := gitRepo.Path | ||
|
||
diff := &PullDiffStats{} | ||
|
||
separator := "..." | ||
if opts.DirectComparison { | ||
separator = ".." | ||
} | ||
|
||
diffPaths := []string{opts.BeforeCommitID + separator + opts.AfterCommitID} | ||
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. Could we use 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. This looks like it shouldn't be possible 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'm not sure |
||
if len(opts.BeforeCommitID) == 0 || opts.BeforeCommitID == git.EmptySHA { | ||
diffPaths = []string{git.EmptyTreeSHA, opts.AfterCommitID} | ||
} | ||
|
||
var err error | ||
|
||
_, diff.TotalAddition, diff.TotalDeletion, err = git.GetDiffShortStat(gitRepo.Ctx, repoPath, nil, diffPaths...) | ||
if err != nil && strings.Contains(err.Error(), "no merge base") { | ||
// git >= 2.28 now returns an error if base and head have become unrelated. | ||
// previously it would return the results of git diff --shortstat base head so let's try that... | ||
diffPaths = []string{opts.BeforeCommitID, opts.AfterCommitID} | ||
_, diff.TotalAddition, diff.TotalDeletion, err = git.GetDiffShortStat(gitRepo.Ctx, repoPath, nil, diffPaths...) | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return diff, nil | ||
} | ||
|
||
// SyncAndGetUserSpecificDiff is like GetDiff, except that user specific data such as which files the given user has already viewed on the given PR will also be set | ||
// Additionally, the database asynchronously is updated if files have changed since the last review | ||
func SyncAndGetUserSpecificDiff(ctx context.Context, userID int64, pull *issues_model.PullRequest, gitRepo *git.Repository, opts *DiffOptions, files ...string) (*Diff, error) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.