diff --git a/.gitignore b/.gitignore index 3b735ec..6a472b4 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,18 @@ # Go workspace file go.work + +# idea +.idea + +# macos +.Ds_Store + +# temp data +cmd/srctx/*.json +cmd/srctx/*.csv +cmd/srctx/*.html +cmd/srctx/*.dot +/*.lsif +/src_darwin_amd64 +/srctx diff --git a/cmd/srctx/diff/core.go b/cmd/srctx/diff/core.go index 70589c6..75e953b 100644 --- a/cmd/srctx/diff/core.go +++ b/cmd/srctx/diff/core.go @@ -74,7 +74,7 @@ func createIndexFile(opts *Options) error { return nil } -func collectLineMap(opts *Options) (diff.AffectedLineMap, error) { +func collectLineMap(opts *Options) (diff.ImpactLineMap, error) { if !opts.NoDiff { lineMap, err := diff.GitDiff(opts.Src, opts.Before, opts.After) if err != nil { @@ -83,10 +83,10 @@ func collectLineMap(opts *Options) (diff.AffectedLineMap, error) { return lineMap, nil } log.Infof("noDiff enabled") - return make(diff.AffectedLineMap), nil + return make(diff.ImpactLineMap), nil } -func collectTotalLineCountMap(opts *Options, src string, lineMap diff.AffectedLineMap) (map[string]int, error) { +func collectTotalLineCountMap(opts *Options, src string, lineMap diff.ImpactLineMap) (map[string]int, error) { totalLineCountMap := make(map[string]int) var err error diff --git a/cmd/srctx/diff/core_file.go b/cmd/srctx/diff/core_file.go index b92ea13..61fec71 100644 --- a/cmd/srctx/diff/core_file.go +++ b/cmd/srctx/diff/core_file.go @@ -12,7 +12,7 @@ import ( "github.com/williamfzc/srctx/graph/file" ) -func fileLevelMain(opts *Options, lineMap diff.AffectedLineMap, totalLineCountMap map[string]int) error { +func fileLevelMain(opts *Options, lineMap diff.ImpactLineMap, totalLineCountMap map[string]int) error { log.Infof("file level main entry") fileGraph, err := createFileGraph(opts) if err != nil { @@ -35,8 +35,8 @@ func fileLevelMain(opts *Options, lineMap diff.AffectedLineMap, totalLineCountMa if totalLineCount, ok := totalLineCountMap[eachStat.FileName]; ok { wrappedStat.TotalLineCount = totalLineCount } - if affectedLineCount, ok := lineMap[eachStat.FileName]; ok { - wrappedStat.AffectedLineCount = len(affectedLineCount) + if impactLineCount, ok := lineMap[eachStat.FileName]; ok { + wrappedStat.ImpactLineCount = len(impactLineCount) } stats = append(stats, wrappedStat) log.Infof("start point: %v, refed: %d, ref: %d", eachPtr.Id(), len(eachStat.ReferencedIds), len(eachStat.ReferenceIds)) diff --git a/cmd/srctx/diff/core_func.go b/cmd/srctx/diff/core_func.go index b4cab5b..1749054 100644 --- a/cmd/srctx/diff/core_func.go +++ b/cmd/srctx/diff/core_func.go @@ -13,7 +13,7 @@ import ( "github.com/williamfzc/srctx/graph/visual/g6" ) -func funcLevelMain(opts *Options, lineMap diff.AffectedLineMap, totalLineCountMap map[string]int) error { +func funcLevelMain(opts *Options, lineMap diff.ImpactLineMap, totalLineCountMap map[string]int) error { log.Infof("func level main entry") // metadata funcGraph, err := createFuncGraph(opts) @@ -39,17 +39,17 @@ func funcLevelMain(opts *Options, lineMap diff.AffectedLineMap, totalLineCountMa wrappedStat := WrapImpactUnitWithFile(eachStat) totalLineCount := len(eachPtr.GetSpan().Lines()) - affectedLineCount := 0 + impactLineCount := 0 if lines, ok := lineMap[eachPtr.Path]; ok { for _, eachLine := range lines { if eachPtr.GetSpan().ContainLine(eachLine) { - affectedLineCount++ + impactLineCount++ } } } wrappedStat.TotalLineCount = totalLineCount - wrappedStat.AffectedLineCount = affectedLineCount + wrappedStat.ImpactLineCount = impactLineCount stats = append(stats, wrappedStat) log.Infof("start point: %v, refed: %d, ref: %d", eachPtr.Id(), len(eachStat.ReferencedIds), len(eachStat.ReferenceIds)) diff --git a/cmd/srctx/diff/objects.go b/cmd/srctx/diff/objects.go index 23e69e3..76d4eb1 100644 --- a/cmd/srctx/diff/objects.go +++ b/cmd/srctx/diff/objects.go @@ -107,14 +107,14 @@ type ImpactUnitWithFile struct { *object.ImpactUnit // line level impact - AffectedLineCount int `csv:"affectedLineCount" json:"affectedLineCount"` - TotalLineCount int `csv:"totalLineCount" json:"totalLineCount"` + ImpactLineCount int `csv:"impactLineCount" json:"impactLineCount"` + TotalLineCount int `csv:"totalLineCount" json:"totalLineCount"` } func WrapImpactUnitWithFile(impactUnit *object.ImpactUnit) *ImpactUnitWithFile { return &ImpactUnitWithFile{ - ImpactUnit: impactUnit, - AffectedLineCount: 0, - TotalLineCount: 0, + ImpactUnit: impactUnit, + ImpactLineCount: 0, + TotalLineCount: 0, } } diff --git a/diff/git.go b/diff/git.go index 0de24d7..f4e7cec 100644 --- a/diff/git.go +++ b/diff/git.go @@ -9,11 +9,11 @@ import ( log "github.com/sirupsen/logrus" ) -// file name -> lines -type AffectedLineMap = map[string][]int +// ImpactLineMap file name -> lines +type ImpactLineMap = map[string][]int -func GitDiff(rootDir string, before string, after string) (AffectedLineMap, error) { - // about why I use cmd rather than some libs +func GitDiff(rootDir string, before string, after string) (ImpactLineMap, error) { + // about why, I use cmd rather than some libs // because go-git 's patch has some bugs ... gitDiffCmd := exec.Command("git", "diff", before, after) gitDiffCmd.Dir = rootDir @@ -23,14 +23,14 @@ func GitDiff(rootDir string, before string, after string) (AffectedLineMap, erro return nil, err } - affected, err := Unified2Affected(data) + affected, err := Unified2Impact(data) if err != nil { return nil, err } return affected, nil } -func PathOffset(repoRoot string, srcRoot string, origin AffectedLineMap) (AffectedLineMap, error) { +func PathOffset(repoRoot string, srcRoot string, origin ImpactLineMap) (ImpactLineMap, error) { modifiedLineMap := make(map[string][]int) for file, lines := range origin { afterPath, err := PathOffsetOne(repoRoot, srcRoot, file) @@ -47,28 +47,28 @@ func PathOffsetOne(repoRoot string, srcRoot string, target string) (string, erro return filepath.Rel(srcRoot, absFile) } -func Unified2Affected(patch []byte) (AffectedLineMap, error) { +func Unified2Impact(patch []byte) (ImpactLineMap, error) { parsed, _, err := gitdiff.Parse(bytes.NewReader(patch)) if err != nil { return nil, err } - affectedMap := make(map[string][]int) + impactLineMap := make(ImpactLineMap) for _, each := range parsed { if each.IsBinary || each.IsDelete { continue } - affectedMap[each.NewName] = make([]int, 0) + impactLineMap[each.NewName] = make([]int, 0) fragments := each.TextFragments for _, eachF := range fragments { left := int(eachF.NewPosition) for i, eachLine := range eachF.Lines { if eachLine.New() && eachLine.Op == gitdiff.OpAdd { - affectedMap[each.NewName] = append(affectedMap[each.NewName], left+i-1) + impactLineMap[each.NewName] = append(impactLineMap[each.NewName], left+i-1) } } } } - return affectedMap, nil + return impactLineMap, nil } diff --git a/graph/file/api_stat.go b/graph/file/api_stat.go index 6f7b2f8..672c6dc 100644 --- a/graph/file/api_stat.go +++ b/graph/file/api_stat.go @@ -14,11 +14,11 @@ func (fg *Graph) Stat(f *Vertex) *object.ImpactUnit { impactUnit.FileName = f.Path impactUnit.UnitName = f.Id() - impactUnit.DirectConnectCount = len(referencedIds) + len(referenceIds) - impactUnit.InDirectConnectCount = len(transitiveReferenceIds) + len(transitiveReferencedIds) + impactUnit.ImpactCount = len(referencedIds) + len(referenceIds) + impactUnit.TransImpactCount = len(transitiveReferenceIds) + len(transitiveReferencedIds) impactUnit.TotalUnitCount = len(fg.IdCache) - impactUnit.AffectedEntries = len(fg.EntryIds(f)) + impactUnit.ImpactEntries = len(fg.EntryIds(f)) impactUnit.TotalEntriesCount = len(fg.ListEntries()) // details diff --git a/graph/function/api_stat.go b/graph/function/api_stat.go index 8d4a635..8fa39f7 100644 --- a/graph/function/api_stat.go +++ b/graph/function/api_stat.go @@ -14,11 +14,11 @@ func (fg *Graph) Stat(f *Vertex) *object.ImpactUnit { impactUnit.FileName = f.Path impactUnit.UnitName = f.Id() - impactUnit.DirectConnectCount = len(referencedIds) + len(referenceIds) - impactUnit.InDirectConnectCount = len(transitiveReferenceIds) + len(transitiveReferencedIds) + impactUnit.ImpactCount = len(referencedIds) + len(referenceIds) + impactUnit.TransImpactCount = len(transitiveReferenceIds) + len(transitiveReferencedIds) impactUnit.TotalUnitCount = len(fg.IdCache) - impactUnit.AffectedEntries = len(fg.EntryIds(f)) + impactUnit.ImpactEntries = len(fg.EntryIds(f)) impactUnit.TotalEntriesCount = len(fg.ListEntries()) // details @@ -29,3 +29,6 @@ func (fg *Graph) Stat(f *Vertex) *object.ImpactUnit { return impactUnit } + +func (fg *Graph) GlobalStat() { +} diff --git a/object/stat.go b/object/impact.go similarity index 75% rename from object/stat.go rename to object/impact.go index da830b0..154438c 100644 --- a/object/stat.go +++ b/object/impact.go @@ -16,12 +16,12 @@ type UnitImpactPart struct { UnitName string `csv:"unitName" json:"unitName"` // Heat - DirectConnectCount int `csv:"directConnectCount" json:"directConnectCount"` - InDirectConnectCount int `csv:"inDirectConnectCount" json:"inDirectConnectCount"` - TotalUnitCount int `csv:"totalUnitCount" json:"totalUnitCount"` + ImpactCount int `csv:"impactCount" json:"impactCount"` + TransImpactCount int `csv:"transImpactCount" json:"transImpactCount"` + TotalUnitCount int `csv:"totalUnitCount" json:"totalUnitCount"` // entries - AffectedEntries int `csv:"affectedEntries" json:"affectedEntries"` + ImpactEntries int `csv:"impactEntries" json:"impactEntries"` TotalEntriesCount int `csv:"totalEntriesCount" json:"totalEntriesCount"` } @@ -45,12 +45,12 @@ func NewImpactUnit() *ImpactUnit { FileName: "", }, UnitImpactPart: &UnitImpactPart{ - UnitName: "", - DirectConnectCount: 0, - InDirectConnectCount: 0, - TotalUnitCount: 0, - AffectedEntries: 0, - TotalEntriesCount: 0, + UnitName: "", + ImpactCount: 0, + TransImpactCount: 0, + TotalUnitCount: 0, + ImpactEntries: 0, + TotalEntriesCount: 0, }, ImpactDetails: &ImpactDetails{ ReferencedIds: make([]string, 0),