VCS[git]: Add 'Revert this chunk' context menu option to diff view.

Implement in git. Add infrastructure to revert single chhunks
by using patch -R. Currently only implemented in git since
only that has functionality to re-run diff.

Rubber-stamped-by: hunger <tobias.hunger@nokia.com>
This commit is contained in:
Friedemann Kleint
2011-03-24 15:44:39 +01:00
parent fbe9925d8c
commit 491a27163a
10 changed files with 251 additions and 21 deletions

View File

@@ -86,6 +86,16 @@ struct VCSBASE_EXPORT VCSBaseEditorParameters
const char *extension;
};
class VCSBASE_EXPORT DiffChunk
{
public:
bool isValid() const;
QByteArray asPatch() const;
QString fileName;
QByteArray chunk;
};
// Base class for editors showing version control system output
// of the type enumerated by EditorContentType.
// The source property should contain the file or directory the log
@@ -99,6 +109,7 @@ class VCSBASE_EXPORT VCSBaseEditorWidget : public TextEditor::BaseTextEditorWidg
Q_PROPERTY(QString annotateRevisionTextFormat READ annotateRevisionTextFormat WRITE setAnnotateRevisionTextFormat)
Q_PROPERTY(QString copyRevisionTextFormat READ copyRevisionTextFormat WRITE setCopyRevisionTextFormat)
Q_PROPERTY(bool isFileLogAnnotateEnabled READ isFileLogAnnotateEnabled WRITE setFileLogAnnotateEnabled)
Q_PROPERTY(bool revertDiffChunkEnabled READ isRevertDiffChunkEnabled WRITE setRevertDiffChunkEnabled)
Q_OBJECT
protected:
@@ -146,6 +157,10 @@ public:
QString diffBaseDirectory() const;
void setDiffBaseDirectory(const QString &d);
// Diff: Can revert?
bool isRevertDiffChunkEnabled() const;
void setRevertDiffChunkEnabled(bool e);
bool isModified() const;
EditorContentType contentType() const;
@@ -194,6 +209,7 @@ signals:
// for LogOutput/AnnotateOutput content types.
void describeRequested(const QString &source, const QString &change);
void annotateRevisionRequested(const QString &source, const QString &change, int lineNumber);
void diffChunkReverted(const VCSBase::DiffChunk &dc);
public slots:
// Convenience slot to set data read from stdout, will use the
@@ -220,6 +236,7 @@ private slots:
void slotDiffCursorPositionChanged();
void slotAnnotateRevision();
void slotCopyRevision();
void slotRevertDiffChunk();
protected:
/* A helper that can be used to locate a file in a diff in case it
@@ -227,6 +244,10 @@ protected:
* source and version control. */
QString findDiffFile(const QString &f, Core::IVersionControl *control = 0) const;
virtual bool canRevertDiffChunk(const DiffChunk &dc) const;
// Revert a patch chunk. Default implemenation uses patch.exe
virtual bool revertDiffChunk(const DiffChunk &dc) const;
private:
// Implement to return a set of change identifiers in
// annotation mode
@@ -242,6 +263,8 @@ private:
// Implement to return the previous version[s] of an annotation change
// for "Annotate previous version"
virtual QStringList annotationPreviousVersions(const QString &revision) const;
// cut out chunk and determine file name.
DiffChunk diffChunk(QTextCursor cursor) const;
void jumpToChangeFromDiff(QTextCursor cursor);
QAction *createDescribeAction(const QString &change);
@@ -253,4 +276,6 @@ private:
} // namespace VCSBase
Q_DECLARE_METATYPE(VCSBase::DiffChunk)
#endif // VCSBASE_BASEEDITOR_H