feat: only use --to to replace --exclude-to, --include-to
parent
ed8e4704e3
commit
2dd6ffd1eb
28
main.go
28
main.go
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -32,8 +31,7 @@ const (
|
||||||
defaultVersion = "0.1.0"
|
defaultVersion = "0.1.0"
|
||||||
|
|
||||||
fromFlag = "from"
|
fromFlag = "from"
|
||||||
excludeToFlag = "exclude-to"
|
toFlag = "to"
|
||||||
includeToFlag = "include-to"
|
|
||||||
versionFlag = "version"
|
versionFlag = "version"
|
||||||
repositoryFlag = "repository"
|
repositoryFlag = "repository"
|
||||||
outputDirFlag = "output-dir"
|
outputDirFlag = "output-dir"
|
||||||
|
@ -57,11 +55,7 @@ func main() {
|
||||||
Usage: "generate from `COMMIT`",
|
Usage: "generate from `COMMIT`",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: excludeToFlag,
|
Name: toFlag,
|
||||||
Usage: "generate to `COMMIT` (exclude that commit)",
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: includeToFlag,
|
|
||||||
Usage: "generate to `COMMIT` (include that commit)",
|
Usage: "generate to `COMMIT` (include that commit)",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
|
@ -140,8 +134,7 @@ func (a *action) Run(c *cli.Context) error {
|
||||||
func (a *action) getFlags(c *cli.Context) {
|
func (a *action) getFlags(c *cli.Context) {
|
||||||
a.debug = c.Bool(debugFlag)
|
a.debug = c.Bool(debugFlag)
|
||||||
a.flags[fromFlag] = c.String(fromFlag)
|
a.flags[fromFlag] = c.String(fromFlag)
|
||||||
a.flags[excludeToFlag] = c.String(excludeToFlag)
|
a.flags[toFlag] = c.String(toFlag)
|
||||||
a.flags[includeToFlag] = c.String(includeToFlag)
|
|
||||||
a.flags[versionFlag] = a.getFlagValue(c, versionFlag, defaultVersion)
|
a.flags[versionFlag] = a.getFlagValue(c, versionFlag, defaultVersion)
|
||||||
a.flags[repositoryFlag] = a.getFlagValue(c, repositoryFlag, defaultRepositry)
|
a.flags[repositoryFlag] = a.getFlagValue(c, repositoryFlag, defaultRepositry)
|
||||||
a.flags[outputDirFlag] = a.getFlagValue(c, outputDirFlag, defaultOutputDir)
|
a.flags[outputDirFlag] = a.getFlagValue(c, outputDirFlag, defaultOutputDir)
|
||||||
|
@ -170,19 +163,8 @@ func (a *action) getCommits() ([]git.Commit, error) {
|
||||||
fromRev := a.flags[fromFlag]
|
fromRev := a.flags[fromFlag]
|
||||||
a.logDebug("from revision %s", fromRev)
|
a.logDebug("from revision %s", fromRev)
|
||||||
|
|
||||||
excludeToRev := a.flags[excludeToFlag]
|
includeToRev := a.flags[toFlag]
|
||||||
a.logDebug("exclude to revision %s", excludeToRev)
|
a.logDebug("to revision %s", includeToRev)
|
||||||
|
|
||||||
includeToRev := a.flags[includeToFlag]
|
|
||||||
a.logDebug("include to revision %s", includeToRev)
|
|
||||||
|
|
||||||
if excludeToRev != "" && includeToRev != "" {
|
|
||||||
return nil, errors.New("excludeToFlag and includeToFlag can not appear same time")
|
|
||||||
}
|
|
||||||
|
|
||||||
if excludeToRev != "" {
|
|
||||||
return r.LogExcludeTo(fromRev, excludeToRev)
|
|
||||||
}
|
|
||||||
|
|
||||||
if includeToRev != "" {
|
if includeToRev != "" {
|
||||||
return r.LogIncludeTo(fromRev, includeToRev)
|
return r.LogIncludeTo(fromRev, includeToRev)
|
||||||
|
|
|
@ -17,7 +17,6 @@ const (
|
||||||
|
|
||||||
type Repository interface {
|
type Repository interface {
|
||||||
Log(fromRev string) ([]Commit, error)
|
Log(fromRev string) ([]Commit, error)
|
||||||
LogExcludeTo(fromRev, toRev string) ([]Commit, error)
|
|
||||||
LogIncludeTo(fromRev, toRev string) ([]Commit, error)
|
LogIncludeTo(fromRev, toRev string) ([]Commit, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,29 +53,6 @@ func (r *repo) Log(fromRev string) ([]Commit, error) {
|
||||||
return r.log(fromHash)
|
return r.log(fromHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all commits between <from revision> and <to revision> (exclude <to revision>)
|
|
||||||
func (r *repo) LogExcludeTo(fromRev, toRev string) ([]Commit, error) {
|
|
||||||
if fromRev == "" {
|
|
||||||
fromRev = head
|
|
||||||
}
|
|
||||||
|
|
||||||
fromHash, err := r.r.ResolveRevision(plumbing.Revision(fromRev))
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to resolve %s: %w", fromRev, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if toRev == "" {
|
|
||||||
return r.log(fromHash)
|
|
||||||
}
|
|
||||||
|
|
||||||
toHash, err := r.r.ResolveRevision(plumbing.Revision(toRev))
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to resolve %s: %w", toRev, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return r.logWithStopFnFirst(fromHash, stopAtHash(toHash))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all commits between <from revision> and <to revision> (include <to revision>)
|
// Get all commits between <from revision> and <to revision> (include <to revision>)
|
||||||
func (r *repo) LogIncludeTo(fromRev, toRev string) ([]Commit, error) {
|
func (r *repo) LogIncludeTo(fromRev, toRev string) ([]Commit, error) {
|
||||||
if fromRev == "" {
|
if fromRev == "" {
|
||||||
|
@ -122,34 +98,6 @@ func (r *repo) log(fromHash *plumbing.Hash) ([]Commit, error) {
|
||||||
return commits, nil
|
return commits, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *repo) logWithStopFnFirst(fromHash *plumbing.Hash, fn stopFn) ([]Commit, error) {
|
|
||||||
cIter, err := r.r.Log(&git.LogOptions{
|
|
||||||
From: *fromHash,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to git log: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
commits := make([]Commit, 0, defaultCommitCount)
|
|
||||||
|
|
||||||
if err := cIter.ForEach(func(c *object.Commit) error {
|
|
||||||
if fn != nil {
|
|
||||||
if err := fn(c); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
commit := newCommit(c)
|
|
||||||
commits = append(commits, commit)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}); err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to iterate each git log: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return commits, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *repo) logWithStopFnLast(fromHash *plumbing.Hash, fn stopFn) ([]Commit, error) {
|
func (r *repo) logWithStopFnLast(fromHash *plumbing.Hash, fn stopFn) ([]Commit, error) {
|
||||||
cIter, err := r.r.Log(&git.LogOptions{
|
cIter, err := r.r.Log(&git.LogOptions{
|
||||||
From: *fromHash,
|
From: *fromHash,
|
||||||
|
|
Loading…
Reference in New Issue