Skip to content

Commit 4d91f93

Browse files
committed
README: make it less experimental, add examples
1 parent 06eeb1d commit 4d91f93

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

README.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,47 @@
1-
Here is a partial port of python 3 difflib package. Its main goal was to
2-
make available a unified diff implementation, mostly for testing purposes.
1+
go-difflib
2+
==========
33

4-
The following class and functions have be ported:
4+
Go-difflib is a partial port of python 3 difflib package. Its main goal
5+
was to make unified and context diff available in pure Go, mostly for
6+
testing purposes.
7+
8+
The following class and functions (and related tests) have be ported:
59

610
* `SequenceMatcher`
711
* `unified_diff()`
812
* `context_diff()`
913

10-
Related doctests and unittests have been ported as well.
14+
## Installation
15+
16+
```bash
17+
$ go get github.com/pmezard/go-difflib/difflib
18+
```
19+
20+
### Quick Start
21+
22+
Diffs are configured with Unified (or ContextDiff) structures, and can
23+
be output to an io.Writer or returned as a string.
24+
25+
```Go
26+
diff := UnifiedDiff{
27+
A: difflib.SplitLines("foo\nbar\n"),
28+
B: difflib.SplitLines("foo\nbaz\n"),
29+
FromFile: "Original",
30+
ToFile: "Current",
31+
Context: 3,
32+
}
33+
text, _ := GetUnifiedDiffString(diff)
34+
fmt.Printf(text)
35+
```
36+
37+
would output:
38+
39+
```
40+
--- Original
41+
+++ Current
42+
@@ -1,3 +1,3 @@
43+
foo
44+
-bar
45+
+baz
46+
```
1147

12-
I have barely used to code yet so do not consider it being production-ready.
13-
The API is likely to evolve too.

difflib/difflib.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//
88
// - unified_diff
99
//
10+
// - context_diff
11+
//
1012
// Getting unified diffs was the main goal of the port. Keep in mind this code
1113
// is mostly suitable to output text differences in a human friendly way, there
1214
// are no guarantees generated diffs are consumable by patch(1).

0 commit comments

Comments
 (0)