Collect commits
This commit is contained in:
parent
d13cbcb356
commit
3ed9f15672
3 changed files with 54 additions and 12 deletions
13
checks.go
13
checks.go
|
@ -2,22 +2,15 @@ package main
|
||||||
|
|
||||||
import(
|
import(
|
||||||
"log"
|
"log"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkRootFolder(storage string) {
|
func checkRootFolder(storage string) {
|
||||||
files, err := ioutil.ReadDir(storage)
|
|
||||||
if err != nil { log.Fatal(err) }
|
|
||||||
|
|
||||||
checked_folders := map[string]bool{"fs": false, "commits": false, "blocks": false}
|
checked_folders := map[string]bool{"fs": false, "commits": false, "blocks": false}
|
||||||
for _, f := range files {
|
for f, _ := range checked_folders {
|
||||||
if _, ok := checked_folders[f.Name()]; ok {
|
if info, err := os.Stat(filepath.Join(storage, f)); err == nil && info.IsDir() {
|
||||||
info, err := os.Stat(filepath.Join(storage, f.Name()));
|
checked_folders[f] = true
|
||||||
if err == nil && info.IsDir() {
|
|
||||||
checked_folders[f.Name()] = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
51
commit.go
51
commit.go
|
@ -2,8 +2,16 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"io/ioutil"
|
||||||
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RepoCommits struct {
|
||||||
|
Config configCollect
|
||||||
|
CommitDesc map[string]string
|
||||||
|
CommitContent map[string]Commit
|
||||||
|
}
|
||||||
|
|
||||||
type Commit struct {
|
type Commit struct {
|
||||||
CommitId string `json:"commit_id"`
|
CommitId string `json:"commit_id"`
|
||||||
RootId string `json:"root_id"`
|
RootId string `json:"root_id"`
|
||||||
|
@ -22,6 +30,45 @@ type Commit struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmdCommit(config configCollect) {
|
func cmdCommit(config configCollect) {
|
||||||
rexists := repoExistsIn(config.Storage, config.RepoId)
|
rc := NewRepoCommits(config)
|
||||||
if !rexists["commits"] { log.Fatal("No commits folder found for repo ",config.RepoId) }
|
rc.CollectDescs()
|
||||||
|
rc.PrintDescs()
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRepoCommits (config configCollect) *RepoCommits {
|
||||||
|
rc := new(RepoCommits)
|
||||||
|
rc.Config = config
|
||||||
|
rc.CommitDesc = make(map[string]string)
|
||||||
|
rc.CommitContent = make(map[string]Commit)
|
||||||
|
return rc
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc* RepoCommits) CollectDescs() {
|
||||||
|
baseFolder := filepath.Join(rc.Config.Storage, "commits", rc.Config.RepoId)
|
||||||
|
log.Println(baseFolder)
|
||||||
|
layer1, err := ioutil.ReadDir(baseFolder)
|
||||||
|
if err != nil { log.Fatal(err) }
|
||||||
|
for _, l1 := range layer1 {
|
||||||
|
intFolder := filepath.Join(baseFolder, l1.Name())
|
||||||
|
layer2, err := ioutil.ReadDir(intFolder)
|
||||||
|
if err != nil { log.Fatal(err) }
|
||||||
|
for _, l2 := range layer2 {
|
||||||
|
commitId := l1.Name() + l2.Name()
|
||||||
|
commitPath := filepath.Join(intFolder, l2.Name())
|
||||||
|
rc.CommitDesc[commitId] = commitPath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc* RepoCommits) PrintDescs() {
|
||||||
|
limit := 10
|
||||||
|
for id, path := range rc.CommitDesc {
|
||||||
|
log.Println(id, path)
|
||||||
|
limit = limit - 1
|
||||||
|
if limit < 0 {
|
||||||
|
log.Println("Too many commits, output has been truncated")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Println("Repo", rc.Config.RepoId, "contains", len(rc.CommitDesc), "commits")
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,10 @@ Options:
|
||||||
opts.Bind(&config)
|
opts.Bind(&config)
|
||||||
|
|
||||||
checkRootFolder(config.Storage)
|
checkRootFolder(config.Storage)
|
||||||
|
rexists := repoExistsIn(config.Storage, config.RepoId)
|
||||||
|
|
||||||
if config.Commits {
|
if config.Commits {
|
||||||
|
if !rexists["commits"] { log.Fatal("No commits folder found for repo ",config.RepoId) }
|
||||||
cmdCommit(config)
|
cmdCommit(config)
|
||||||
} else {
|
} else {
|
||||||
log.Fatal("This command is not implemented")
|
log.Fatal("This command is not implemented")
|
||||||
|
|
Loading…
Reference in a new issue