Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -366,5 +366,19 @@ bool GitEditor::supportChangeLinks() const ...@@ -366,5 +366,19 @@ bool GitEditor::supportChangeLinks() const
|| (editor()->id() == Git::Constants::GIT_REBASE_EDITOR_ID); || (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 Internal
} // namespace Git } // namespace Git
...@@ -74,6 +74,7 @@ private: ...@@ -74,6 +74,7 @@ private:
void addChangeActions(QMenu *menu, const QString &change); void addChangeActions(QMenu *menu, const QString &change);
QString revisionSubject(const QTextBlock &inBlock) const; QString revisionSubject(const QTextBlock &inBlock) const;
bool supportChangeLinks() const; bool supportChangeLinks() const;
QString fileNameForLine(int line) const;
mutable QRegExp m_changeNumberPattern; mutable QRegExp m_changeNumberPattern;
QString m_currentChange; QString m_currentChange;
......
...@@ -684,6 +684,12 @@ bool VcsBaseEditorWidget::supportChangeLinks() const ...@@ -684,6 +684,12 @@ bool VcsBaseEditorWidget::supportChangeLinks() const
} }
} }
QString VcsBaseEditorWidget::fileNameForLine(int line) const
{
Q_UNUSED(line);
return source();
}
void VcsBaseEditorWidget::init() void VcsBaseEditorWidget::init()
{ {
d->m_editor = editor(); d->m_editor = editor();
...@@ -1414,8 +1420,13 @@ void VcsBaseEditorWidget::addDiffActions(QMenu *, const DiffChunk &) ...@@ -1414,8 +1420,13 @@ void VcsBaseEditorWidget::addDiffActions(QMenu *, const DiffChunk &)
void VcsBaseEditorWidget::slotAnnotateRevision() void VcsBaseEditorWidget::slotAnnotateRevision()
{ {
if (const QAction *a = qobject_cast<const QAction *>(sender())) { if (const QAction *a = qobject_cast<const QAction *>(sender())) {
QFileInfo fi(source()); const int currentLine = editor()->currentLine();
emit annotateRevisionRequested(fi.absolutePath(), fi.fileName(), 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); a->data().toString(), currentLine);
} }
} }
......
...@@ -107,6 +107,7 @@ protected: ...@@ -107,6 +107,7 @@ protected:
// Pattern for log entry. hash/revision number must be in the first capture group // Pattern for log entry. hash/revision number must be in the first capture group
void setLogEntryPattern(const QRegExp &pattern); void setLogEntryPattern(const QRegExp &pattern);
virtual bool supportChangeLinks() const; virtual bool supportChangeLinks() const;
virtual QString fileNameForLine(int line) const;
public: public:
virtual void init(); virtual void init();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment