mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-27 20:49:33 +08:00
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>
This commit is contained in:
parent
241b74f6c5
commit
f766b00293
@ -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
|
// 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) {
|
func (c *Commit) CommitsByRange(page, pageSize int, not string) ([]*Commit, error) {
|
||||||
return c.repo.commitsByRange(c.ID, page, pageSize)
|
return c.repo.commitsByRange(c.ID, page, pageSize, not)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommitsBefore returns all the commits before current revision
|
// CommitsBefore returns all the commits before current revision
|
||||||
|
@ -90,14 +90,22 @@ func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
|
|||||||
return commits[0], nil
|
return commits[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repository) commitsByRange(id SHA1, page, pageSize int) ([]*Commit, error) {
|
func (repo *Repository) commitsByRange(id SHA1, page, pageSize int, not string) ([]*Commit, error) {
|
||||||
stdout, _, err := NewCommand(repo.Ctx, "log").
|
cmd := NewCommand(repo.Ctx, "log").
|
||||||
AddOptionFormat("--skip=%d", (page-1)*pageSize).AddOptionFormat("--max-count=%d", pageSize).AddArguments(prettyLogFormat).
|
AddOptionFormat("--skip=%d", (page-1)*pageSize).
|
||||||
AddDynamicArguments(id.String()).
|
AddOptionFormat("--max-count=%d", pageSize).
|
||||||
RunStdBytes(&RunOpts{Dir: repo.Path})
|
AddArguments(prettyLogFormat).
|
||||||
|
AddDynamicArguments(id.String())
|
||||||
|
|
||||||
|
if not != "" {
|
||||||
|
cmd.AddOptionValues("--not", not)
|
||||||
|
}
|
||||||
|
|
||||||
|
stdout, _, err := cmd.RunStdBytes(&RunOpts{Dir: repo.Path})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return repo.parsePrettyFormatLogToList(stdout)
|
return repo.parsePrettyFormatLogToList(stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +115,10 @@ func GetAllCommits(ctx *context.APIContext) {
|
|||||||
// in: query
|
// in: query
|
||||||
// description: page size of results (ignored if used with 'path')
|
// description: page size of results (ignored if used with 'path')
|
||||||
// type: integer
|
// type: integer
|
||||||
|
// - name: not
|
||||||
|
// in: query
|
||||||
|
// description: commits that match the given specifier will not be listed.
|
||||||
|
// type: string
|
||||||
// responses:
|
// responses:
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/CommitList"
|
// "$ref": "#/responses/CommitList"
|
||||||
@ -181,7 +185,8 @@ func GetAllCommits(ctx *context.APIContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Query commits
|
// Query commits
|
||||||
commits, err = baseCommit.CommitsByRange(listOptions.Page, listOptions.PageSize)
|
not := ctx.FormString("not")
|
||||||
|
commits, err = baseCommit.CommitsByRange(listOptions.Page, listOptions.PageSize, not)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CommitsByRange", err)
|
ctx.Error(http.StatusInternalServerError, "CommitsByRange", err)
|
||||||
return
|
return
|
||||||
|
@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
// ShowBranchFeed shows tags and/or releases on the repo as RSS / Atom feed
|
// ShowBranchFeed shows tags and/or releases on the repo as RSS / Atom feed
|
||||||
func ShowBranchFeed(ctx *context.Context, repo *repo.Repository, formatType string) {
|
func ShowBranchFeed(ctx *context.Context, repo *repo.Repository, formatType string) {
|
||||||
commits, err := ctx.Repo.Commit.CommitsByRange(0, 10)
|
commits, err := ctx.Repo.Commit.CommitsByRange(0, 10, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("ShowBranchFeed", err)
|
ctx.ServerError("ShowBranchFeed", err)
|
||||||
return
|
return
|
||||||
|
@ -70,7 +70,7 @@ func Commits(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Both `git log branchName` and `git log commitId` work.
|
// Both `git log branchName` and `git log commitId` work.
|
||||||
commits, err := ctx.Repo.Commit.CommitsByRange(page, pageSize)
|
commits, err := ctx.Repo.Commit.CommitsByRange(page, pageSize, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("CommitsByRange", err)
|
ctx.ServerError("CommitsByRange", err)
|
||||||
return
|
return
|
||||||
|
6
templates/swagger/v1_json.tmpl
generated
6
templates/swagger/v1_json.tmpl
generated
@ -3803,6 +3803,12 @@
|
|||||||
"description": "page size of results (ignored if used with 'path')",
|
"description": "page size of results (ignored if used with 'path')",
|
||||||
"name": "limit",
|
"name": "limit",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "commits that match the given specifier will not be listed.",
|
||||||
|
"name": "not",
|
||||||
|
"in": "query"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
Loading…
Reference in New Issue
Block a user