Download internal/diff/diff.go from SaylorTwift/crush: direct link, hf CLI and curl.
- Browser
- Download file 692 Bytes
-
https://huggingface.co/SaylorTwift/crush/resolve/main/internal/diff/diff.go
- Command line
-
hf download hf://SaylorTwift/crush/internal/diff/diff.go
-
curl -L -o diff.go https://huggingface.co/SaylorTwift/crush/resolve/main/internal/diff/diff.go
692 Bytes
| package diff | |
| import ( | |
| "strings" | |
| "github.com/aymanbagabas/go-udiff" | |
| ) | |
| // GenerateDiff creates a unified diff from two file contents | |
| func GenerateDiff(beforeContent, afterContent, fileName string) (string, int, int) { | |
| fileName = strings.TrimPrefix(fileName, "/") | |
| var ( | |
| unified = udiff.Unified("a/"+fileName, "b/"+fileName, beforeContent, afterContent) | |
| additions = 0 | |
| removals = 0 | |
| ) | |
| lines := strings.SplitSeq(unified, "\n") | |
| for line := range lines { | |
| if strings.HasPrefix(line, "+") && !strings.HasPrefix(line, "+++") { | |
| additions++ | |
| } else if strings.HasPrefix(line, "-") && !strings.HasPrefix(line, "---") { | |
| removals++ | |
| } | |
| } | |
| return unified, additions, removals | |
| } | |