2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-07-15 12:28:40 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2009-07-15 12:28:40 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-07-15 12:28:40 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2009-07-15 12:28:40 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-07-15 12:28:40 +02:00
|
|
|
|
|
|
|
|
#include "cvsutils.h"
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QRegExp>
|
|
|
|
|
#include <QStringList>
|
2009-07-15 12:28:40 +02:00
|
|
|
|
2012-01-07 16:55:09 +01:00
|
|
|
namespace Cvs {
|
2009-07-15 12:28:40 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2012-01-07 16:55:09 +01:00
|
|
|
CvsRevision::CvsRevision(const QString &rev) :
|
2009-07-15 12:28:40 +02:00
|
|
|
revision(rev)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 16:55:09 +01:00
|
|
|
CvsLogEntry::CvsLogEntry(const QString &f) :
|
2009-07-15 12:28:40 +02:00
|
|
|
file(f)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 16:55:09 +01:00
|
|
|
QDebug operator<<(QDebug d, const CvsLogEntry &e)
|
2009-07-15 12:28:40 +02:00
|
|
|
{
|
|
|
|
|
QDebug nospace = d.nospace();
|
|
|
|
|
nospace << "File: " << e.file << e.revisions.size() << '\n';
|
2012-11-28 20:44:03 +02:00
|
|
|
foreach (const CvsRevision &r, e.revisions)
|
2009-07-15 12:28:40 +02:00
|
|
|
nospace << " " << r.revision << ' ' << r.date << ' ' << r.commitId << '\n';
|
|
|
|
|
return d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Parse:
|
|
|
|
|
\code
|
|
|
|
|
RCS file: /repo/foo.h
|
|
|
|
|
Working file: foo.h
|
|
|
|
|
head: 1.2
|
|
|
|
|
...
|
|
|
|
|
----------------------------
|
|
|
|
|
revision 1.2
|
|
|
|
|
date: 2009-07-14 13:30:25 +0200; author: <author>; state: dead; lines: +0 -0; commitid: <id>;
|
|
|
|
|
<message>
|
|
|
|
|
----------------------------
|
|
|
|
|
revision 1.1
|
|
|
|
|
...
|
|
|
|
|
=============================================================================
|
|
|
|
|
\endcode */
|
|
|
|
|
|
2012-01-07 16:55:09 +01:00
|
|
|
QList<CvsLogEntry> parseLogEntries(const QString &o,
|
|
|
|
|
const QString &directory,
|
2014-05-19 23:32:33 +03:00
|
|
|
const QString &filterCommitId)
|
2009-07-15 12:28:40 +02:00
|
|
|
{
|
|
|
|
|
enum ParseState { FileState, RevisionState, StatusLineState };
|
|
|
|
|
|
2012-01-07 16:55:09 +01:00
|
|
|
QList<CvsLogEntry> rc;
|
2009-07-15 12:28:40 +02:00
|
|
|
const QStringList lines = o.split(QString(QLatin1Char('\n')), QString::SkipEmptyParts);
|
|
|
|
|
ParseState state = FileState;
|
|
|
|
|
|
|
|
|
|
const QString workingFilePrefix = QLatin1String("Working file: ");
|
2012-04-30 12:01:15 +02:00
|
|
|
QRegExp statusPattern = QRegExp(QLatin1String("^date: ([\\d\\-]+) .*commitid: ([^;]+);$"));
|
|
|
|
|
QRegExp revisionPattern = QRegExp(QLatin1String("^revision ([\\d\\.]+)$"));
|
2009-07-15 12:28:40 +02:00
|
|
|
const QChar slash = QLatin1Char('/');
|
|
|
|
|
Q_ASSERT(statusPattern.isValid() && revisionPattern.isValid());
|
|
|
|
|
const QString fileSeparator = QLatin1String("=============================================================================");
|
|
|
|
|
|
|
|
|
|
// Parse using a state enumeration and regular expressions as not to fall for weird
|
|
|
|
|
// commit messages in state 'RevisionState'
|
2012-11-28 20:44:03 +02:00
|
|
|
foreach (const QString &line, lines) {
|
2009-07-15 12:28:40 +02:00
|
|
|
switch (state) {
|
|
|
|
|
case FileState:
|
|
|
|
|
if (line.startsWith(workingFilePrefix)) {
|
|
|
|
|
QString file = directory;
|
|
|
|
|
if (!file.isEmpty())
|
|
|
|
|
file += slash;
|
|
|
|
|
file += line.mid(workingFilePrefix.size()).trimmed();
|
2012-01-07 16:55:09 +01:00
|
|
|
rc.push_back(CvsLogEntry(file));
|
2009-07-15 12:28:40 +02:00
|
|
|
state = RevisionState;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case RevisionState:
|
|
|
|
|
if (revisionPattern.exactMatch(line)) {
|
2012-01-07 16:55:09 +01:00
|
|
|
rc.back().revisions.push_back(CvsRevision(revisionPattern.cap(1)));
|
2009-07-15 12:28:40 +02:00
|
|
|
state = StatusLineState;
|
|
|
|
|
} else {
|
|
|
|
|
if (line == fileSeparator)
|
|
|
|
|
state = FileState;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case StatusLineState:
|
|
|
|
|
if (statusPattern.exactMatch(line)) {
|
|
|
|
|
const QString commitId = statusPattern.cap(2);
|
|
|
|
|
if (filterCommitId.isEmpty() || filterCommitId == commitId) {
|
|
|
|
|
rc.back().revisions.back().date = statusPattern.cap(1);
|
|
|
|
|
rc.back().revisions.back().commitId = commitId;
|
|
|
|
|
} else {
|
|
|
|
|
rc.back().revisions.pop_back();
|
|
|
|
|
}
|
|
|
|
|
state = RevisionState;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Purge out files with no matching commits
|
|
|
|
|
if (!filterCommitId.isEmpty()) {
|
2012-01-07 16:55:09 +01:00
|
|
|
for (QList<CvsLogEntry>::iterator it = rc.begin(); it != rc.end(); ) {
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (it->revisions.empty())
|
2009-07-15 12:28:40 +02:00
|
|
|
it = rc.erase(it);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2009-07-15 12:28:40 +02:00
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString fixDiffOutput(QString d)
|
|
|
|
|
{
|
|
|
|
|
if (d.isEmpty())
|
|
|
|
|
return d;
|
|
|
|
|
// Kill all lines starting with '?'
|
|
|
|
|
const QChar questionMark = QLatin1Char('?');
|
|
|
|
|
const QChar newLine = QLatin1Char('\n');
|
|
|
|
|
for (int pos = 0; pos < d.size(); ) {
|
|
|
|
|
const int endOfLinePos = d.indexOf(newLine, pos);
|
|
|
|
|
if (endOfLinePos == -1)
|
|
|
|
|
break;
|
|
|
|
|
const int nextLinePos = endOfLinePos + 1;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (d.at(pos) == questionMark)
|
2009-07-15 12:28:40 +02:00
|
|
|
d.remove(pos, nextLinePos - pos);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2009-07-15 12:28:40 +02:00
|
|
|
pos = nextLinePos;
|
|
|
|
|
}
|
|
|
|
|
return d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parse "cvs status" output for added/modified/deleted files
|
|
|
|
|
// "File: <foo> Status: Up-to-date"
|
|
|
|
|
// "File: <foo> Status: Locally Modified"
|
|
|
|
|
// "File: no file <foo> Status: Locally Removed"
|
|
|
|
|
// "File: hup Status: Locally Added"
|
|
|
|
|
// Not handled for commit purposes: "Needs Patch/Needs Merge"
|
|
|
|
|
// In between, we might encounter "cvs status: Examining subdir"...
|
|
|
|
|
// As we run the status command from the repository directory,
|
|
|
|
|
// we need to add the full path, again.
|
|
|
|
|
// stdout/stderr need to be merged to catch directories.
|
|
|
|
|
|
|
|
|
|
// Parse out status keywords, return state enum or -1
|
2012-01-07 16:55:09 +01:00
|
|
|
static int stateFromKeyword(const QString &s)
|
2009-07-15 12:28:40 +02:00
|
|
|
{
|
|
|
|
|
if (s == QLatin1String("Up-to-date"))
|
|
|
|
|
return -1;
|
|
|
|
|
if (s == QLatin1String("Locally Modified"))
|
2012-01-07 16:55:09 +01:00
|
|
|
return CvsSubmitEditor::LocallyModified;
|
2009-07-15 12:28:40 +02:00
|
|
|
if (s == QLatin1String("Locally Added"))
|
2012-01-07 16:55:09 +01:00
|
|
|
return CvsSubmitEditor::LocallyAdded;
|
2009-07-15 12:28:40 +02:00
|
|
|
if (s == QLatin1String("Locally Removed"))
|
2012-01-07 16:55:09 +01:00
|
|
|
return CvsSubmitEditor::LocallyRemoved;
|
2009-07-15 12:28:40 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StateList parseStatusOutput(const QString &directory, const QString &output)
|
|
|
|
|
{
|
|
|
|
|
StateList changeSet;
|
|
|
|
|
const QString fileKeyword = QLatin1String("File: ");
|
|
|
|
|
const QString statusKeyword = QLatin1String("Status: ");
|
|
|
|
|
const QString noFileKeyword = QLatin1String("no file ");
|
|
|
|
|
const QString directoryKeyword = QLatin1String("cvs status: Examining ");
|
|
|
|
|
const QString dotDir = QString(QLatin1Char('.'));
|
|
|
|
|
const QChar slash = QLatin1Char('/');
|
|
|
|
|
|
|
|
|
|
const QStringList list = output.split(QLatin1Char('\n'), QString::SkipEmptyParts);
|
|
|
|
|
|
|
|
|
|
QString path = directory;
|
|
|
|
|
if (!path.isEmpty())
|
|
|
|
|
path += slash;
|
|
|
|
|
foreach (const QString &l, list) {
|
|
|
|
|
// Status line containing file
|
|
|
|
|
if (l.startsWith(fileKeyword)) {
|
|
|
|
|
// Parse state
|
|
|
|
|
const int statusPos = l.indexOf(statusKeyword);
|
|
|
|
|
if (statusPos == -1)
|
|
|
|
|
continue;
|
|
|
|
|
const int state = stateFromKeyword(l.mid(statusPos + statusKeyword.size()).trimmed());
|
|
|
|
|
if (state == -1)
|
|
|
|
|
continue;
|
|
|
|
|
// Concatenate file name, Correct "no file <foo>"
|
|
|
|
|
QString fileName = l.mid(fileKeyword.size(), statusPos - fileKeyword.size()).trimmed();
|
2012-01-07 16:55:09 +01:00
|
|
|
if (state == CvsSubmitEditor::LocallyRemoved && fileName.startsWith(noFileKeyword))
|
2009-07-15 12:28:40 +02:00
|
|
|
fileName.remove(0, noFileKeyword.size());
|
2012-01-07 16:55:09 +01:00
|
|
|
changeSet.push_back(CvsSubmitEditor::StateFilePair(static_cast<CvsSubmitEditor::State>(state), path + fileName));
|
2009-07-15 12:28:40 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// Examining a new subdirectory
|
|
|
|
|
if (l.startsWith(directoryKeyword)) {
|
|
|
|
|
path = directory;
|
|
|
|
|
if (!path.isEmpty())
|
|
|
|
|
path += slash;
|
|
|
|
|
const QString newSubDir = l.mid(directoryKeyword.size()).trimmed();
|
|
|
|
|
if (newSubDir != dotDir) { // Skip Examining '.'
|
|
|
|
|
path += newSubDir;
|
|
|
|
|
path += slash;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return changeSet;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-06 17:24:40 +01:00
|
|
|
// Decrement version number "1.2" -> "1.1"
|
|
|
|
|
QString previousRevision(const QString &rev)
|
|
|
|
|
{
|
|
|
|
|
const int dotPos = rev.lastIndexOf(QLatin1Char('.'));
|
|
|
|
|
if (dotPos == -1)
|
|
|
|
|
return rev;
|
|
|
|
|
const int minor = rev.mid(dotPos + 1).toInt();
|
|
|
|
|
return rev.left(dotPos + 1) + QString::number(minor - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Is "[1.2...].1"?
|
|
|
|
|
bool isFirstRevision(const QString &r)
|
|
|
|
|
{
|
|
|
|
|
return r.endsWith(QLatin1String(".1"));
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-15 12:28:40 +02:00
|
|
|
} // namespace Internal
|
2012-01-07 16:55:09 +01:00
|
|
|
} // namespace Cvs
|