gitPull(): don't use regex anumore, but just plain

string-matching/searching.
Regex seems to be quite error-prone.
This commit is contained in:
Gerhard Hoffmann 2023-10-30 14:59:58 +01:00
parent 7dc04c4422
commit 196f1a730e

View File

@ -303,25 +303,34 @@ std::optional<QString> GitClient::gitPull() {
if (!s.isEmpty()) { if (!s.isEmpty()) {
QStringList lines = Update::split(s, '\n'); QStringList lines = Update::split(s, '\n');
if (!lines.empty()) { if (!lines.empty()) {
int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr"); static const QRegularExpression alreadyUpToDate("^\\s*Already\\s+up\\s+to\\s+date.*$");
m_branchName = (zoneNr != 0) ? QString("zg1/zone%1").arg(zoneNr) : "master"; if (std::none_of(lines.cbegin(), lines.cend(),
// lines can look like this: [](QString const &s) { return s.contains(alreadyUpToDate); })) {
// From https://git.mimbach49.de/GerhardHoffmann/customer_281 int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr");
// 41ec581..5d25ac3 master -> origin/master m_branchName = (zoneNr != 0) ? QString("zg1/zone%1").arg(zoneNr) : "master";
// ff10f57..43530a1 zg1/zone1 -> origin/zg1/zone1 // lines can look like this:
// 6ed893f..5d9882c zg1/zone2 -> origin/zg1/zone2 // From https://git.mimbach49.de/GerhardHoffmann/customer_281
// 4384d17..77045d8 zg1/zone3 -> origin/zg1/zone3 // 41ec581..5d25ac3 master -> origin/master
// 89d2812..36a0d74 zg1/zone5 -> origin/zg1/zone5 // ff10f57..43530a1 zg1/zone1 -> origin/zg1/zone1
bool found = false; // 6ed893f..5d9882c zg1/zone2 -> origin/zg1/zone2
for (int i=0; i < lines.size(); ++i) { // 4384d17..77045d8 zg1/zone3 -> origin/zg1/zone3
if (lines.at(i).contains(m_branchName)) { // 89d2812..36a0d74 zg1/zone5 -> origin/zg1/zone5
found = true; bool found = false;
// 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1 for (int i=0; i < lines.size(); ++i) {
static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)"); if (lines.at(i).contains(m_branchName)) {
QRegularExpressionMatch match = re.match(lines.at(i)); found = true;
if (match.hasMatch()) { // 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)");
return match.captured(2); 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 { } else {
emit m_worker->showErrorMessage("git pull", emit m_worker->showErrorMessage("git pull",
QString("(wrong cap-count (%1)").arg(re.captureCount())); QString("(wrong cap-count (%1)").arg(re.captureCount()));