2016-11-16 12:51:32 -06:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2018-07-16 14:02:29 -05:00
|
|
|
** Copyright (c) 2018 Artur Shepilko
|
2016-11-16 12:51:32 -06:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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 The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "fossileditor.h"
|
|
|
|
|
#include "annotationhighlighter.h"
|
|
|
|
|
#include "constants.h"
|
|
|
|
|
#include "fossilplugin.h"
|
|
|
|
|
#include "fossilclient.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/synchronousprocess.h>
|
|
|
|
|
#include <vcsbase/diffandloghighlighter.h>
|
|
|
|
|
|
2017-04-20 02:21:51 -05:00
|
|
|
#include <QRegularExpression>
|
2016-11-16 12:51:32 -06:00
|
|
|
#include <QRegExp>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QTextCursor>
|
|
|
|
|
#include <QTextBlock>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
|
|
|
|
namespace Fossil {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2017-04-20 02:21:51 -05:00
|
|
|
class FossilEditorWidgetPrivate
|
2016-11-16 12:51:32 -06:00
|
|
|
{
|
2017-04-20 02:21:51 -05:00
|
|
|
public:
|
|
|
|
|
FossilEditorWidgetPrivate() :
|
2020-02-19 23:30:43 +02:00
|
|
|
m_exactChangesetId(Constants::CHANGESET_ID_EXACT)
|
2017-04-20 02:21:51 -05:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_exactChangesetId.isValid(), return);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const QRegularExpression m_exactChangesetId;
|
|
|
|
|
};
|
2016-11-16 12:51:32 -06:00
|
|
|
|
2017-04-20 02:21:51 -05:00
|
|
|
FossilEditorWidget::FossilEditorWidget() :
|
|
|
|
|
d(new FossilEditorWidgetPrivate)
|
|
|
|
|
{
|
2016-11-16 12:51:32 -06:00
|
|
|
setAnnotateRevisionTextFormat(tr("&Annotate %1"));
|
|
|
|
|
setAnnotatePreviousRevisionTextFormat(tr("Annotate &Parent Revision %1"));
|
|
|
|
|
|
2020-02-19 23:30:43 +02:00
|
|
|
const QRegularExpression exactDiffFileIdPattern(Constants::DIFFFILE_ID_EXACT);
|
2016-11-16 12:51:32 -06:00
|
|
|
QTC_ASSERT(exactDiffFileIdPattern.isValid(), return);
|
|
|
|
|
setDiffFilePattern(exactDiffFileIdPattern);
|
|
|
|
|
|
2020-02-19 23:30:43 +02:00
|
|
|
const QRegularExpression logChangePattern("^.*\\[([0-9a-f]{5,40})\\]");
|
2016-11-16 12:51:32 -06:00
|
|
|
QTC_ASSERT(logChangePattern.isValid(), return);
|
|
|
|
|
setLogEntryPattern(logChangePattern);
|
2020-02-19 23:30:43 +02:00
|
|
|
setAnnotationEntryPattern(QString("^") + Constants::CHANGESET_ID + " ");
|
2016-11-16 12:51:32 -06:00
|
|
|
}
|
|
|
|
|
|
2017-04-20 02:21:51 -05:00
|
|
|
FossilEditorWidget::~FossilEditorWidget()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-16 12:51:32 -06:00
|
|
|
QString FossilEditorWidget::changeUnderCursor(const QTextCursor &cursorIn) const
|
|
|
|
|
{
|
|
|
|
|
QTextCursor cursor = cursorIn;
|
|
|
|
|
cursor.select(QTextCursor::WordUnderCursor);
|
|
|
|
|
if (cursor.hasSelection()) {
|
|
|
|
|
const QString change = cursor.selectedText();
|
2017-04-20 02:21:51 -05:00
|
|
|
QRegularExpressionMatch exactChangesetIdMatch = d->m_exactChangesetId.match(change);
|
2016-11-16 12:51:32 -06:00
|
|
|
if (exactChangesetIdMatch.hasMatch())
|
|
|
|
|
return change;
|
|
|
|
|
}
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-16 12:25:41 -05:00
|
|
|
QString FossilEditorWidget::decorateVersion(const QString &revision) const
|
|
|
|
|
{
|
|
|
|
|
static const int shortChangesetIdSize(10);
|
|
|
|
|
static const int maxTextSize(120);
|
|
|
|
|
|
|
|
|
|
const QFileInfo fi(source());
|
|
|
|
|
const QString workingDirectory = fi.absolutePath();
|
2020-02-07 14:23:28 +01:00
|
|
|
const FossilClient *client = FossilPlugin::client();
|
2018-07-16 12:25:41 -05:00
|
|
|
RevisionInfo revisionInfo =
|
|
|
|
|
client->synchronousRevisionQuery(workingDirectory, revision, true);
|
|
|
|
|
|
|
|
|
|
// format: 'revision (committer "comment...")'
|
|
|
|
|
QString output = revision.left(shortChangesetIdSize)
|
|
|
|
|
+ " (" + revisionInfo.committer
|
|
|
|
|
+ " \"" + revisionInfo.commentMsg.left(maxTextSize);
|
|
|
|
|
|
|
|
|
|
if (output.size() > maxTextSize) {
|
|
|
|
|
output.truncate(maxTextSize - 3);
|
|
|
|
|
output.append("...");
|
|
|
|
|
}
|
|
|
|
|
output.append("\")");
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList FossilEditorWidget::annotationPreviousVersions(const QString &revision) const
|
|
|
|
|
{
|
|
|
|
|
QStringList revisions;
|
|
|
|
|
const QFileInfo fi(source());
|
|
|
|
|
const QString workingDirectory = fi.absolutePath();
|
2020-02-07 14:23:28 +01:00
|
|
|
const FossilClient *client = FossilPlugin::client();
|
2018-07-16 12:25:41 -05:00
|
|
|
RevisionInfo revisionInfo =
|
|
|
|
|
client->synchronousRevisionQuery(workingDirectory, revision);
|
|
|
|
|
if (revisionInfo.parentId.isEmpty())
|
|
|
|
|
return QStringList();
|
|
|
|
|
|
|
|
|
|
revisions.append(revisionInfo.parentId);
|
|
|
|
|
revisions.append(revisionInfo.mergeParentIds);
|
|
|
|
|
return revisions;
|
|
|
|
|
}
|
2016-11-16 12:51:32 -06:00
|
|
|
|
2018-07-16 12:25:41 -05:00
|
|
|
VcsBase::BaseAnnotationHighlighter *FossilEditorWidget::createAnnotationHighlighter(
|
|
|
|
|
const QSet<QString> &changes) const
|
2016-11-16 12:51:32 -06:00
|
|
|
{
|
|
|
|
|
return new FossilAnnotationHighlighter(changes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Fossil
|