Skip to content

Commit

Permalink
Merge pull request neuvector#1598 from Acmarr/main
Browse files Browse the repository at this point in the history
NVSHAS-9436 add CompareWithoutEpoch function
  • Loading branch information
jayhuang-suse authored Oct 14, 2024
2 parents 03c8975 + be46047 commit 169a265
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions share/utils/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,37 @@ func (a Version) Compare(b Version) int {
return signum(verrevcmp(a.el_ver, b.el_ver))
}

// CompareWithoutEpoch uses same comparison logic as Compare but doesn't compare epoch.
func (a Version) CompareWithoutEpoch(b Version) int {
// Quick check
if a == b {
return 0
}

// Max/Min comparison
if a == MinVersion || b == MaxVersion {
return -1
}
if b == MinVersion || a == MaxVersion {
return 1
}

// Compare version
rc := verrevcmp(a.version, b.version)
if rc != 0 {
return signum(rc)
}

// Compare revision
rc = verrevcmp(a.revision, b.revision)
if rc != 0 {
return signum(rc)
}

// Compare el_ver
return signum(verrevcmp(a.el_ver, b.el_ver))
}

// String returns the string representation of a Version
func (v Version) String() (s string) {
if v.epoch != 0 {
Expand Down

0 comments on commit 169a265

Please sign in to comment.