gitPull(): don't use regex anumore, but just plain
string-matching/searching. Regex seems to be quite error-prone.
This commit is contained in:
parent
7dc04c4422
commit
196f1a730e
@ -303,25 +303,34 @@ std::optional<QString> GitClient::gitPull() {
|
||||
if (!s.isEmpty()) {
|
||||
QStringList lines = Update::split(s, '\n');
|
||||
if (!lines.empty()) {
|
||||
int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr");
|
||||
m_branchName = (zoneNr != 0) ? QString("zg1/zone%1").arg(zoneNr) : "master";
|
||||
// lines can look like this:
|
||||
// From https://git.mimbach49.de/GerhardHoffmann/customer_281
|
||||
// 41ec581..5d25ac3 master -> origin/master
|
||||
// ff10f57..43530a1 zg1/zone1 -> origin/zg1/zone1
|
||||
// 6ed893f..5d9882c zg1/zone2 -> origin/zg1/zone2
|
||||
// 4384d17..77045d8 zg1/zone3 -> origin/zg1/zone3
|
||||
// 89d2812..36a0d74 zg1/zone5 -> origin/zg1/zone5
|
||||
bool found = false;
|
||||
for (int i=0; i < lines.size(); ++i) {
|
||||
if (lines.at(i).contains(m_branchName)) {
|
||||
found = true;
|
||||
// 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1
|
||||
static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)");
|
||||
QRegularExpressionMatch match = re.match(lines.at(i));
|
||||
if (match.hasMatch()) {
|
||||
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches
|
||||
return match.captured(2);
|
||||
static const QRegularExpression alreadyUpToDate("^\\s*Already\\s+up\\s+to\\s+date.*$");
|
||||
if (std::none_of(lines.cbegin(), lines.cend(),
|
||||
[](QString const &s) { return s.contains(alreadyUpToDate); })) {
|
||||
int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr");
|
||||
m_branchName = (zoneNr != 0) ? QString("zg1/zone%1").arg(zoneNr) : "master";
|
||||
// lines can look like this:
|
||||
// From https://git.mimbach49.de/GerhardHoffmann/customer_281
|
||||
// 41ec581..5d25ac3 master -> origin/master
|
||||
// ff10f57..43530a1 zg1/zone1 -> origin/zg1/zone1
|
||||
// 6ed893f..5d9882c zg1/zone2 -> origin/zg1/zone2
|
||||
// 4384d17..77045d8 zg1/zone3 -> origin/zg1/zone3
|
||||
// 89d2812..36a0d74 zg1/zone5 -> origin/zg1/zone5
|
||||
bool found = false;
|
||||
for (int i=0; i < lines.size(); ++i) {
|
||||
if (lines.at(i).contains(m_branchName)) {
|
||||
found = true;
|
||||
// 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1
|
||||
static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)");
|
||||
QRegularExpressionMatch match = re.match(lines.at(i));
|
||||
if (match.hasMatch()) {
|
||||
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches
|
||||
QString const matchCaptured = match.captured(2);
|
||||
worker()->CONSOLE(QStringList(matchCaptured)) << Worker::UPDATE_STEP::UPDATE_REPOSITORY;
|
||||
return matchCaptured;
|
||||
} else {
|
||||
QStringList lst(QString("(wrong capture count (%1)").arg(re.captureCount()));
|
||||
worker()->GUI(lst) << (worker()->CONSOLE(lst) << Worker::UPDATE_STEP::UPDATE_REPOSITORY_FAILURE);
|
||||
}
|
||||
} else {
|
||||
emit m_worker->showErrorMessage("git pull",
|
||||
QString("(wrong cap-count (%1)").arg(re.captureCount()));
|
||||
|
Loading…
Reference in New Issue
Block a user