Skip to content

Commit 2edae66

Browse files
Rename the paramater structure for line-oriented diffing...
...so that it;s common to the context0diff and unified-diff cases.
1 parent 3189546 commit 2edae66

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

difflib/difflib.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ func formatRangeUnified(start, stop int) string {
791791
}
792792

793793
// Unified diff parameters
794-
type UnifiedDiff struct {
794+
type LineDiffParams struct {
795795
A []string // First sequence lines
796796
FromFile string // First file name
797797
FromDate string // First file time
@@ -821,7 +821,7 @@ type UnifiedDiff struct {
821821
// times. Any or all of these may be specified using strings for
822822
// 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'.
823823
// The modification times are normally expressed in the ISO 8601 format.
824-
func WriteUnifiedDiff(writer io.Writer, diff UnifiedDiff) error {
824+
func WriteUnifiedDiff(writer io.Writer, diff LineDiffParams) error {
825825
//buf := bufio.NewWriter(writer)
826826
//defer buf.Flush()
827827
var bld strings.Builder
@@ -902,7 +902,7 @@ func WriteUnifiedDiff(writer io.Writer, diff UnifiedDiff) error {
902902
}
903903

904904
// Like WriteUnifiedDiff but returns the diff a string.
905-
func GetUnifiedDiffString(diff UnifiedDiff) (string, error) {
905+
func GetUnifiedDiffString(diff LineDiffParams) (string, error) {
906906
w := &bytes.Buffer{}
907907
err := WriteUnifiedDiff(w, diff)
908908
return string(w.Bytes()), err
@@ -922,7 +922,9 @@ func formatRangeContext(start, stop int) string {
922922
return fmt.Sprintf("%d,%d", beginning, beginning+length-1)
923923
}
924924

925-
type ContextDiff UnifiedDiff
925+
// For backward compatibility. Ugh.
926+
type ContextDiff = LineDiffParams
927+
type UnifiedDiff = LineDiffParams
926928

927929
// Compare two sequences of lines; generate the delta as a context diff.
928930
//
@@ -1034,7 +1036,7 @@ func GetContextDiffString(diff ContextDiff) (string, error) {
10341036
}
10351037

10361038
// Split a string on "\n" while preserving them. The output can be used
1037-
// as input for UnifiedDiff and ContextDiff structures.
1039+
// as input for LineDiffParams.
10381040
func SplitLines(s string) []string {
10391041
lines := strings.SplitAfter(s, "\n")
10401042
lines[len(lines)-1] += "\n"

difflib/difflib_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fmt.Printf("%s,%T",a,b)`
121121
one
122122
three
123123
four`
124-
diff := UnifiedDiff{
124+
diff := LineDiffParams{
125125
A: SplitLines(a),
126126
B: SplitLines(b),
127127
FromFile: "Original",
@@ -274,7 +274,7 @@ func TestSFBugsRatioForNullSeqn(t *testing.T) {
274274
func TestSFBugsComparingEmptyLists(t *testing.T) {
275275
groups := NewMatcher(nil, nil).GetGroupedOpCodes(-1)
276276
assertEqual(t, len(groups), 0)
277-
diff := UnifiedDiff{
277+
diff := LineDiffParams{
278278
FromFile: "Original",
279279
ToFile: "Current",
280280
Context: 3,
@@ -326,7 +326,7 @@ func TestOutputFormatRangeFormatContext(t *testing.T) {
326326
}
327327

328328
func TestOutputFormatTabDelimiter(t *testing.T) {
329-
diff := UnifiedDiff{
329+
diff := LineDiffParams{
330330
A: splitChars("one"),
331331
B: splitChars("two"),
332332
FromFile: "Original",
@@ -350,7 +350,7 @@ func TestOutputFormatTabDelimiter(t *testing.T) {
350350
}
351351

352352
func TestOutputFormatNoTrailingTabOnEmptyFiledate(t *testing.T) {
353-
diff := UnifiedDiff{
353+
diff := LineDiffParams{
354354
A: splitChars("one"),
355355
B: splitChars("two"),
356356
FromFile: "Original",
@@ -367,7 +367,7 @@ func TestOutputFormatNoTrailingTabOnEmptyFiledate(t *testing.T) {
367367
}
368368

369369
func TestOmitFilenames(t *testing.T) {
370-
diff := UnifiedDiff{
370+
diff := LineDiffParams{
371371
A: SplitLines("o\nn\ne\n"),
372372
B: SplitLines("t\nw\no\n"),
373373
Eol: "\n",
@@ -600,7 +600,7 @@ func TestGetUnifiedDiffString(t *testing.T) {
600600
A := "one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\nnine\nten\n"
601601
B := "one\ntwo\nthr33\nfour\nfive\nsix\nseven\neight\nnine\nten\n"
602602
// Build diff
603-
diff := UnifiedDiff{A: SplitLines(A),
603+
diff := LineDiffParams{A: SplitLines(A),
604604
FromFile: "file", FromDate: "then",
605605
B: SplitLines(B),
606606
ToFile: "tile", ToDate: "now", Eol: "", Context: 1}

0 commit comments

Comments
 (0)