From e76f558f972a2879595b5cb13a52947f518a313e Mon Sep 17 00:00:00 2001 From: despiegk Date: Fri, 15 Aug 2025 07:41:10 +0200 Subject: [PATCH] ... --- lib/develop/gittools/gitlocation.v | 2 +- lib/develop/gittools/gitstructure.v | 26 ++++++++++++------------- lib/develop/gittools/repository_load.v | 3 --- lib/develop/gittools/repository_model.v | 2 +- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/develop/gittools/gitlocation.v b/lib/develop/gittools/gitlocation.v index c1926583..77f567d0 100644 --- a/lib/develop/gittools/gitlocation.v +++ b/lib/develop/gittools/gitlocation.v @@ -32,7 +32,7 @@ pub fn (mut gs GitStructure) gitlocation_from_path(path string) !GitLocation { provider := parts[0] account := parts[1] name := parts[2] - mut repo_path := if parts.len > 3 { parts[3..].join('/') } else { '' } + mut repo_path := if parts.len > 3 { parts[3..].join('/') } else { "" } //this is for relative path in repo return GitLocation{ provider: provider diff --git a/lib/develop/gittools/gitstructure.v b/lib/develop/gittools/gitstructure.v index 1d09ec29..d2e0f97d 100644 --- a/lib/develop/gittools/gitstructure.v +++ b/lib/develop/gittools/gitstructure.v @@ -2,6 +2,7 @@ module gittools import crypto.md5 import freeflowuniverse.herolib.core.pathlib +import freeflowuniverse.herolib.ui.console import os import json @@ -37,7 +38,6 @@ pub fn (mut gitstructure GitStructure) load(reset bool) ! { if reset { gitstructure.cache_reset()! - $dbg; } for _, mut repo in gitstructure.repos { @@ -51,14 +51,18 @@ pub fn (mut gitstructure GitStructure) load(reset bool) ! { // - path (string): The path to search for repositories. // - processed_paths ([]string): List of already processed paths to avoid duplication. fn (mut gitstructure GitStructure) load_recursive(path string, mut processed_paths []string) ! { + + path_object := pathlib.get(path) relpath := path_object.path_relative(gitstructure.coderoot.path)! - // Limit the recursion depth to avoid deep directory traversal. - if relpath.count('/') > 4 { + // Limit the recursion depth to avoid deep directory traversal, because we have a predefined structure of git repo's. + if relpath.count('/') > 2 { return } + // console.print_debug("Loading git repositories from: ${path}, relpath:${relpath}") + items := os.ls(path) or { return error('Cannot load gitstructure because directory not found: ${path}') } @@ -67,10 +71,14 @@ fn (mut gitstructure GitStructure) load_recursive(path string, mut processed_pat current_path := os.join_path(path, item) if os.is_dir(current_path) { + excluded_dirs := ['node_modules', 'vendor', 'dist', 'build', 'bin', 'obj', 'target', 'tmp', 'temp'] + if item.starts_with('.') || item.starts_with('_') || excluded_dirs.contains(item) { + continue + } + if os.exists(os.join_path(current_path, '.git')) { // Initialize the repository from the current path. mut repo := gitstructure.repo_init_from_path_(current_path)! - // repo.status_update()! key_ := repo.cache_key() path_ := repo.path() @@ -85,9 +93,6 @@ fn (mut gitstructure GitStructure) load_recursive(path string, mut processed_pat continue } - if item.starts_with('.') || item.starts_with('_') { - continue - } // Recursively search in subdirectories. gitstructure.load_recursive(current_path, mut processed_paths)! } @@ -122,6 +127,7 @@ fn (mut gitstructure GitStructure) repo_init_from_path_(path string, params Repo // Retrieve GitLocation from the path. gl := gitstructure.gitlocation_from_path(mypath.path)! + console.print_debug("Initializing GitRepo from path: ${mypath.path}") // Initialize and return a GitRepo struct. mut r := GitRepo{ gs: &gitstructure @@ -180,9 +186,3 @@ pub fn (mut self GitStructure) cache_reset() ! { redis.del(key)! } } - -// Load config from redis -fn (mut self GitStructure) coderoot() !pathlib.Path { - mut coderoot := pathlib.get_dir(path: self.coderoot.path, create: true)! - return coderoot -} diff --git a/lib/develop/gittools/repository_load.v b/lib/develop/gittools/repository_load.v index 4744bdfc..3a6ec6b5 100644 --- a/lib/develop/gittools/repository_load.v +++ b/lib/develop/gittools/repository_load.v @@ -79,9 +79,6 @@ fn (mut repo GitRepo) load_internal() ! { // Persist the newly loaded state to the cache. repo.cache_set()! - // println(repo) - - $dbg; } // Helper to load remote tags diff --git a/lib/develop/gittools/repository_model.v b/lib/develop/gittools/repository_model.v index 41c50d8d..eea2b57f 100644 --- a/lib/develop/gittools/repository_model.v +++ b/lib/develop/gittools/repository_model.v @@ -6,7 +6,7 @@ module gittools pub struct GitRepo { // a git repo is always part of a git structure mut: - gs &GitStructure + gs &GitStructure @[skip; str: skip] last_load int // epoch when last loaded pub mut: provider string // e.g., github.com