mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
use repo receiver func
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@@ -14,27 +15,47 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
year := time.Now().Year()
|
year := time.Now().Year()
|
||||||
for i := year - 4; i <= year; i++ {
|
repo, err := OpenRepo(".")
|
||||||
GetYear(i)
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
}
|
}
|
||||||
|
str, err := repo.GetYear(year)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Print(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetYear(year int) {
|
type Repo git.Repository
|
||||||
|
|
||||||
|
func OpenRepo(directory string) (Repo, error) {
|
||||||
|
if s, err := os.Stat(directory); err != nil {
|
||||||
|
return Repo{}, err
|
||||||
|
} else {
|
||||||
|
if !s.IsDir() {
|
||||||
|
return Repo{}, errors.New("received path to non-directory for git repo")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
r, err := git.PlainOpenWithOptions(directory, &(git.PlainOpenOptions{DetectDotGit: true}))
|
||||||
|
return Repo(*r), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo Repo) GetYear(year int) (string, error) {
|
||||||
yearLength := 365
|
yearLength := 365
|
||||||
if year%4 == 0 {
|
if year%4 == 0 {
|
||||||
yearLength++
|
yearLength++
|
||||||
}
|
}
|
||||||
data := types.NewDataSet()
|
data := types.NewDataSet()
|
||||||
|
r := git.Repository(repo)
|
||||||
r, err := git.PlainOpenWithOptions(".", &(git.PlainOpenOptions{DetectDotGit: true}))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("gitfetch error: Could not find a git repository to open!\n")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
ref, err := r.Head()
|
ref, err := r.Head()
|
||||||
// TODO handle this error
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})
|
cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
err = cIter.ForEach(func(c *object.Commit) error {
|
err = cIter.ForEach(func(c *object.Commit) error {
|
||||||
ts := c.Author.When
|
ts := c.Author.When
|
||||||
commit := types.Commit{Author: c.Author.Name, Message: c.Message, TimeStamp: ts}
|
commit := types.Commit{Author: c.Author.Name, Message: c.Message, TimeStamp: ts}
|
||||||
@@ -62,5 +83,5 @@ func GetYear(year int) {
|
|||||||
freq[k.YearDay()-1]++
|
freq[k.YearDay()-1]++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Print(gterm.GetYearUnicode(freq))
|
return gterm.GetYearUnicode(freq), nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user