Пример #1
0
KDevelop::VcsEvent BazaarUtils::parseBzrLogPart(const QString& output)
{
    const QStringList outputLines = output.split('\n');
    KDevelop::VcsEvent commitInfo;
    bool atMessage = false;
    QString message;
    bool afterMessage = false;
    QHash<QString, KDevelop::VcsItemEvent::Actions> fileToActionsMapping;
    KDevelop::VcsItemEvent::Action currentAction;
    for (const QString &line : outputLines) {
        if (!atMessage) {
            if (line.startsWith(QStringLiteral("revno"))) {
                QString revno = line.mid(QStringLiteral("revno: ").length());
                revno = revno.left(revno.indexOf(' '));
                KDevelop::VcsRevision revision;
                revision.setRevisionValue(revno.toLongLong(), KDevelop::VcsRevision::GlobalNumber);
                commitInfo.setRevision(revision);
            } else if (line.startsWith(QStringLiteral("committer: "))) {
                QString commiter = line.mid(QStringLiteral("committer: ").length());
                commitInfo.setAuthor(commiter);     // Author goes after commiter, but only if is different
            } else if (line.startsWith(QStringLiteral("author"))) {
                QString author = line.mid(QStringLiteral("author: ").length());
                commitInfo.setAuthor(author);       // It may override commiter (In fact commiter is not supported by VcsEvent)
            } else if (line.startsWith(QStringLiteral("timestamp"))) {
                const QString formatString = QStringLiteral("yyyy-MM-dd hh:mm:ss");
                QString timestamp = line.mid(QStringLiteral("timestamp: ddd ").length(), formatString.length());
                commitInfo.setDate(QDateTime::fromString(timestamp, formatString));
            } else if (line.startsWith(QStringLiteral("message"))) {
                atMessage = true;
            }
        } else if (atMessage && !afterMessage) {
            if (!line.isEmpty() && line[0].isSpace()) {
                message += line.trimmed() + "\n";
            } else if (!line.isEmpty()) {
                afterMessage = true;
                // leave atMessage = true
                currentAction = BazaarUtils::parseActionDescription(line);
            } // if line is empty - ignore and get next
        } else if (afterMessage) {
            if (!line.isEmpty() && !line[0].isSpace()) {
                currentAction = BazaarUtils::parseActionDescription(line);
            } else if (!line.isEmpty()) {
                fileToActionsMapping[line.trimmed()] |= currentAction;
            } // if line is empty - ignore and get next
        }
    }
    if (atMessage)
        commitInfo.setMessage(message.trimmed());
    for (auto i = fileToActionsMapping.begin(); i != fileToActionsMapping.end(); ++i) {
        KDevelop::VcsItemEvent itemEvent;
        itemEvent.setRepositoryLocation(i.key());
        itemEvent.setActions(i.value());
        commitInfo.addItem(itemEvent);
    }
    return commitInfo;
}
Пример #2
0
void CvsLogJob::parseOutput(const QString& jobOutput, QList<QVariant>& events)
{
    static QRegExp rx_sep( "[-=]+" );
    static QRegExp rx_rev( "revision ((\\d+\\.?)+)" );
    static QRegExp rx_branch( "branches:\\s+(.*)" );
    static QRegExp rx_date( "date:\\s+([^;]*);\\s+author:\\s+([^;]*).*" );


    QStringList lines = jobOutput.split('\n');

    KDevelop::VcsEvent item;
    bool firstSeperatorReached = false;
    QString log;

    for (int i=0; i<lines.count(); ++i) {
        QString s = lines[i];
//         qCDebug(PLUGIN_CVS) << "line:" << s ;

        if (rx_rev.exactMatch(s)) {
//             qCDebug(PLUGIN_CVS) << "MATCH REVISION" ;
            KDevelop::VcsRevision rev;
            rev.setRevisionValue( rx_rev.cap(1), KDevelop::VcsRevision::FileNumber );
            item.setRevision( rev );
        } else if (rx_branch.exactMatch(s)) {
//             qCDebug(PLUGIN_CVS) << "MATCH BRANCH" ;
        } else if (rx_date.exactMatch(s)) {
//             qCDebug(PLUGIN_CVS) << "MATCH DATE" ;
            QString date = rx_date.cap(1);
            // cut out the part that matches the Qt::ISODate format
            date.truncate(19);

            item.setDate( QDateTime::fromString( date, Qt::ISODate ) );
            item.setAuthor( rx_date.cap(2) );
        } else  if (rx_sep.exactMatch(s)) {
//             qCDebug(PLUGIN_CVS) << "MATCH SEPARATOR" ;
            if (firstSeperatorReached) {
                item.setMessage( log );
                log.clear();

                events.append( qVariantFromValue( item ) );

                KDevelop::VcsEvent empty;
                item = empty;
            } else {
                firstSeperatorReached = true;
            }
        } else {
            if (firstSeperatorReached) {
//                 qCDebug(PLUGIN_CVS) << "ADDING LOG" ;
                log += s+'\n';
            }
        }
    }
}