MCPcopy Create free account
hub / github.com/cogentcore/core / DiffEditorDialogFromRevs

Function DiffEditorDialogFromRevs

texteditor/diffeditor.go:55–86  ·  view source on GitHub ↗

DiffEditorDialogFromRevs opens a dialog for displaying diff between file at two different revisions from given repository if empty, defaults to: A = current HEAD, B = current WC file. -1, -2 etc also work as universal ways of specifying prior revisions.

(ctx core.Widget, repo vcs.Repo, file string, fbuf *Buffer, rev_a, rev_b string)

Source from the content-addressed store, hash-verified

53// if empty, defaults to: A = current HEAD, B = current WC file.
54// -1, -2 etc also work as universal ways of specifying prior revisions.
55func DiffEditorDialogFromRevs(ctx core.Widget, repo vcs.Repo, file string, fbuf *Buffer, rev_a, rev_b string) (*DiffEditor, error) {
56 var astr, bstr []string
57 if rev_b == "" { // default to current file
58 if fbuf != nil {
59 bstr = fbuf.Strings(false)
60 } else {
61 fb, err := text.FileBytes(file)
62 if err != nil {
63 core.ErrorDialog(ctx, err)
64 return nil, err
65 }
66 bstr = text.BytesToLineStrings(fb, false) // don't add new lines
67 }
68 } else {
69 fb, err := repo.FileContents(file, rev_b)
70 if err != nil {
71 core.ErrorDialog(ctx, err)
72 return nil, err
73 }
74 bstr = text.BytesToLineStrings(fb, false) // don't add new lines
75 }
76 fb, err := repo.FileContents(file, rev_a)
77 if err != nil {
78 core.ErrorDialog(ctx, err)
79 return nil, err
80 }
81 astr = text.BytesToLineStrings(fb, false) // don't add new lines
82 if rev_a == "" {
83 rev_a = "HEAD"
84 }
85 return DiffEditorDialog(ctx, "DiffVcs: "+fsx.DirAndFile(file), astr, bstr, file, file, rev_a, rev_b), nil
86}
87
88// DiffEditorDialog opens a dialog for displaying diff between two files as line-strings
89func DiffEditorDialog(ctx core.Widget, title string, astr, bstr []string, afile, bfile, arev, brev string) *DiffEditor {

Callers 2

diffVCSMethod · 0.92
makeToolbarMethod · 0.92

Calls 7

FileBytesFunction · 0.92
ErrorDialogFunction · 0.92
BytesToLineStringsFunction · 0.92
DirAndFileFunction · 0.92
DiffEditorDialogFunction · 0.85
FileContentsMethod · 0.65
StringsMethod · 0.45

Tested by

no test coverage detected