aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorMatthew Walowski <mattwalowski@gmail.com>2023-04-29 05:34:14 -0700
committerGitHub <noreply@github.com>2023-04-29 08:34:14 -0400
commitf766b002938b5c81e343c81fda3c0669fa09809f (patch)
treed0d5baa5d120b81c18721b7de2f46d2b855f6b0f /modules
parent241b74f6c536c1d7de3b4e79e552bf1a3264cc6d (diff)
downloadgitea-f766b002938b5c81e343c81fda3c0669fa09809f.tar.gz
gitea-f766b002938b5c81e343c81fda3c0669fa09809f.zip
Add ability to specify '--not' from GetAllCommits (#24409)
For my specific use case, I'd like to get all commits that are on one branch but NOT on the other branch. For instance, I'd like to get all the commits on `Branch1` that are not also on `master` (I.e. all commits that were made after `Branch1` was created). This PR adds a `not` query param that gets passed down to the `git log` command to allow the user to exclude items from `GetAllCommits`. See [git documentation](https://git-scm.com/docs/git-log#Documentation/git-log.txt---not) --------- Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'modules')
-rw-r--r--modules/git/commit.go4
-rw-r--r--modules/git/repo_commit.go18
2 files changed, 15 insertions, 7 deletions
diff --git a/modules/git/commit.go b/modules/git/commit.go
index 610d27c68a..f28c315cb5 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -187,8 +187,8 @@ func (c *Commit) CommitsCount() (int64, error) {
}
// CommitsByRange returns the specific page commits before current revision, every page's number default by CommitsRangeSize
-func (c *Commit) CommitsByRange(page, pageSize int) ([]*Commit, error) {
- return c.repo.commitsByRange(c.ID, page, pageSize)
+func (c *Commit) CommitsByRange(page, pageSize int, not string) ([]*Commit, error) {
+ return c.repo.commitsByRange(c.ID, page, pageSize, not)
}
// CommitsBefore returns all the commits before current revision
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go
index 153a116b06..30a82eb297 100644
--- a/modules/git/repo_commit.go
+++ b/modules/git/repo_commit.go
@@ -90,14 +90,22 @@ func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
return commits[0], nil
}
-func (repo *Repository) commitsByRange(id SHA1, page, pageSize int) ([]*Commit, error) {
- stdout, _, err := NewCommand(repo.Ctx, "log").
- AddOptionFormat("--skip=%d", (page-1)*pageSize).AddOptionFormat("--max-count=%d", pageSize).AddArguments(prettyLogFormat).
- AddDynamicArguments(id.String()).
- RunStdBytes(&RunOpts{Dir: repo.Path})
+func (repo *Repository) commitsByRange(id SHA1, page, pageSize int, not string) ([]*Commit, error) {
+ cmd := NewCommand(repo.Ctx, "log").
+ AddOptionFormat("--skip=%d", (page-1)*pageSize).
+ AddOptionFormat("--max-count=%d", pageSize).
+ AddArguments(prettyLogFormat).
+ AddDynamicArguments(id.String())
+
+ if not != "" {
+ cmd.AddOptionValues("--not", not)
+ }
+
+ stdout, _, err := cmd.RunStdBytes(&RunOpts{Dir: repo.Path})
if err != nil {
return nil, err
}
+
return repo.parsePrettyFormatLogToList(stdout)
}