forked from cryfs/cryfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVersionCompare.cpp
More file actions
43 lines (39 loc) · 1.52 KB
/
VersionCompare.cpp
File metadata and controls
43 lines (39 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "VersionCompare.h"
#include "parser.h"
#include <tuple>
#include <cstring>
using std::string;
namespace gitversion {
bool VersionCompare::isOlderThan(const string &v1Str, const string &v2Str) {
VersionInfo v1 = Parser::parse(v1Str);
VersionInfo v2 = Parser::parse(v2Str);
unsigned long v1_major = std::stoul(v1.majorVersion);
unsigned long v2_major = std::stoul(v2.majorVersion);
unsigned long v1_minor = std::stoul(v1.minorVersion);
unsigned long v2_minor = std::stoul(v2.minorVersion);
unsigned long v1_hotfix = std::stoul(v1.hotfixVersion);
unsigned long v2_hotfix = std::stoul(v2.hotfixVersion);
int versionTagCompare = _versionTagCompare(v1.versionTag, v2.versionTag);
return (v1_major < v2_major) || ((v1_major == v2_major) && (
(v1_minor < v2_minor) || ((v1_minor == v2_minor) && (
(v1_hotfix < v2_hotfix) || ((v1_hotfix == v2_hotfix) && (
(0 > versionTagCompare) || ((0 == versionTagCompare) && (
(v1.commitsSinceTag < v2.commitsSinceTag)
))))))));
}
int VersionCompare::_versionTagCompare(const string &tag1, const string &tag2) {
if (tag1 == "") {
if (tag2 == "") {
return 0;
} else {
return 1;
}
} else {
if (tag2 == "") {
return -1;
} else {
return strcmp(tag1.c_str(), tag2.c_str());
}
}
}
}