~kornellapacz/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH gmnigit] allow limiting the commits to export

Omar Polo <op@omarpolo.com>
Details
Message ID
<87fspychbq.fsf@omarpolo.com>
DKIM signature
pass
Download raw message
Patch: +22 -1
Hello,

Sorry for the email flood, but I had some free time today and I tried to
improve gmnigit a bit :)

This adds a -max-commits flags that allows to limit the number of
commits to export.  This speeds up significantly the time for some
non-tiny repos.  It also reduces the space on disk.

The default are unchanged: one has to explicitly pass -max-commits with
a non-negative value to opt-in.



From 760a1d26732fcef73358e19217d28344bf6c997c Mon Sep 17 00:00:00 2001
From: Omar Polo <op@omarpolo.com>
Date: Sat, 8 Jan 2022 16:38:03 +0000
Subject: [PATCH] allow limiting the maximum number of commits to export

Some repository can be huge, and limiting the number of commits speeds
up the processing time significantly.  (it also saves some space on the
disk.)
---
 README.md  |  2 ++
 commits.go | 14 +++++++++++++-
 main.go    |  7 +++++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index e0a95de..6f42fed 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/commits.go b/commits.go
index 68b5091..a3b7709 100644
--- a/commits.go
+++ b/commits.go
@@ -1,7 +1,9 @@
package main

import (
	"errors"
	"fmt"
	"log"
	"os"
	"path/filepath"
	"sort"
@@ -21,6 +23,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)
@@ -56,7 +60,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) {
@@ -67,7 +73,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 {
		n++
		if maxCommits != -1 && n == maxCommits {
			return EndOfCommits
		}

		commitTemplate.Execute(commitsIndex, commit)

		patchFile, err := os.Create(filepath.Join(commitsPath, commit.Hash.String()+".patch"))
diff --git a/main.go b/main.go
index b997e5c..cbe44be 100644
--- a/main.go
+++ b/main.go
@@ -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
-- 
2.34.1
Omar Polo <op@omarpolo.com>
Details
Message ID
<878rvqch4d.fsf@omarpolo.com>
In-Reply-To
<87fspychbq.fsf@omarpolo.com> (view parent)
DKIM signature
pass
Download raw message
Patch: +22 -1
Omar Polo <op@omarpolo.com> writes:

> Hello,
>
> Sorry for the email flood, but I had some free time today and I tried to
> improve gmnigit a bit :)
>
> This adds a -max-commits flags that allows to limit the number of
> commits to export.  This speeds up significantly the time for some
> non-tiny repos.  It also reduces the space on disk.
>
> The default are unchanged: one has to explicitly pass -max-commits with
> a non-negative value to opt-in.

oops, the handling of `-max-commits 0' was wrong, here's another try:


From 8971b46b33186e7b84de38670ce129a997f39d16 Mon Sep 17 00:00:00 2001
From: Omar Polo <op@omarpolo.com>
Date: Sat, 8 Jan 2022 16:43:12 +0000
Subject: [PATCH] allow limiting the maximum number of commits to export

Some repository can be huge, and limiting the number of commits speeds
up the processing time significantly.  (it also saves some space on the
disk.)
---
 README.md  |  2 ++
 commits.go | 14 +++++++++++++-
 main.go    |  7 +++++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index e0a95de..6f42fed 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/commits.go b/commits.go
index 68b5091..4af2cac 100644
--- a/commits.go
+++ b/commits.go
@@ -1,7 +1,9 @@
package main

import (
	"errors"
	"fmt"
	"log"
	"os"
	"path/filepath"
	"sort"
@@ -21,6 +23,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)
@@ -56,7 +60,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) {
@@ -67,7 +73,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"))
diff --git a/main.go b/main.go
index b997e5c..cbe44be 100644
--- a/main.go
+++ b/main.go
@@ -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
-- 
2.34.1
Reply to thread Export thread (mbox)