diff --git a/modules/diferenco/unified_encoder.go b/modules/diferenco/unified_encoder.go index 39d35d0..a2430dc 100644 --- a/modules/diferenco/unified_encoder.go +++ b/modules/diferenco/unified_encoder.go @@ -194,7 +194,7 @@ func (e *UnifiedEncoder) writePatchHunk(b *strings.Builder, hunk *Hunk) { _, _ = b.WriteString(" +") _, _ = b.WriteString(strconv.Itoa(hunk.ToLine)) } - _, _ = b.WriteString("@@") + _, _ = b.WriteString(" @@") _, _ = b.WriteString(e.color.Reset(color.Frag)) _ = b.WriteByte('\n') for _, line := range hunk.Lines { diff --git a/utils/diff2/main.go b/utils/diff2/main.go new file mode 100644 index 0000000..d458ade --- /dev/null +++ b/utils/diff2/main.go @@ -0,0 +1,47 @@ +package main + +import ( + "context" + "fmt" + "os" + + "github.com/antgroup/hugescm/modules/diferenco" + "github.com/antgroup/hugescm/modules/diferenco/color" +) + +func main() { + if len(os.Args) < 3 { + fmt.Fprintf(os.Stderr, "usage: %s file1 file2\n", os.Args[0]) + return + } + fd1, err := os.Open(os.Args[1]) + if err != nil { + fmt.Fprintf(os.Stderr, "open file %s error: %v\n", os.Args[1], err) + return + } + defer fd1.Close() + fd2, err := os.Open(os.Args[2]) + if err != nil { + fmt.Fprintf(os.Stderr, "open file %s error: %v\n", os.Args[2], err) + return + } + defer fd2.Close() + + u, err := diferenco.DoUnified(context.Background(), &diferenco.Options{ + From: &diferenco.File{ + Path: os.Args[1], + }, + To: &diferenco.File{ + Path: os.Args[2], + }, + R1: fd1, + R2: fd2, + }) + if err != nil { + return + } + e := diferenco.NewUnifiedEncoder(os.Stderr) + e.SetColor(color.NewColorConfig()) + _ = e.Encode([]*diferenco.Unified{u}) + +}