Commit aa5b0495 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

Git: Improve LogChangeWidget



* Enable display of local-only commits
* Enable specifying a top commit

Change-Id: I0688ba9ac670f709d2044ae2b7bff081fd86c860
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 8695fe6d
......@@ -126,19 +126,22 @@ void ChangeSelectionDialog::selectCommitFromRecentHistory()
if (workingDir.isEmpty())
return;
QString commit = change();
int tilde = commit.indexOf(QLatin1Char('~'));
if (tilde != -1)
commit.truncate(tilde);
QPointer<LogChangeDialog> dialog = new LogChangeDialog(false);
dialog->setWindowTitle(tr("Select Commit"));
dialog->runDialog(workingDir);
dialog->runDialog(workingDir, commit);
if (dialog->result() == QDialog::Rejected || dialog->commitIndex() == -1)
return;
QString change = QLatin1String("HEAD");
if (dialog->commitIndex() > 0)
change += QLatin1Char('~') + QString::number(dialog->commitIndex());
commit += QLatin1Char('~') + QString::number(dialog->commitIndex());
m_changeNumberEdit->setText(change);
m_changeNumberEdit->setText(commit);
}
void ChangeSelectionDialog::chooseWorkingDirectory()
......
......@@ -769,7 +769,7 @@ void GitPlugin::startRebase()
return;
LogChangeDialog dialog(false);
dialog.setWindowTitle(tr("Interactive Rebase"));
if (!dialog.runDialog(workingDirectory))
if (!dialog.runDialog(workingDirectory, QString(), false))
return;
const QString change = dialog.commit();
if (!change.isEmpty())
......
......@@ -168,7 +168,7 @@ void GitSubmitEditorWidget::initialize(CommitType commitType, const QString &rep
QVBoxLayout *logChangeLayout = new QVBoxLayout;
logChangeGroupBox->setLayout(logChangeLayout);
m_logChangeWidget = new LogChangeWidget;
m_logChangeWidget->init(repository);
m_logChangeWidget->init(repository, QString(), false);
logChangeLayout->addWidget(m_logChangeWidget);
insertTopWidget(logChangeGroupBox);
m_gitSubmitPanelUi.editGroup->hide();
......
......@@ -64,9 +64,9 @@ LogChangeWidget::LogChangeWidget(QWidget *parent)
setSelectionBehavior(QAbstractItemView::SelectRows);
}
bool LogChangeWidget::init(const QString &repository)
bool LogChangeWidget::init(const QString &repository, const QString &commit, bool includeRemote)
{
if (!populateLog(repository) || !m_model->rowCount())
if (!populateLog(repository, commit, includeRemote) || !m_model->rowCount())
return false;
selectionModel()->select(m_model->index(0, 0),
QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
......@@ -89,7 +89,7 @@ int LogChangeWidget::commitIndex() const
return -1;
}
bool LogChangeWidget::populateLog(const QString &repository)
bool LogChangeWidget::populateLog(const QString &repository, const QString &commit, bool includeRemote)
{
if (const int rowCount = m_model->rowCount())
m_model->removeRows(0, rowCount);
......@@ -98,6 +98,9 @@ bool LogChangeWidget::populateLog(const QString &repository)
GitClient *client = GitPlugin::instance()->gitClient();
QStringList arguments;
arguments << QLatin1String("--max-count=40") << QLatin1String("--format=%h:%s %d");
arguments << (commit.isEmpty() ? QLatin1String("HEAD") : commit);
if (!includeRemote)
arguments << QLatin1String("--not") << QLatin1String("--remotes");
QString output;
if (!client->synchronousLog(repository, arguments, &output))
return false;
......@@ -165,9 +168,9 @@ LogChangeDialog::LogChangeDialog(bool isReset, QWidget *parent) :
resize(600, 400);
}
bool LogChangeDialog::runDialog(const QString &repository)
bool LogChangeDialog::runDialog(const QString &repository, const QString &commit, bool includeRemote)
{
if (!widget->init(repository))
if (!widget->init(repository, commit, includeRemote))
return QDialog::Rejected;
return QDialog::exec() == QDialog::Accepted;
......
......@@ -52,12 +52,13 @@ class LogChangeWidget : public QTreeView
public:
explicit LogChangeWidget(QWidget *parent = 0);
bool init(const QString &repository);
bool init(const QString &repository, const QString &commit = QString(),
bool includeRemote = true);
QString commit() const;
int commitIndex() const;
private:
bool populateLog(const QString &repository);
bool populateLog(const QString &repository, const QString &commit, bool includeRemote);
const QStandardItem *currentItem(int column = 0) const;
QStandardItemModel *m_model;
......@@ -69,7 +70,8 @@ class LogChangeDialog : public QDialog
public:
LogChangeDialog(bool isReset, QWidget *parent = 0);
bool runDialog(const QString &repository);
bool runDialog(const QString &repository, const QString &commit = QString(),
bool includeRemote = true);
QString commit() const;
int commitIndex() const;
......
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