diff --git a/command.go b/command.go index 3fd0827..2a8fa35 100644 --- a/command.go +++ b/command.go @@ -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") diff --git a/commit.go b/commit.go index a59c1db..b3ee445 100644 --- a/commit.go +++ b/commit.go @@ -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 "" + } 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) } }