Harden a little bit

This commit is contained in:
Quentin 2021-04-22 16:15:54 +02:00
parent bb9d9c16eb
commit cb6074ee27
Signed by: quentin
GPG key ID: A98E9B769E4FF428
2 changed files with 29 additions and 11 deletions

View file

@ -13,6 +13,11 @@ func cmdHead(config configCollect) {
rc.CollectContent()
rc.BuildGraph()
log.Println("Repo has", len(rc.Root), "sources")
if len(rc.Root) > 1 {
for cn, _ := range rc.Root {
log.Println("Commit "+cn.Id+"\n"+cn.Content.String())
}
}
rc.FindLeafs()
log.Println("Repo has", len(rc.Leafs), "sinks")

View file

@ -22,6 +22,7 @@ type RepoCommits struct {
}
type CommitNode struct {
Id string
Parents map[*CommitNode]Empty
Children map[*CommitNode]Empty
Content Commit
@ -44,15 +45,23 @@ type Commit struct {
Version int `json:"version"`
}
func nilable(s *string) string {
if s == nil {
return "<nil>"
} else {
return *s
}
}
func (c* Commit) String() string {
return fmt.Sprintf(`RootId: %s
CreatorName: %s
Creator: %s
Description: %s
Ctime: %s
RepoName: %s
RepoDesc: %s
`, *c.RootId, *c.CreatorName, *c.Creator, *c.Description, time.Unix(c.Ctime, 0), *c.RepoName, *c.RepoDesc)
return fmt.Sprintf(`RootId: %v
CreatorName: %v
Creator: %v
Description: %v
Ctime: %v
RepoName: %v
RepoDesc: %v
`, nilable(c.RootId), nilable(c.CreatorName), nilable(c.Creator), nilable(c.Description), time.Unix(c.Ctime, 0), nilable(c.RepoName), nilable(c.RepoDesc))
}
func NewRepoCommits (config configCollect) *RepoCommits {
@ -81,9 +90,10 @@ func (rc* RepoCommits) CollectDescs() {
}
}
func NewCommitNode(c Commit) *CommitNode {
func NewCommitNode(c Commit, id string) *CommitNode {
cn := new(CommitNode)
cn.Content = c
cn.Id = id
cn.Parents = make(map[*CommitNode]Empty)
cn.Children = make(map[*CommitNode]Empty)
@ -96,8 +106,11 @@ func (rc* RepoCommits) CollectContent() {
if err != nil { log.Fatal(err) }
var c Commit;
json.Unmarshal(data, &c)
rc.CommitContent[id] = NewCommitNode(c)
err := json.Unmarshal(data, &c)
if err != nil {
log.Fatal(err)
}
rc.CommitContent[id] = NewCommitNode(c,id)
}
}