This commit is contained in:
2025-08-15 07:41:10 +02:00
parent e030309b7f
commit e76f558f97
4 changed files with 15 additions and 18 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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

View File

@@ -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