From 1ce8a813150181ca9e3d06a517a6339788445d51 Mon Sep 17 00:00:00 2001 From: zongz Date: Mon, 23 Dec 2024 17:13:37 +0800 Subject: [PATCH] fix: rm useless comments and move clean deprecated methods Signed-off-by: zongz --- pkg/client/dependency_graph.go | 72 ---------------------------------- pkg/client/deperated.go | 68 ++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 72 deletions(-) delete mode 100644 pkg/client/dependency_graph.go diff --git a/pkg/client/dependency_graph.go b/pkg/client/dependency_graph.go deleted file mode 100644 index 9392f8d8..00000000 --- a/pkg/client/dependency_graph.go +++ /dev/null @@ -1,72 +0,0 @@ -// Deprecated: This package is deprecated and will be removed in a future release. -package client - -import pkg "kcl-lang.io/kpm/pkg/package" - -// Construct dependency graph -type DependencyGraph map[string][]string - -// Function to construct dependency graph by parsing kcl.mod file -func ConstructDependencyGraphFromModFile(kpmClient *KpmClient, kclPkg *pkg.KclPkg) (DependencyGraph, error) { - dependencies, err := kpmClient.ParseKclModFile(kclPkg) - if err != nil { - return nil, err - } - return ConstructDependencyGraph(dependencies), nil -} - -// Function to construct dependency graph from dependency map -func ConstructDependencyGraph(dependencies map[string]map[string]string) DependencyGraph { - graph := make(DependencyGraph) - for dependency, details := range dependencies { - // Construct full module path including version or other attributes - fullPath := dependency - if version, ok := details["version"]; ok { - fullPath += "@" + version - } else if gitURL, ok := details["git"]; ok { - fullPath += "@" + gitURL - if tag, ok := details["tag"]; ok { - fullPath += "#" + tag - } else if commit, ok := details["commit"]; ok { - fullPath += "@" + commit - } - } else if path, ok := details["path"]; ok { - fullPath += "@" + path - } - graph[fullPath] = make([]string, 0) - } - return graph -} - -// Traverse dependency graph using depth-first search (DFS) -func DFS(graph DependencyGraph, dependency string, visited map[string]bool, result []string) []string { - // Mark current dependency as visited - visited[dependency] = true - - // Add current dependency to result - result = append(result, dependency) - - // Recursively traverse dependencies - for _, dep := range graph[dependency] { - if !visited[dep] { - result = DFS(graph, dep, visited, result) - } - } - - return result -} - -// Output dependencies in the same format as go mod graph -func OutputDependencies(graph DependencyGraph) []string { - result := make([]string, 0) - visited := make(map[string]bool) - - // Traverse each dependency using DFS - for dependency := range graph { - if !visited[dependency] { - result = DFS(graph, dependency, visited, result) - } - } - - return result -} diff --git a/pkg/client/deperated.go b/pkg/client/deperated.go index cceb3f2f..db915851 100644 --- a/pkg/client/deperated.go +++ b/pkg/client/deperated.go @@ -1464,3 +1464,71 @@ func (c *KpmClient) LoadPkgFromPath(path string) (*pkg.KclPkg, error) { pkg.WithSettings(&c.settings), ) } + +// Construct dependency graph +type DependencyGraph map[string][]string + +// Function to construct dependency graph by parsing kcl.mod file +func ConstructDependencyGraphFromModFile(kpmClient *KpmClient, kclPkg *pkg.KclPkg) (DependencyGraph, error) { + dependencies, err := kpmClient.ParseKclModFile(kclPkg) + if err != nil { + return nil, err + } + return ConstructDependencyGraph(dependencies), nil +} + +// Function to construct dependency graph from dependency map +func ConstructDependencyGraph(dependencies map[string]map[string]string) DependencyGraph { + graph := make(DependencyGraph) + for dependency, details := range dependencies { + // Construct full module path including version or other attributes + fullPath := dependency + if version, ok := details["version"]; ok { + fullPath += "@" + version + } else if gitURL, ok := details["git"]; ok { + fullPath += "@" + gitURL + if tag, ok := details["tag"]; ok { + fullPath += "#" + tag + } else if commit, ok := details["commit"]; ok { + fullPath += "@" + commit + } + } else if path, ok := details["path"]; ok { + fullPath += "@" + path + } + graph[fullPath] = make([]string, 0) + } + return graph +} + +// Traverse dependency graph using depth-first search (DFS) +func DFS(graph DependencyGraph, dependency string, visited map[string]bool, result []string) []string { + // Mark current dependency as visited + visited[dependency] = true + + // Add current dependency to result + result = append(result, dependency) + + // Recursively traverse dependencies + for _, dep := range graph[dependency] { + if !visited[dep] { + result = DFS(graph, dep, visited, result) + } + } + + return result +} + +// Output dependencies in the same format as go mod graph +func OutputDependencies(graph DependencyGraph) []string { + result := make([]string, 0) + visited := make(map[string]bool) + + // Traverse each dependency using DFS + for dependency := range graph { + if !visited[dependency] { + result = DFS(graph, dependency, visited, result) + } + } + + return result +}