|
|
@ -31,18 +31,18 @@ import ( |
|
|
|
type DiffLineType uint8 |
|
|
|
type DiffLineType uint8 |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
DIFF_LINE_PLAIN DiffLineType = iota + 1 |
|
|
|
DiffLinePlain DiffLineType = iota + 1 |
|
|
|
DIFF_LINE_ADD |
|
|
|
DiffLineAdd |
|
|
|
DIFF_LINE_DEL |
|
|
|
DiffLineDel |
|
|
|
DIFF_LINE_SECTION |
|
|
|
DIFF_LINE_SECTION |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type DiffFileType uint8 |
|
|
|
type DiffFileType uint8 |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
DIFF_FILE_ADD DiffFileType = iota + 1 |
|
|
|
DiffFileAdd DiffFileType = iota + 1 |
|
|
|
DIFF_FILE_CHANGE |
|
|
|
DiffFileChange |
|
|
|
DIFF_FILE_DEL |
|
|
|
DiffFileDel |
|
|
|
DIFF_FILE_RENAME |
|
|
|
DIFF_FILE_RENAME |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
@ -73,19 +73,19 @@ func diffToHTML(diffs []diffmatchpatch.Diff, lineType DiffLineType) template.HTM |
|
|
|
|
|
|
|
|
|
|
|
// Reproduce signs which are cutted for inline diff before.
|
|
|
|
// Reproduce signs which are cutted for inline diff before.
|
|
|
|
switch lineType { |
|
|
|
switch lineType { |
|
|
|
case DIFF_LINE_ADD: |
|
|
|
case DiffLineAdd: |
|
|
|
buf.WriteByte('+') |
|
|
|
buf.WriteByte('+') |
|
|
|
case DIFF_LINE_DEL: |
|
|
|
case DiffLineDel: |
|
|
|
buf.WriteByte('-') |
|
|
|
buf.WriteByte('-') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for i := range diffs { |
|
|
|
for i := range diffs { |
|
|
|
switch { |
|
|
|
switch { |
|
|
|
case diffs[i].Type == diffmatchpatch.DiffInsert && lineType == DIFF_LINE_ADD: |
|
|
|
case diffs[i].Type == diffmatchpatch.DiffInsert && lineType == DiffLineAdd: |
|
|
|
buf.Write(addedCodePrefix) |
|
|
|
buf.Write(addedCodePrefix) |
|
|
|
buf.WriteString(html.EscapeString(diffs[i].Text)) |
|
|
|
buf.WriteString(html.EscapeString(diffs[i].Text)) |
|
|
|
buf.Write(codeTagSuffix) |
|
|
|
buf.Write(codeTagSuffix) |
|
|
|
case diffs[i].Type == diffmatchpatch.DiffDelete && lineType == DIFF_LINE_DEL: |
|
|
|
case diffs[i].Type == diffmatchpatch.DiffDelete && lineType == DiffLineDel: |
|
|
|
buf.Write(removedCodePrefix) |
|
|
|
buf.Write(removedCodePrefix) |
|
|
|
buf.WriteString(html.EscapeString(diffs[i].Text)) |
|
|
|
buf.WriteString(html.EscapeString(diffs[i].Text)) |
|
|
|
buf.Write(codeTagSuffix) |
|
|
|
buf.Write(codeTagSuffix) |
|
|
@ -109,9 +109,9 @@ func (diffSection *DiffSection) GetLine(lineType DiffLineType, idx int) *DiffLin |
|
|
|
LOOP: |
|
|
|
LOOP: |
|
|
|
for _, diffLine := range diffSection.Lines { |
|
|
|
for _, diffLine := range diffSection.Lines { |
|
|
|
switch diffLine.Type { |
|
|
|
switch diffLine.Type { |
|
|
|
case DIFF_LINE_ADD: |
|
|
|
case DiffLineAdd: |
|
|
|
addCount++ |
|
|
|
addCount++ |
|
|
|
case DIFF_LINE_DEL: |
|
|
|
case DiffLineDel: |
|
|
|
delCount++ |
|
|
|
delCount++ |
|
|
|
default: |
|
|
|
default: |
|
|
|
if matchDiffLine != nil { |
|
|
|
if matchDiffLine != nil { |
|
|
@ -123,11 +123,11 @@ LOOP: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch lineType { |
|
|
|
switch lineType { |
|
|
|
case DIFF_LINE_DEL: |
|
|
|
case DiffLineDel: |
|
|
|
if diffLine.RightIdx == 0 && diffLine.LeftIdx == idx-difference { |
|
|
|
if diffLine.RightIdx == 0 && diffLine.LeftIdx == idx-difference { |
|
|
|
matchDiffLine = diffLine |
|
|
|
matchDiffLine = diffLine |
|
|
|
} |
|
|
|
} |
|
|
|
case DIFF_LINE_ADD: |
|
|
|
case DiffLineAdd: |
|
|
|
if diffLine.LeftIdx == 0 && diffLine.RightIdx == idx+difference { |
|
|
|
if diffLine.LeftIdx == 0 && diffLine.RightIdx == idx+difference { |
|
|
|
matchDiffLine = diffLine |
|
|
|
matchDiffLine = diffLine |
|
|
|
} |
|
|
|
} |
|
|
@ -159,15 +159,15 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine) tem |
|
|
|
|
|
|
|
|
|
|
|
// try to find equivalent diff line. ignore, otherwise
|
|
|
|
// try to find equivalent diff line. ignore, otherwise
|
|
|
|
switch diffLine.Type { |
|
|
|
switch diffLine.Type { |
|
|
|
case DIFF_LINE_ADD: |
|
|
|
case DiffLineAdd: |
|
|
|
compareDiffLine = diffSection.GetLine(DIFF_LINE_DEL, diffLine.RightIdx) |
|
|
|
compareDiffLine = diffSection.GetLine(DiffLineDel, diffLine.RightIdx) |
|
|
|
if compareDiffLine == nil { |
|
|
|
if compareDiffLine == nil { |
|
|
|
return template.HTML(html.EscapeString(diffLine.Content)) |
|
|
|
return template.HTML(html.EscapeString(diffLine.Content)) |
|
|
|
} |
|
|
|
} |
|
|
|
diff1 = compareDiffLine.Content |
|
|
|
diff1 = compareDiffLine.Content |
|
|
|
diff2 = diffLine.Content |
|
|
|
diff2 = diffLine.Content |
|
|
|
case DIFF_LINE_DEL: |
|
|
|
case DiffLineDel: |
|
|
|
compareDiffLine = diffSection.GetLine(DIFF_LINE_ADD, diffLine.LeftIdx) |
|
|
|
compareDiffLine = diffSection.GetLine(DiffLineAdd, diffLine.LeftIdx) |
|
|
|
if compareDiffLine == nil { |
|
|
|
if compareDiffLine == nil { |
|
|
|
return template.HTML(html.EscapeString(diffLine.Content)) |
|
|
|
return template.HTML(html.EscapeString(diffLine.Content)) |
|
|
|
} |
|
|
|
} |
|
|
@ -264,7 +264,7 @@ func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (* |
|
|
|
|
|
|
|
|
|
|
|
switch { |
|
|
|
switch { |
|
|
|
case line[0] == ' ': |
|
|
|
case line[0] == ' ': |
|
|
|
diffLine := &DiffLine{Type: DIFF_LINE_PLAIN, Content: line, LeftIdx: leftLine, RightIdx: rightLine} |
|
|
|
diffLine := &DiffLine{Type: DiffLinePlain, Content: line, LeftIdx: leftLine, RightIdx: rightLine} |
|
|
|
leftLine++ |
|
|
|
leftLine++ |
|
|
|
rightLine++ |
|
|
|
rightLine++ |
|
|
|
curSection.Lines = append(curSection.Lines, diffLine) |
|
|
|
curSection.Lines = append(curSection.Lines, diffLine) |
|
|
@ -289,14 +289,14 @@ func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (* |
|
|
|
case line[0] == '+': |
|
|
|
case line[0] == '+': |
|
|
|
curFile.Addition++ |
|
|
|
curFile.Addition++ |
|
|
|
diff.TotalAddition++ |
|
|
|
diff.TotalAddition++ |
|
|
|
diffLine := &DiffLine{Type: DIFF_LINE_ADD, Content: line, RightIdx: rightLine} |
|
|
|
diffLine := &DiffLine{Type: DiffLineAdd, Content: line, RightIdx: rightLine} |
|
|
|
rightLine++ |
|
|
|
rightLine++ |
|
|
|
curSection.Lines = append(curSection.Lines, diffLine) |
|
|
|
curSection.Lines = append(curSection.Lines, diffLine) |
|
|
|
continue |
|
|
|
continue |
|
|
|
case line[0] == '-': |
|
|
|
case line[0] == '-': |
|
|
|
curFile.Deletion++ |
|
|
|
curFile.Deletion++ |
|
|
|
diff.TotalDeletion++ |
|
|
|
diff.TotalDeletion++ |
|
|
|
diffLine := &DiffLine{Type: DIFF_LINE_DEL, Content: line, LeftIdx: leftLine} |
|
|
|
diffLine := &DiffLine{Type: DiffLineDel, Content: line, LeftIdx: leftLine} |
|
|
|
if leftLine > 0 { |
|
|
|
if leftLine > 0 { |
|
|
|
leftLine++ |
|
|
|
leftLine++ |
|
|
|
} |
|
|
|
} |
|
|
@ -330,7 +330,7 @@ func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (* |
|
|
|
curFile = &DiffFile{ |
|
|
|
curFile = &DiffFile{ |
|
|
|
Name: a, |
|
|
|
Name: a, |
|
|
|
Index: len(diff.Files) + 1, |
|
|
|
Index: len(diff.Files) + 1, |
|
|
|
Type: DIFF_FILE_CHANGE, |
|
|
|
Type: DiffFileChange, |
|
|
|
Sections: make([]*DiffSection, 0, 10), |
|
|
|
Sections: make([]*DiffSection, 0, 10), |
|
|
|
} |
|
|
|
} |
|
|
|
diff.Files = append(diff.Files, curFile) |
|
|
|
diff.Files = append(diff.Files, curFile) |
|
|
@ -354,13 +354,13 @@ func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (* |
|
|
|
|
|
|
|
|
|
|
|
switch { |
|
|
|
switch { |
|
|
|
case strings.HasPrefix(line, "new file"): |
|
|
|
case strings.HasPrefix(line, "new file"): |
|
|
|
curFile.Type = DIFF_FILE_ADD |
|
|
|
curFile.Type = DiffFileAdd |
|
|
|
curFile.IsCreated = true |
|
|
|
curFile.IsCreated = true |
|
|
|
case strings.HasPrefix(line, "deleted"): |
|
|
|
case strings.HasPrefix(line, "deleted"): |
|
|
|
curFile.Type = DIFF_FILE_DEL |
|
|
|
curFile.Type = DiffFileDel |
|
|
|
curFile.IsDeleted = true |
|
|
|
curFile.IsDeleted = true |
|
|
|
case strings.HasPrefix(line, "index"): |
|
|
|
case strings.HasPrefix(line, "index"): |
|
|
|
curFile.Type = DIFF_FILE_CHANGE |
|
|
|
curFile.Type = DiffFileChange |
|
|
|
case strings.HasPrefix(line, "similarity index 100%"): |
|
|
|
case strings.HasPrefix(line, "similarity index 100%"): |
|
|
|
curFile.Type = DIFF_FILE_RENAME |
|
|
|
curFile.Type = DIFF_FILE_RENAME |
|
|
|
curFile.IsRenamed = true |
|
|
|
curFile.IsRenamed = true |
|
|
@ -459,8 +459,8 @@ func GetDiffRange(repoPath, beforeCommitID, afterCommitID string, maxLines, maxL |
|
|
|
type RawDiffType string |
|
|
|
type RawDiffType string |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
RAW_DIFF_NORMAL RawDiffType = "diff" |
|
|
|
RawDiffNormal RawDiffType = "diff" |
|
|
|
RAW_DIFF_PATCH RawDiffType = "patch" |
|
|
|
RawDiffPatch RawDiffType = "patch" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// GetRawDiff dumps diff results of repository in given commit ID to io.Writer.
|
|
|
|
// GetRawDiff dumps diff results of repository in given commit ID to io.Writer.
|
|
|
@ -478,14 +478,14 @@ func GetRawDiff(repoPath, commitID string, diffType RawDiffType, writer io.Write |
|
|
|
|
|
|
|
|
|
|
|
var cmd *exec.Cmd |
|
|
|
var cmd *exec.Cmd |
|
|
|
switch diffType { |
|
|
|
switch diffType { |
|
|
|
case RAW_DIFF_NORMAL: |
|
|
|
case RawDiffNormal: |
|
|
|
if commit.ParentCount() == 0 { |
|
|
|
if commit.ParentCount() == 0 { |
|
|
|
cmd = exec.Command("git", "show", commitID) |
|
|
|
cmd = exec.Command("git", "show", commitID) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
c, _ := commit.Parent(0) |
|
|
|
c, _ := commit.Parent(0) |
|
|
|
cmd = exec.Command("git", "diff", "-M", c.ID.String(), commitID) |
|
|
|
cmd = exec.Command("git", "diff", "-M", c.ID.String(), commitID) |
|
|
|
} |
|
|
|
} |
|
|
|
case RAW_DIFF_PATCH: |
|
|
|
case RawDiffPatch: |
|
|
|
if commit.ParentCount() == 0 { |
|
|
|
if commit.ParentCount() == 0 { |
|
|
|
cmd = exec.Command("git", "format-patch", "--no-signature", "--stdout", "--root", commitID) |
|
|
|
cmd = exec.Command("git", "format-patch", "--no-signature", "--stdout", "--root", commitID) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|