|
|
|
@ -70,7 +70,7 @@ func (diff *Diff) NumFiles() int {
|
|
|
|
|
|
|
|
|
|
const DIFF_HEAD = "diff --git "
|
|
|
|
|
|
|
|
|
|
func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) {
|
|
|
|
|
func ParsePatch(pid int64, maxlines int, cmd *exec.Cmd, reader io.Reader) (*Diff, error) {
|
|
|
|
|
scanner := bufio.NewScanner(reader)
|
|
|
|
|
var (
|
|
|
|
|
curFile *DiffFile
|
|
|
|
@ -79,6 +79,7 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
leftLine, rightLine int
|
|
|
|
|
isTooLong bool
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
diff := &Diff{Files: make([]*DiffFile, 0)}
|
|
|
|
@ -90,16 +91,17 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if line == "" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = i + 1
|
|
|
|
|
|
|
|
|
|
// Diff data too large.
|
|
|
|
|
if i == 5000 {
|
|
|
|
|
// Diff data too large, we only show the first about maxlines lines
|
|
|
|
|
if i == maxlines {
|
|
|
|
|
isTooLong = true
|
|
|
|
|
log.Warn("Diff data too large")
|
|
|
|
|
return &Diff{}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if line == "" {
|
|
|
|
|
continue
|
|
|
|
|
//return &Diff{}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch {
|
|
|
|
@ -110,6 +112,10 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) {
|
|
|
|
|
curSection.Lines = append(curSection.Lines, diffLine)
|
|
|
|
|
continue
|
|
|
|
|
case line[0] == '@':
|
|
|
|
|
if isTooLong {
|
|
|
|
|
return diff, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curSection = &DiffSection{}
|
|
|
|
|
curFile.Sections = append(curFile.Sections, curSection)
|
|
|
|
|
ss := strings.Split(line, "@@")
|
|
|
|
@ -143,6 +149,10 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) {
|
|
|
|
|
|
|
|
|
|
// Get new file.
|
|
|
|
|
if strings.HasPrefix(line, DIFF_HEAD) {
|
|
|
|
|
if isTooLong {
|
|
|
|
|
return diff, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs := strings.Split(line[len(DIFF_HEAD):], " ")
|
|
|
|
|
a := fs[0]
|
|
|
|
|
|
|
|
|
@ -174,7 +184,7 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) {
|
|
|
|
|
return diff, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetDiffRange(repoPath, beforeCommitId string, afterCommitId string) (*Diff, error) {
|
|
|
|
|
func GetDiffRange(repoPath, beforeCommitId string, afterCommitId string, maxlines int) (*Diff, error) {
|
|
|
|
|
repo, err := git.OpenRepository(repoPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -228,9 +238,9 @@ func GetDiffRange(repoPath, beforeCommitId string, afterCommitId string) (*Diff,
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
return ParsePatch(pid, cmd, rd)
|
|
|
|
|
return ParsePatch(pid, maxlines, cmd, rd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func GetDiffCommit(repoPath, commitId string) (*Diff, error) {
|
|
|
|
|
return GetDiffRange(repoPath, "", commitId)
|
|
|
|
|
func GetDiffCommit(repoPath, commitId string, maxlines int) (*Diff, error) {
|
|
|
|
|
return GetDiffRange(repoPath, "", commitId, maxlines)
|
|
|
|
|
}
|
|
|
|
|