Commit 5e585b9e authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

Git: Support annotate revision for renamed files



Change-Id: I6993cdd6f91f29b6f4e990cc5ba332ff63f7ed9f
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 2a542705
......@@ -366,5 +366,19 @@ bool GitEditor::supportChangeLinks() const
|| (editor()->id() == Git::Constants::GIT_REBASE_EDITOR_ID);
}
QString GitEditor::fileNameForLine(int line) const
{
// 7971b6e7 share/qtcreator/dumper/dumper.py (hjk
QTextBlock block = document()->findBlockByLineNumber(line - 1);
QTC_ASSERT(block.isValid(), return source());
static QRegExp renameExp(QLatin1String("^" CHANGE_PATTERN "\\s+([^(]+)"));
if (renameExp.indexIn(block.text()) != -1) {
const QString fileName = renameExp.cap(1).trimmed();
if (!fileName.isEmpty())
return fileName;
}
return source();
}
} // namespace Internal
} // namespace Git
......@@ -74,6 +74,7 @@ private:
void addChangeActions(QMenu *menu, const QString &change);
QString revisionSubject(const QTextBlock &inBlock) const;
bool supportChangeLinks() const;
QString fileNameForLine(int line) const;
mutable QRegExp m_changeNumberPattern;
QString m_currentChange;
......
......@@ -684,6 +684,12 @@ bool VcsBaseEditorWidget::supportChangeLinks() const
}
}
QString VcsBaseEditorWidget::fileNameForLine(int line) const
{
Q_UNUSED(line);
return source();
}
void VcsBaseEditorWidget::init()
{
d->m_editor = editor();
......@@ -1414,8 +1420,13 @@ void VcsBaseEditorWidget::addDiffActions(QMenu *, const DiffChunk &)
void VcsBaseEditorWidget::slotAnnotateRevision()
{
if (const QAction *a = qobject_cast<const QAction *>(sender())) {
QFileInfo fi(source());
emit annotateRevisionRequested(fi.absolutePath(), fi.fileName(),
const int currentLine = editor()->currentLine();
const QString fileName = fileNameForLine(currentLine);
QString workingDirectory = d->m_workingDirectory;
if (workingDirectory.isEmpty())
workingDirectory = QFileInfo(fileName).absolutePath();
emit annotateRevisionRequested(workingDirectory,
QDir(workingDirectory).relativeFilePath(fileName),
a->data().toString(), currentLine);
}
}
......
......@@ -107,6 +107,7 @@ protected:
// Pattern for log entry. hash/revision number must be in the first capture group
void setLogEntryPattern(const QRegExp &pattern);
virtual bool supportChangeLinks() const;
virtual QString fileNameForLine(int line) const;
public:
virtual void init();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment