Harden a little bit
This commit is contained in:
parent
bb9d9c16eb
commit
cb6074ee27
2 changed files with 29 additions and 11 deletions
|
@ -13,6 +13,11 @@ func cmdHead(config configCollect) {
|
||||||
rc.CollectContent()
|
rc.CollectContent()
|
||||||
rc.BuildGraph()
|
rc.BuildGraph()
|
||||||
log.Println("Repo has", len(rc.Root), "sources")
|
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()
|
rc.FindLeafs()
|
||||||
log.Println("Repo has", len(rc.Leafs), "sinks")
|
log.Println("Repo has", len(rc.Leafs), "sinks")
|
||||||
|
|
35
commit.go
35
commit.go
|
@ -22,6 +22,7 @@ type RepoCommits struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommitNode struct {
|
type CommitNode struct {
|
||||||
|
Id string
|
||||||
Parents map[*CommitNode]Empty
|
Parents map[*CommitNode]Empty
|
||||||
Children map[*CommitNode]Empty
|
Children map[*CommitNode]Empty
|
||||||
Content Commit
|
Content Commit
|
||||||
|
@ -44,15 +45,23 @@ type Commit struct {
|
||||||
Version int `json:"version"`
|
Version int `json:"version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func nilable(s *string) string {
|
||||||
|
if s == nil {
|
||||||
|
return "<nil>"
|
||||||
|
} else {
|
||||||
|
return *s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c* Commit) String() string {
|
func (c* Commit) String() string {
|
||||||
return fmt.Sprintf(`RootId: %s
|
return fmt.Sprintf(`RootId: %v
|
||||||
CreatorName: %s
|
CreatorName: %v
|
||||||
Creator: %s
|
Creator: %v
|
||||||
Description: %s
|
Description: %v
|
||||||
Ctime: %s
|
Ctime: %v
|
||||||
RepoName: %s
|
RepoName: %v
|
||||||
RepoDesc: %s
|
RepoDesc: %v
|
||||||
`, *c.RootId, *c.CreatorName, *c.Creator, *c.Description, time.Unix(c.Ctime, 0), *c.RepoName, *c.RepoDesc)
|
`, 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 {
|
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 := new(CommitNode)
|
||||||
cn.Content = c
|
cn.Content = c
|
||||||
|
cn.Id = id
|
||||||
cn.Parents = make(map[*CommitNode]Empty)
|
cn.Parents = make(map[*CommitNode]Empty)
|
||||||
cn.Children = make(map[*CommitNode]Empty)
|
cn.Children = make(map[*CommitNode]Empty)
|
||||||
|
|
||||||
|
@ -96,8 +106,11 @@ func (rc* RepoCommits) CollectContent() {
|
||||||
if err != nil { log.Fatal(err) }
|
if err != nil { log.Fatal(err) }
|
||||||
|
|
||||||
var c Commit;
|
var c Commit;
|
||||||
json.Unmarshal(data, &c)
|
err := json.Unmarshal(data, &c)
|
||||||
rc.CommitContent[id] = NewCommitNode(c)
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
rc.CommitContent[id] = NewCommitNode(c,id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue