/
uzer_007
/
Rixea
Обзор
Документация
Войти
/
uzer_007
/
Rixea
Код
Запросы
0
Задачи
Вики
Пакеты
5
Релизы
2
CI/CD
Аналитика
Безопасность
master
modules/git/config_submodule.go
75 строк
2 KB
uzer_007
feat: первая версия Rixea
02 авг 2026, 22:16
02 авг 2026, 22:16
d4f7504
Код
Авторство
О чём код?
// Copyright 2026 Uzer_007. All rights reserved. // SPDX-License-Identifier: MIT package git import ( "bufio" "fmt" "io" "strings" ) // SubModule is a reference on git repository type SubModule struct { Path string URL string Branch string // this field is newly added but not really used } // configParseSubModules this is not a complete parse for gitmodules file, it only // parses the url and path of submodules. At the moment it only parses well-formed gitmodules files. // In the future, there should be a complete implementation of https://git-scm.com/docs/git-config#_syntax func configParseSubModules(r io.Reader) (*ObjectCache[*SubModule], error) { var subModule *SubModule subModules := newObjectCache[*SubModule]() scanner := bufio.NewScanner(r) for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) // Skip empty lines and comments if line == "" || strings.HasPrefix(line, "#") || strings.HasPrefix(line, ";") { continue } // Section header [section] if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") { if subModule != nil { subModules.Set(subModule.Path, subModule) } if strings.HasPrefix(line, "[submodule") { subModule = &SubModule{} } else { subModule = nil } continue } if subModule == nil { continue } parts := strings.SplitN(line, "=", 2) if len(parts) != 2 { continue } key := strings.TrimSpace(parts[0]) value := strings.TrimSpace(parts[1]) switch key { case "path": subModule.Path = value case "url": subModule.URL = value case "branch": subModule.Branch = value } } if err := scanner.Err(); err != nil { return nil, fmt.Errorf("error reading file: %w", err) } if subModule != nil { subModules.Set(subModule.Path, subModule) } return subModules, nil }