aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-11-08 17:21:54 +0000
committerGitHub <noreply@github.com>2020-11-08 12:21:54 -0500
commitc05a8abc762f868e67dd131d34f45218a0fb95ab (patch)
tree9aa0909c736933adc895ef830941dca85206ee07 /modules/git
parentd4e0b286558a68c96b0001a0676099c06067511b (diff)
downloadgitea-c05a8abc762f868e67dd131d34f45218a0fb95ab.tar.gz
gitea-c05a8abc762f868e67dd131d34f45218a0fb95ab.zip
Multiple GitGraph improvements: Exclude PR heads, Add branch/PR links, Show only certain branches, (#12766)
* Multiple GitGraph improvements. Add backend support for excluding PRs, selecting branches and files. Fix #10327 Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @silverwind Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @silverwind Signed-off-by: Andrew Thornton <art27@cantab.net> * Only show refs in dropdown we display on the graph Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @silverwind Signed-off-by: Andrew Thornton <art27@cantab.net> * use flexbox for ui header Signed-off-by: Andrew Thornton <art27@cantab.net> * Move Hide Pull Request button to the dropdown Signed-off-by: Andrew Thornton <art27@cantab.net> * Add SHA and user pictures Signed-off-by: Andrew Thornton <art27@cantab.net> * fix test Signed-off-by: Andrew Thornton <art27@cantab.net> * fix test 2 Signed-off-by: Andrew Thornton <art27@cantab.net> * fixes * async * more tweaks * use tabs in tmpl Signed-off-by: Andrew Thornton <art27@cantab.net> * remove commented thing Signed-off-by: Andrew Thornton <art27@cantab.net> * fix linting Signed-off-by: Andrew Thornton <art27@cantab.net> * Update web_src/js/features/gitgraph.js Co-authored-by: silverwind <me@silverwind.io> * graph tweaks * more tweaks * add title Signed-off-by: Andrew Thornton <art27@cantab.net> * fix loading indicator z-index and position Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'modules/git')
-rw-r--r--modules/git/commit.go22
-rw-r--r--modules/git/ref.go43
-rw-r--r--modules/git/repo.go2
-rw-r--r--modules/git/repo_commit.go6
4 files changed, 64 insertions, 9 deletions
diff --git a/modules/git/commit.go b/modules/git/commit.go
index 87278af9c7..6425345ea8 100644
--- a/modules/git/commit.go
+++ b/modules/git/commit.go
@@ -262,8 +262,19 @@ func CommitChangesWithArgs(repoPath string, args []string, opts CommitChangesOpt
}
// AllCommitsCount returns count of all commits in repository
-func AllCommitsCount(repoPath string) (int64, error) {
- stdout, err := NewCommand("rev-list", "--all", "--count").RunInDir(repoPath)
+func AllCommitsCount(repoPath string, hidePRRefs bool, files ...string) (int64, error) {
+ args := []string{"--all", "--count"}
+ if hidePRRefs {
+ args = append([]string{"--exclude=refs/pull/*"}, args...)
+ }
+ cmd := NewCommand("rev-list")
+ cmd.AddArguments(args...)
+ if len(files) > 0 {
+ cmd.AddArguments("--")
+ cmd.AddArguments(files...)
+ }
+
+ stdout, err := cmd.RunInDir(repoPath)
if err != nil {
return 0, err
}
@@ -271,7 +282,8 @@ func AllCommitsCount(repoPath string) (int64, error) {
return strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
}
-func commitsCount(repoPath string, revision, relpath []string) (int64, error) {
+// CommitsCountFiles returns number of total commits of until given revision.
+func CommitsCountFiles(repoPath string, revision, relpath []string) (int64, error) {
cmd := NewCommand("rev-list", "--count")
cmd.AddArguments(revision...)
if len(relpath) > 0 {
@@ -288,8 +300,8 @@ func commitsCount(repoPath string, revision, relpath []string) (int64, error) {
}
// CommitsCount returns number of total commits of until given revision.
-func CommitsCount(repoPath, revision string) (int64, error) {
- return commitsCount(repoPath, []string{revision}, []string{})
+func CommitsCount(repoPath string, revision ...string) (int64, error) {
+ return CommitsCountFiles(repoPath, revision, []string{})
}
// CommitsCount returns number of total commits of until current revision.
diff --git a/modules/git/ref.go b/modules/git/ref.go
index 67b56ac999..2a2798b18f 100644
--- a/modules/git/ref.go
+++ b/modules/git/ref.go
@@ -4,6 +4,8 @@
package git
+import "strings"
+
// Reference represents a Git ref.
type Reference struct {
Name string
@@ -16,3 +18,44 @@ type Reference struct {
func (ref *Reference) Commit() (*Commit, error) {
return ref.repo.getCommit(ref.Object)
}
+
+// ShortName returns the short name of the reference
+func (ref *Reference) ShortName() string {
+ if ref == nil {
+ return ""
+ }
+ if strings.HasPrefix(ref.Name, "refs/heads/") {
+ return ref.Name[11:]
+ }
+ if strings.HasPrefix(ref.Name, "refs/tags/") {
+ return ref.Name[10:]
+ }
+ if strings.HasPrefix(ref.Name, "refs/remotes/") {
+ return ref.Name[13:]
+ }
+ if strings.HasPrefix(ref.Name, "refs/pull/") && strings.IndexByte(ref.Name[10:], '/') > -1 {
+ return ref.Name[10 : strings.IndexByte(ref.Name[10:], '/')+10]
+ }
+
+ return ref.Name
+}
+
+// RefGroup returns the group type of the reference
+func (ref *Reference) RefGroup() string {
+ if ref == nil {
+ return ""
+ }
+ if strings.HasPrefix(ref.Name, "refs/heads/") {
+ return "heads"
+ }
+ if strings.HasPrefix(ref.Name, "refs/tags/") {
+ return "tags"
+ }
+ if strings.HasPrefix(ref.Name, "refs/remotes/") {
+ return "remotes"
+ }
+ if strings.HasPrefix(ref.Name, "refs/pull/") && strings.IndexByte(ref.Name[10:], '/') > -1 {
+ return "pull"
+ }
+ return ""
+}
diff --git a/modules/git/repo.go b/modules/git/repo.go
index 644ff09284..ae370d3da9 100644
--- a/modules/git/repo.go
+++ b/modules/git/repo.go
@@ -49,7 +49,7 @@ const prettyLogFormat = `--pretty=format:%H`
// GetAllCommitsCount returns count of all commits in repository
func (repo *Repository) GetAllCommitsCount() (int64, error) {
- return AllCommitsCount(repo.Path)
+ return AllCommitsCount(repo.Path, false)
}
func (repo *Repository) parsePrettyFormatLogToList(logs []byte) (*list.List, error) {
diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go
index 1f123c97fb..ee3b05447b 100644
--- a/modules/git/repo_commit.go
+++ b/modules/git/repo_commit.go
@@ -318,7 +318,7 @@ func (repo *Repository) FileChangedBetweenCommits(filename, id1, id2 string) (bo
// FileCommitsCount return the number of files at a revison
func (repo *Repository) FileCommitsCount(revision, file string) (int64, error) {
- return commitsCount(repo.Path, []string{revision}, []string{file})
+ return CommitsCountFiles(repo.Path, []string{revision}, []string{file})
}
// CommitsByFileAndRange return the commits according revison file and the page
@@ -413,11 +413,11 @@ func (repo *Repository) CommitsBetweenIDs(last, before string) (*list.List, erro
// CommitsCountBetween return numbers of commits between two commits
func (repo *Repository) CommitsCountBetween(start, end string) (int64, error) {
- count, err := commitsCount(repo.Path, []string{start + "..." + end}, []string{})
+ count, err := CommitsCountFiles(repo.Path, []string{start + "..." + end}, []string{})
if err != nil && strings.Contains(err.Error(), "no merge base") {
// future versions of git >= 2.28 are likely to return an error if before and last have become unrelated.
// previously it would return the results of git rev-list before last so let's try that...
- return commitsCount(repo.Path, []string{start, end}, []string{})
+ return CommitsCountFiles(repo.Path, []string{start, end}, []string{})
}
return count, err