diff --git a/commit.go b/commit.go index 3835322..a97762d 100644 --- a/commit.go +++ b/commit.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "log" "io/ioutil" "path/filepath" @@ -10,6 +11,13 @@ type RepoCommits struct { Config configCollect CommitDesc map[string]string CommitContent map[string]Commit + Head *CommitNode +} + +type CommitNode struct { + Parents []*CommitNode + Children []*CommitNode + Content Commit } type Commit struct { @@ -31,8 +39,12 @@ type Commit struct { func cmdCommit(config configCollect) { rc := NewRepoCommits(config) + rc.CollectDescs() rc.PrintDescs() + + rc.CollectContent() + //rc.BuildGraph() } func NewRepoCommits (config configCollect) *RepoCommits { @@ -72,3 +84,15 @@ func (rc* RepoCommits) PrintDescs() { } log.Println("Repo", rc.Config.RepoId, "contains", len(rc.CommitDesc), "commits") } + +func (rc* RepoCommits) CollectContent() { + for id, path := range rc.CommitDesc { + data, err := ioutil.ReadFile(path) + if err != nil { log.Fatal(err) } + + var c Commit + json.Unmarshal(data, &c) + rc.CommitContent[id] = c + log.Println(rc.CommitContent[id]) + } +}