Make it compile
This commit is contained in:
parent
3a27a0c146
commit
ac3a653442
@ -5,14 +5,14 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"container/list"
|
"container/list"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
"io"
|
"io"
|
||||||
"bufio"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gogits/git"
|
"github.com/gogits/git"
|
||||||
)
|
)
|
||||||
@ -228,17 +228,18 @@ func GetCommits(userName, reposName, branchname string) (*list.List, error) {
|
|||||||
return r.AllCommits()
|
return r.AllCommits()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Diff line types.
|
||||||
const (
|
const (
|
||||||
PlainLine = iota + 1
|
DIFF_LINE_PLAIN = iota + 1
|
||||||
AddLine
|
DIFF_LINE_ADD
|
||||||
DelLine
|
DIFF_LINE_DEL
|
||||||
SectionLine
|
DIFF_LINE_SECTION
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AddFile = iota + 1
|
DIFF_FILE_ADD = iota + 1
|
||||||
ChangeFile
|
DIFF_FILE_CHANGE
|
||||||
DelFile
|
DIFF_FILE_DEL
|
||||||
)
|
)
|
||||||
|
|
||||||
type DiffLine struct {
|
type DiffLine struct {
|
||||||
@ -269,15 +270,17 @@ func (diff *Diff) NumFiles() int {
|
|||||||
return len(diff.Files)
|
return len(diff.Files)
|
||||||
}
|
}
|
||||||
|
|
||||||
const diffHead = "diff --git "
|
const DIFF_HEAD = "diff --git "
|
||||||
|
|
||||||
func ParsePatch(reader io.Reader) (*Diff, error) {
|
func ParsePatch(reader io.Reader) (*Diff, error) {
|
||||||
scanner := bufio.NewScanner(reader)
|
scanner := bufio.NewScanner(reader)
|
||||||
var totalAdd, totalDel int
|
var totalAdd, totalDel int
|
||||||
var curFile *DiffFile
|
var curFile *DiffFile
|
||||||
var curSection * DiffSection
|
curSection := &DiffSection{
|
||||||
|
Lines: make([]*DiffLine, 0, 10),
|
||||||
|
}
|
||||||
//var leftLine, rightLine int
|
//var leftLine, rightLine int
|
||||||
diff := &Diff{Files:make([]*DiffFile, 0)}
|
diff := &Diff{Files: make([]*DiffFile, 0)}
|
||||||
var i int
|
var i int
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
@ -287,50 +290,48 @@ func ParsePatch(reader io.Reader) (*Diff, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if line[0] == ' ' {
|
if line[0] == ' ' {
|
||||||
diffLine := &DiffLine{Type: PlainLine, Content:line}
|
diffLine := &DiffLine{Type: DIFF_LINE_PLAIN, Content: line}
|
||||||
curSection.Lines = append(curSection.Lines, diffLine)
|
curSection.Lines = append(curSection.Lines, diffLine)
|
||||||
continue
|
continue
|
||||||
} else if line[0] == '@' {
|
} else if line[0] == '@' {
|
||||||
curSection = &DiffSection{}
|
curSection = &DiffSection{}
|
||||||
curFile.Sections = append(curFile.Sections, curSection)
|
curFile.Sections = append(curFile.Sections, curSection)
|
||||||
ss := strings.Split(line, "@@")
|
ss := strings.Split(line, "@@")
|
||||||
diffLine := &DiffLine{Type: SectionLine, Content:"@@ "+ss[len(ss)-2]}
|
diffLine := &DiffLine{Type: DIFF_LINE_SECTION, Content: "@@" + ss[len(ss)-2] + "@@"}
|
||||||
curSection.Lines = append(curSection.Lines, diffLine)
|
curSection.Lines = append(curSection.Lines, diffLine)
|
||||||
|
|
||||||
|
diffLine = &DiffLine{Type: DIFF_LINE_PLAIN, Content: ss[len(ss)-1]}
|
||||||
|
|
||||||
diffLine = &DiffLine{Type: PlainLine, Content:ss[len(ss)-1]}
|
|
||||||
curSection.Lines = append(curSection.Lines, diffLine)
|
curSection.Lines = append(curSection.Lines, diffLine)
|
||||||
continue
|
continue
|
||||||
} else if line[0] == '+' {
|
} else if line[0] == '+' {
|
||||||
diffLine := &DiffLine{Type: AddLine, Content:line}
|
diffLine := &DiffLine{Type: DIFF_LINE_ADD, Content: line}
|
||||||
curSection.Lines = append(curSection.Lines, diffLine)
|
curSection.Lines = append(curSection.Lines, diffLine)
|
||||||
continue
|
continue
|
||||||
} else if line[0] == '-' {
|
} else if line[0] == '-' {
|
||||||
diffLine := &DiffLine{Type: DelLine, Content:line}
|
diffLine := &DiffLine{Type: DIFF_LINE_DEL, Content: line}
|
||||||
curSection.Lines = append(curSection.Lines, diffLine)
|
curSection.Lines = append(curSection.Lines, diffLine)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(line, diffHead) {
|
if strings.HasPrefix(line, DIFF_HEAD) {
|
||||||
if curFile != nil {
|
if curFile != nil {
|
||||||
curFile.Addition, totalAdd = totalAdd, 0
|
curFile.Addition, totalAdd = totalAdd, 0
|
||||||
curFile.Deletion, totalDel = totalDel, 0
|
curFile.Deletion, totalDel = totalDel, 0
|
||||||
curFile = nil
|
curFile = nil
|
||||||
}
|
}
|
||||||
fs := strings.Split(line[len(diffHead):], " ")
|
fs := strings.Split(line[len(DIFF_HEAD):], " ")
|
||||||
a := fs[0]
|
a := fs[0]
|
||||||
|
|
||||||
curFile = &DiffFile{
|
curFile = &DiffFile{
|
||||||
Name:a[strings.Index(a, "/")+1:],
|
Name: a[strings.Index(a, "/")+1:],
|
||||||
Type: ChangeFile,
|
Type: DIFF_FILE_CHANGE,
|
||||||
Sections:make([]*DiffSection, 0),
|
Sections: make([]*DiffSection, 0),
|
||||||
}
|
}
|
||||||
diff.Files = append(diff.Files, curFile)
|
diff.Files = append(diff.Files, curFile)
|
||||||
scanner.Scan()
|
scanner.Scan()
|
||||||
scanner.Scan()
|
scanner.Scan()
|
||||||
if scanner.Text() == "--- /dev/null" {
|
if scanner.Text() == "--- /dev/null" {
|
||||||
curFile.Type = AddFile
|
curFile.Type = DIFF_FILE_ADD
|
||||||
}
|
}
|
||||||
scanner.Scan()
|
scanner.Scan()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user