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

Method DiffVCS

texteditor/diffbrowser/vcs.go:26–118  ·  view source on GitHub ↗

DiffVCS creates a tree of files changed in given revision.

(repo vcs.Repo, revA, revB string)

Source from the content-addressed store, hash-verified

24
25// DiffVCS creates a tree of files changed in given revision.
26func (br *Browser) DiffVCS(repo vcs.Repo, revA, revB string) {
27 cinfo, err := repo.FilesChanged(revA, revB, false)
28 if err != nil {
29 slog.Error(err.Error())
30 return
31 }
32 br.PathA = repo.LocalPath()
33 br.PathB = br.PathA
34 files := stringsx.SplitLines(string(cinfo))
35 tv := br.Tree()
36 tv.SetText(fsx.DirAndFile(br.PathA))
37 cdir := ""
38 var cdirs []string
39 var cnodes []*Node
40 root := br.Tree()
41 for _, fl := range files {
42 fd := strings.Fields(fl)
43 if len(fd) < 2 {
44 continue
45 }
46 status := fd[0]
47 if len(status) > 1 {
48 status = status[:1]
49 }
50 fpa := fd[1]
51 fpb := fpa
52 if len(fd) == 3 {
53 fpb = fd[2]
54 }
55 fp := fpb
56 dir, fn := filepath.Split(fp)
57 dir = filepath.Dir(dir)
58 if dir != cdir {
59 dirs := strings.Split(dir, "/")
60 nd := len(dirs)
61 mn := min(len(cdirs), nd)
62 di := 0
63 for i := 0; i < mn; i++ {
64 if cdirs[i] != dirs[i] {
65 break
66 } else {
67 di = i
68 }
69 }
70 cnodes = cnodes[:di]
71 for i := di; i < nd; i++ {
72 var nn *Node
73 if i == 0 {
74 nn = NewNode(root)
75 } else {
76 nn = NewNode(cnodes[i-1])
77 }
78 dp := filepath.Join(br.PathA, filepath.Join(dirs[:i+1]...))
79 nn.SetFileA(dp).SetFileB(dp)
80 nn.SetText(dirs[i])
81 cnodes = append(cnodes, nn)
82 }
83 cdir = dir

Callers 1

NewDiffBrowserVCSFunction · 0.80

Calls 15

TreeMethod · 0.95
SetFileAMethod · 0.95
SetTextBMethod · 0.95
SetTextAMethod · 0.95
SplitLinesFunction · 0.92
DirAndFileFunction · 0.92
SplitMethod · 0.80
SetStatusMethod · 0.80
SetRevBMethod · 0.80
SetRevAMethod · 0.80
InitFileMethod · 0.80
NewNodeFunction · 0.70

Tested by

no test coverage detected