Skip to content

Commit

Permalink
diff: fix write hunk
Browse files Browse the repository at this point in the history
  • Loading branch information
fcharlie committed Dec 14, 2024
1 parent d136001 commit a639406
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/diferenco/unified_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
47 changes: 47 additions & 0 deletions utils/diff2/main.go
Original file line number Diff line number Diff line change
@@ -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})

}

0 comments on commit a639406

Please sign in to comment.