Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Version
Manage
Activity
Members
Plan
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Utilities
Version
Commits
a0608f85
Verified
Commit
a0608f85
authored
1 year ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
chore: optimize
parent
164906dc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
git.go
+25
-17
25 additions, 17 deletions
git.go
with
25 additions
and
17 deletions
git.go
+
25
−
17
View file @
a0608f85
...
...
@@ -11,7 +11,6 @@ import (
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/storer"
)
type
CommitType
int
...
...
@@ -43,15 +42,31 @@ func GetCommitType(path string) (CommitType, error) {
}
func
getLatestSemanticTag
(
path
string
)
(
string
,
error
)
{
r
,
err
:=
git
.
PlainOpen
(
path
)
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"failed to open repository: %v"
,
err
)
}
tagList
,
err
:=
getSemanticTags
(
r
)
if
err
!=
nil
{
return
""
,
err
}
if
len
(
tagList
)
==
0
{
return
""
,
fmt
.
Errorf
(
"no semantic tags found"
)
}
sort
.
Slice
(
tagList
,
func
(
i
,
j
int
)
bool
{
return
compareSemanticVersions
(
tagList
[
i
],
tagList
[
j
])
})
return
tagList
[
len
(
tagList
)
-
1
],
nil
}
func
getSemanticTags
(
r
*
git
.
Repository
)
([]
string
,
error
)
{
tags
,
err
:=
r
.
Tags
()
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"failed to get tags: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to get tags: %v"
,
err
)
}
var
tagList
[]
string
...
...
@@ -64,18 +79,10 @@ func getLatestSemanticTag(path string) (string, error) {
})
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"failed to iterate over tags: %v"
,
err
)
}
if
len
(
tagList
)
==
0
{
return
""
,
fmt
.
Errorf
(
"no semantic tags found"
)
return
nil
,
fmt
.
Errorf
(
"failed to iterate over tags: %v"
,
err
)
}
sort
.
Slice
(
tagList
,
func
(
i
,
j
int
)
bool
{
return
compareSemanticVersions
(
tagList
[
i
],
tagList
[
j
])
})
return
tagList
[
len
(
tagList
)
-
1
],
nil
return
tagList
,
nil
}
func
isSemanticVersion
(
tagName
string
)
bool
{
...
...
@@ -109,10 +116,8 @@ func getLatestTagCommit(r *git.Repository) (*object.Commit, error) {
return
nil
,
fmt
.
Errorf
(
"failed to get tags: %v"
,
err
)
}
var
(
mostRecentTag
*
plumbing
.
Reference
mostRecentCommit
*
object
.
Commit
)
var
mostRecentTag
*
plumbing
.
Reference
var
mostRecentCommit
*
object
.
Commit
err
=
tags
.
ForEach
(
func
(
tag
*
plumbing
.
Reference
)
error
{
obj
,
err
:=
r
.
TagObject
(
tag
.
Hash
())
...
...
@@ -141,6 +146,7 @@ func getLatestTagCommit(r *git.Repository) (*object.Commit, error) {
return
nil
})
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to iterate over tags: %v"
,
err
)
}
...
...
@@ -156,6 +162,7 @@ func getCommitTypeSinceTag(r *git.Repository, tagCommit *object.Commit) (CommitT
var
commitType
CommitType
found
:=
false
err
=
cIter
.
ForEach
(
func
(
commit
*
object
.
Commit
)
error
{
if
commit
.
Hash
==
tagCommit
.
Hash
{
found
=
true
...
...
@@ -176,6 +183,7 @@ func getCommitTypeSinceTag(r *git.Repository, tagCommit *object.Commit) (CommitT
return
nil
})
if
err
!=
nil
{
return
OtherCommit
,
fmt
.
Errorf
(
"failed to iterate over commit log: %v"
,
err
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment