Skip to content

Commit 483e663

Browse files
committed
repo_commit: add CommitsAfterDate
1 parent e76267f commit 483e663

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

commit.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@ func commitsCount(repoPath, revision, relpath string) (int64, error) {
163163
return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
164164
}
165165

166-
// CommitsCount returns number of total commits of until given revision.
167-
func CommitsCount(repoPath, revision string) (int64, error) {
168-
return commitsCount(repoPath, revision, "")
169-
}
170-
171166
func (c *Commit) CommitsCount() (int64, error) {
172167
return CommitsCount(c.repo.Path, c.ID.String())
173168
}

git.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111
)
1212

13-
const _VERSION = "0.6.4"
13+
const _VERSION = "0.6.5"
1414

1515
func Version() string {
1616
return _VERSION

repo.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,3 @@ func GetRepoSize(repoPath string) (*CountObject, error) {
278278

279279
return countObject, nil
280280
}
281-
282-
// GetLatestCommitDate returns the date of latest commit of repository.
283-
// If branch is empty, it returns the latest commit across all branches.
284-
func GetLatestCommitDate(repoPath, branch string) (time.Time, error) {
285-
cmd := NewCommand("for-each-ref", "--count=1", "--sort=-committerdate", "--format=%(committerdate:iso8601)")
286-
if len(branch) > 0 {
287-
cmd.AddArguments("refs/heads/" + branch)
288-
}
289-
stdout, err := cmd.RunInDir(repoPath)
290-
if err != nil {
291-
return time.Time{}, err
292-
}
293-
294-
return time.Parse("2006-01-02 15:04:05 -0700", strings.TrimSpace(stdout))
295-
}

repo_commit.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"strconv"
1212
"strings"
13+
"time"
1314

1415
"github.com/mcuadros/go-version"
1516
)
@@ -379,3 +380,34 @@ func (repo *Repository) getCommitsBeforeLimit(id sha1, num int) (*list.List, err
379380
l := list.New()
380381
return l, repo.commitsBefore(l, nil, id, 1, num)
381382
}
383+
384+
// CommitsAfterDate returns a list of commits which committed after given date.
385+
// The format of date should be in RFC3339.
386+
func (repo *Repository) CommitsAfterDate(date string) (*list.List, error) {
387+
stdout, err := NewCommand("log", _PRETTY_LOG_FORMAT, "--since="+date).RunInDirBytes(repo.Path)
388+
if err != nil {
389+
return nil, err
390+
}
391+
392+
return repo.parsePrettyFormatLogToList(stdout)
393+
}
394+
395+
// CommitsCount returns number of total commits of until given revision.
396+
func CommitsCount(repoPath, revision string) (int64, error) {
397+
return commitsCount(repoPath, revision, "")
398+
}
399+
400+
// GetLatestCommitDate returns the date of latest commit of repository.
401+
// If branch is empty, it returns the latest commit across all branches.
402+
func GetLatestCommitDate(repoPath, branch string) (time.Time, error) {
403+
cmd := NewCommand("for-each-ref", "--count=1", "--sort=-committerdate", "--format=%(committerdate:iso8601)")
404+
if len(branch) > 0 {
405+
cmd.AddArguments("refs/heads/" + branch)
406+
}
407+
stdout, err := cmd.RunInDir(repoPath)
408+
if err != nil {
409+
return time.Time{}, err
410+
}
411+
412+
return time.Parse("2006-01-02 15:04:05 -0700", strings.TrimSpace(stdout))
413+
}

0 commit comments

Comments
 (0)