예제 #1
0
func testDiffFiles(t *testing.T, old, new string, level int) diff.Data {
	diffs, e := diff.Files(old, new, level)

	if e != nil {
		t.Fatal(e)
	}

	return diffs
}
예제 #2
0
파일: revision.go 프로젝트: shuLhan/wvcgen
/*
Diff given two list of old and new revision id, compare each of them and save
their diff (deletions and additions as single string joined by " ") on dataset.

The revision text will be looked up in directory `Dir` and with extension
".txt".
*/
func Diff(oldids, newids []string, ext string) (
	tabula.DatasetInterface,
	error,
) {
	diffset := &tabula.Dataset{
		Mode: tabula.DatasetModeColumns,
	}

	colAdds := tabula.NewColumn(tabula.TString, "additions")
	colDels := tabula.NewColumn(tabula.TString, "deletions")

	// Get minimum length
	minlen := len(oldids)
	newlen := len(newids)
	if newlen < minlen {
		minlen = newlen
	}

	for x := 0; x < minlen; x++ {
		oldrevid := Dir + "/" + oldids[x] + ext
		newrevid := Dir + "/" + newids[x] + ext

		diffs, e := diff.Files(oldrevid, newrevid, diff.LevelWords)
		if e != nil {
			return nil, e
		}

		dels := diffs.GetAllDels()
		delstr := dels.Join(" ")
		delrec, e := tabula.NewRecordBy(delstr, tabula.TString)

		if e != nil {
			return nil, e
		}

		adds := diffs.GetAllAdds()
		addstr := adds.Join(" ")
		addrec, e := tabula.NewRecordBy(addstr, tabula.TString)

		if e != nil {
			return nil, e
		}

		colDels.PushBack(delrec)
		colAdds.PushBack(addrec)
	}

	diffset.PushColumn(*colDels)
	diffset.PushColumn(*colAdds)

	return diffset, nil
}