Beispiel #1
0
void Annotate::unify(SList dst, SCList src) {

	const QString m("Merge");
	for (int i = 0; i < dst.size(); ++i) {
		if (dst.at(i) == m)
			dst[i] = src.at(i);
	}
}
Beispiel #2
0
bool CommitImpl::checkConfirm(SCRef msg, SCRef patchName, SCList selFiles, bool amend) {

//	QTextCodec* tc = QTextCodec::codecForCStrings();
//	QTextCodec::setCodecForCStrings(0); // set temporary Latin-1

	// NOTEME: i18n-ugly
	QString whatToDo = amend ?
	    (git->isStGITStack() ? "refresh top patch with" :
	     			   "amend last commit with") :
	    (git->isStGITStack() ? "create a new patch with" : "commit");

        QString text("Do you want to " + whatToDo);

        bool const fullList = selFiles.size() < 20;
        if (fullList)
            text.append(" the following file(s)?\n\n" + selFiles.join("\n") +
                        "\n\nwith the message:\n\n");
        else
            text.append(" those " + QString::number(selFiles.size()) +
                        " files the with the message:\n\n");

	text.append(msg);
	if (git->isStGITStack())
		text.append("\n\nAnd patch name: " + patchName);

//	QTextCodec::setCodecForCStrings(tc);

        QMessageBox msgBox(this);
        msgBox.setWindowTitle("Commit changes - QGit");
        msgBox.setText(text);
        if (!fullList)
            msgBox.setDetailedText(selFiles.join("\n"));

        msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
        msgBox.setDefaultButton(QMessageBox::Yes);

        return msgBox.exec() != QMessageBox::No;
}
Beispiel #3
0
const QString Git::quote(SCList sl) {

	QString q(sl.join(QUOTE_CHAR + ' ' + QUOTE_CHAR));
	q.prepend(QUOTE_CHAR).append(QUOTE_CHAR);
	return q;
}
Beispiel #4
0
bool Annotate::setAnnotation(SCRef diff, SCRef author, SCList prevAnn, SList newAnn, int ofs)
{
    newAnn.clear();
    QStringList::const_iterator cur(prevAnn.constBegin());
    QString line;
    int idx = 0, num, lineNumStart, lineNumEnd;
    int curLineNum = 1; // warning, starts from 1 instead of 0
    bool inHeader = true;

    while (getNextSection(diff, idx, line, "\n")) {
        char firstChar = line.at(0).toLatin1();

        if (inHeader) {
            if (firstChar == '@')
                inHeader = false;
            else
                continue;
        }

        switch (firstChar) {
        case '@':
            // an unified diff fragment header has form '@@ -a,b +c,d @@'
            // where 'a' is old file line number and 'b' is old file
            // number of lines of the hunk, 'c' and 'd' are the same
            // for new file. If the file does not have enough lines
            // then also the form '@@ -a +c @@' is used.
            if (ofs == 0)
                lineNumStart = line.indexOf('-') + 1;
            else
            // in this case we are given diff fragments with
            // faked small files that span the fragment plus
            // some padding. So we use 'c' instead of 'a' to
            // find the beginning of our patch in the faked file,
            // this value will be offsetted by ofs later
                lineNumStart = line.indexOf('+') + 1;

            lineNumEnd = line.indexOf(',', lineNumStart);
            if (lineNumEnd == -1) // small file case
                lineNumEnd = line.indexOf(' ', lineNumStart);

            num = line.mid(lineNumStart, lineNumEnd - lineNumStart).toInt();
            num -= ofs; // offset for range filter computation

            // diff lines start from 1, 0 is empty file,
            // instead QValueList::at() starts from 0
            if (num < 0 || num > prevAnn.size()) {
                dbp("ASSERT setAnnotation: start line number is %1", num);
                isError = true;
                return false;
            }
            for ( ; curLineNum < num; ++curLineNum) {
                newAnn.append(*cur);
                ++cur;
            }
            break;
        case '+':
            newAnn.append(author);
            break;
        case '-':
            if (curLineNum > prevAnn.size()) {
                dbp("ASSERT setAnnotation: remove end of "
                    "file, diff is %1", diff);
                isError = true;
                return false;
            } else {
                ++cur;
                ++curLineNum;
            }
            break;
        case '\\':
            // diff(1) produces a "\ No newline at end of file", but the
            // message is locale dependent, so just test the space after '\'
            if (line[1] == ' ')
                break;

            // fall through
        default:
            if (curLineNum > prevAnn.size()) {
                dbp("ASSERT setAnnotation: end of "
                    "file reached, diff is %1", diff);
                isError = true;
                return false;
            } else {
                newAnn.append(*cur);
                ++cur;
                ++curLineNum;
            }
            break;
        }
    }

    // copy the tail
    for ( ; curLineNum <= prevAnn.size(); ++curLineNum) {
        newAnn.append(*cur);
        ++cur;
    }

    return true;
}