{"id":16096488,"url":"https://github.com/aymanbagabas/go-udiff","last_synced_at":"2025-04-04T04:03:58.519Z","repository":{"id":153280150,"uuid":"628511376","full_name":"aymanbagabas/go-udiff","owner":"aymanbagabas","description":"µDiff - a micro Go diffing library","archived":false,"fork":false,"pushed_at":"2024-10-01T19:45:28.000Z","size":99,"stargazers_count":165,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-16T19:48:30.295Z","etag":null,"topics":["diff","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aymanbagabas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-BSD","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["aymanbagabas"],"patreon":"aymanbagabas","custom":["https://www.paypal.me/aymanbagabas","https://www.buymeacoffee.com/aymanbagabas"]}},"created_at":"2023-04-16T07:05:37.000Z","updated_at":"2024-10-09T18:37:16.000Z","dependencies_parsed_at":"2024-02-18T04:26:23.442Z","dependency_job_id":"f788f28e-ff43-48a3-9c85-55eab4b55197","html_url":"https://github.com/aymanbagabas/go-udiff","commit_stats":{"total_commits":47,"total_committers":4,"mean_commits":11.75,"dds":0.3191489361702128,"last_synced_commit":"47156b2dfa1fa02311b01be50b268a06ecd79597"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aymanbagabas%2Fgo-udiff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aymanbagabas%2Fgo-udiff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aymanbagabas%2Fgo-udiff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aymanbagabas%2Fgo-udiff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aymanbagabas","download_url":"https://codeload.github.com/aymanbagabas/go-udiff/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247112767,"owners_count":20885606,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["diff","go","golang"],"created_at":"2024-10-09T17:14:03.724Z","updated_at":"2025-04-04T04:03:58.491Z","avatar_url":"https://github.com/aymanbagabas.png","language":"Go","funding_links":["https://github.com/sponsors/aymanbagabas","https://patreon.com/aymanbagabas","https://www.paypal.me/aymanbagabas","https://www.buymeacoffee.com/aymanbagabas"],"categories":["Go"],"sub_categories":[],"readme":"# µDiff\n\n\u003cp\u003e\n\u003ca href=\"https://github.com/aymanbagabas/go-udiff/releases\"\u003e\u003cimg src=\"https://img.shields.io/github/release/aymanbagabas/go-udiff.svg\" alt=\"Latest Release\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pkg.go.dev/github.com/aymanbagabas/go-udiff?tab=doc\"\u003e\u003cimg src=\"https://godoc.org/github.com/golang/gddo?status.svg\" alt=\"Go Docs\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/aymanbagabas/go-udiff/actions\"\u003e\u003cimg src=\"https://github.com/aymanbagabas/go-udiff/workflows/build/badge.svg\" alt=\"Build Status\"\u003e\u003c/a\u003e\n\u003ca href=\"https://goreportcard.com/report/github.com/aymanbagabas/go-udiff\"\u003e\u003cimg alt=\"Go Report Card\" src=\"https://goreportcard.com/badge/github.com/aymanbagabas/go-udiff\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nMicro diff (µDiff) is a Go library that implements the\n[Myers'](http://www.xmailserver.org/diff2.pdf) diffing algorithm. It aims to\nprovide a minimal API to compute and apply diffs with zero dependencies. It\nalso supports generating diffs in the [Unified Format](https://www.gnu.org/software/diffutils/manual/html_node/Unified-Format.html).\nIf you are looking for a way to parse unified diffs, check out\n[sourcegraph/go-diff](https://github.com/sourcegraph/go-diff).\n\nThis is merely a copy of the [Golang tools internal diff package](https://github.com/golang/tools/tree/master/internal/diff)\nwith a few modifications to export package symbols. All credit goes to the [Go authors](https://go.dev/AUTHORS).\n\n## Usage\n\nYou can import the package using the following command:\n\n```bash\ngo get github.com/aymanbagabas/go-udiff\n```\n\n## Examples\n\nGenerate a unified diff for strings `a` and `b` with the default number of\ncontext lines (3). Use `udiff.ToUnified` to specify the number of context\nlines.\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n\n    \"github.com/aymanbagabas/go-udiff\"\n)\n\nfunc main() {\n    a := \"Hello, world!\\n\"\n    b := \"Hello, Go!\\nSay hi to µDiff\"\n    unified := udiff.Unified(\"a.txt\", \"b.txt\", a, b)\n    fmt.Println(unified)\n}\n```\n\n```\n--- a.txt\n+++ b.txt\n@@ -1 +1,2 @@\n-Hello, world!\n+Hello, Go!\n+Say hi to µDiff\n\\ No newline at end of file\n```\n\nApply changes to a string.\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n\n    \"github.com/aymanbagabas/go-udiff\"\n)\n\nfunc main() {\n    a := \"Hello, world!\\n\"\n    b := \"Hello, Go!\\nSay hi to µDiff\"\n\n    edits := udiff.Strings(a, b)\n    final, err := udiff.Apply(a, edits)\n    if err != nil {\n        panic(err)\n    }\n\n    fmt.Println(final)\n}\n```\n\n```\nHello, Go!\nSay hi to µDiff\n```\n\nTo get a line-by-line diff and edits:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n\n    \"github.com/aymanbagabas/go-udiff\"\n)\n\nfunc main() {\n    a := \"Hello, world!\\n\"\n    b := \"Hello, Go!\\nSay hi to µDiff\"\n\n    edits := udiff.Strings(a, b)\n    d, err := udiff.ToUnifiedDiff(\"a.txt\", \"b.txt\", a, edits, udiff.DefaultContextLines)\n    if err != nil {\n        panic(err)\n    }\n\n    for _, h := range d.Hunks {\n        fmt.Printf(\"hunk: -%d, +%d\\n\", h.FromLine, h.ToLine)\n        for _, l := range h.Lines {\n            fmt.Printf(\"%s %q\\n\", l.Kind, l.Content)\n        }\n    }\n}\n```\n\n```\nhunk: -1, +1\ndelete \"Hello, world!\\n\"\ninsert \"Hello, Go!\\n\"\ninsert \"Say hi to µDiff\"\n```\n\n## Alternatives\n\n- [sergi/go-diff](https://github.com/sergi/go-diff) No longer reliable. See [#123](https://github.com/sergi/go-diff/issues/123) and [#141](https://github.com/sergi/go-diff/pull/141).\n- [hexops/gotextdiff](https://github.com/hexops/gotextdiff) Takes the same approach but looks like the project is abandoned.\n- [sourcegraph/go-diff](https://github.com/sourcegraph/go-diff) It doesn't compute diffs. Great package for parsing and printing unified diffs.\n\n## Contributing\n\nPlease send any contributions [upstream](https://github.com/golang/tools). Pull\nrequests made against [the upstream diff package](https://github.com/golang/tools/tree/master/internal/diff)\nare welcome.\n\n## License\n\n[BSD 3-Clause](./LICENSE-BSD) and [MIT](./LICENSE-MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faymanbagabas%2Fgo-udiff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faymanbagabas%2Fgo-udiff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faymanbagabas%2Fgo-udiff/lists"}