mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
76 lines
1.8 KiB
Go
76 lines
1.8 KiB
Go
// Copyright 2026 Hanzo AI, Inc. 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
|
|
}
|