M README.md => README.md +2 -0
@@ 21,6 21,8 @@ place `gmnigit` binary somewhere in your `$PATH`.
Usage of gmnigit:
-dist string
destination path (if exists will be overwritten)
+ -max-commits int
+ Max number of commit to export, -1 to export all (default -1)
-name string
project name, mandatory if generating the tags page
-perms
M commits.go => commits.go +13 -1
@@ 1,7 1,9 @@
package main
import (
+ "errors"
"fmt"
+ "log"
"os"
"path/filepath"
"text/template"
@@ 19,6 21,8 @@ Date: {{.Author.When.Format "Mon Jan 02 15:04:05 2006 -0700"}}
Message: {{ .Message }}
`))
+var EndOfCommits = errors.New("stop processing commits")
+
func iterateOverCommits(r *git.Repository, callback func(*object.Commit, *object.Patch) error) {
ref, err := r.Head()
check(err)
@@ 54,7 58,9 @@ func iterateOverCommits(r *git.Repository, callback func(*object.Commit, *object
return callback(c, patch)
})
- check(err)
+ if err != nil && err != EndOfCommits {
+ log.Fatal("can't process commits:", err)
+ }
}
func createCommitsFiles(repository *git.Repository) {
@@ 65,7 71,13 @@ func createCommitsFiles(repository *git.Repository) {
check(err)
commitsIndex.WriteString("# Commits \n\n")
+ n := 0
iterateOverCommits(repository, func(commit *object.Commit, patch *object.Patch) error {
+ if maxCommits != -1 && n == maxCommits {
+ return EndOfCommits
+ }
+ n++
+
commitTemplate.Execute(commitsIndex, commit)
patchFile, err := os.Create(filepath.Join(commitsPath, commit.Hash.String()+".patch"))
M main.go => main.go +7 -0
@@ 24,6 24,7 @@ var (
showPermissions bool
generateRefs bool
projectName string
+ maxCommits int
)
func main() {
@@ 34,9 35,15 @@ func main() {
flag.BoolVar(&showPermissions, "perms", false, "show files permissions in browsable tree")
flag.BoolVar(&generateRefs, "refs", false, "generate the tags page")
flag.StringVar(&projectName, "name", "", "project name, mandatory if generating the tags page")
+ flag.IntVar(&maxCommits, "max-commits", -1, "Max number of commit to export, -1 to export all")
flag.Parse()
+ if maxCommits < -1 {
+ flag.Usage()
+ os.Exit(1)
+ }
+
if repositoryPath == "" || distPath == "" {
flag.Usage()
return