Esempio n. 1
0
void loadData(Database *database, const QString &qtPath)
{
     GitClient gitClient(qtPath);
     QStringList branches =
             gitClient.runCommand(QStringList() << "branch" << "-r");
     // qDebug() << "branches" << branches;

     // filter branches, allow x.y and "master"
    QStringList filteredBranches;
    foreach (const QString &candidate, branches) {
        if (candidate.simplified() == "origin/1.0.0") // for creator
            filteredBranches.append(candidate.simplified());
        if (candidate.simplified() == "origin/master")
            filteredBranches.append(candidate.simplified());
        if (candidate.count('.') == 1 && candidate.count('-') == 0)
            filteredBranches.append(candidate.simplified());

        //if (filteredBranches.count() > 1)
        //    break;
    }

    qDebug() << "Accepted branches" << filteredBranches;
    foreach (const QString &branch, filteredBranches)
        loadBranchData(database, branch, qtPath);
}
Esempio n. 2
0
// Prompt for restore: Make sure repository is unmodified,
// prompt for a branch if desired or just ask to restore.
// Note that the stash to be restored changes if the user
// chooses to stash away modified repository.
bool StashDialog::promptForRestore(QString *stash,
                                   QString *branch /* = 0*/,
                                   QString *errorMessage)
{
    const QString stashIn = *stash;
    bool modifiedPromptShown = false;
    switch (gitClient()->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules), 0, errorMessage)) {
    case GitClient::StatusFailed:
        return false;
    case GitClient::StatusChanged: {
            switch (promptModifiedRepository(*stash)) {
            case ModifiedRepositoryCancel:
                return false;
            case ModifiedRepositoryStash:
                if (gitClient()->synchronousStash(m_repository, QString(), GitClient::StashPromptDescription).isEmpty())
                    return false;
                *stash = nextStash(*stash); // Our stash id to be restored changed
                QTC_ASSERT(!stash->isEmpty(), return false);
                break;
            case ModifiedRepositoryDiscard:
                if (!gitClient()->synchronousReset(m_repository))
                    return false;
                break;
            }
        modifiedPromptShown = true;
    }
        break;
    case GitClient::StatusUnchanged:
        break;
    }
    // Prompt for branch or just ask.
    if (branch) {
        *branch = stashRestoreDefaultBranch(*stash);
        if (!inputText(this, tr("Restore Stash to Branch"), tr("Branch:"), branch)
            || branch->isEmpty())
            return false;
    } else {
        if (!modifiedPromptShown && !ask(tr("Stash Restore"), tr("Would you like to restore %1?").arg(stashIn)))
            return false;
    }
    return true;
}
Esempio n. 3
0
void StashDialog::deleteAll()
{
    const QString title = tr("Delete Stashes");
    if (!ask(title, tr("Do you want to delete all stashes?")))
        return;
    QString errorMessage;
    if (gitClient()->synchronousStashRemove(m_repository, QString(), &errorMessage))
        refresh(m_repository, true);
    else
        warning(title, errorMessage);
}
Esempio n. 4
0
void StashDialog::restoreCurrentInBranch()
{
    const int index = currentRow();
    QTC_ASSERT(index >= 0, return);
    QString errorMessage;
    QString branch;
    QString name = m_model->at(index).name;
    if (promptForRestore(&name, &branch, &errorMessage)
            && gitClient()->synchronousStashRestore(m_repository, name, false, branch)) {
        refresh(m_repository, true); // git deletes the stash, unfortunately.
    } else if (!errorMessage.isEmpty()) {
        warning(msgRestoreFailedTitle(name), errorMessage);
    }
}
Esempio n. 5
0
void StashDialog::restoreCurrent()
{
    const int index = currentRow();
    QTC_ASSERT(index >= 0, return);
    QString errorMessage;
    QString name = m_model->at(index).name;
    // Make sure repository is not modified, restore. The command will
    // output to window on success.
    if (promptForRestore(&name, 0, &errorMessage)
            && gitClient()->synchronousStashRestore(m_repository, name)) {
        refresh(m_repository, true); // Might have stashed away local changes.
    } else if (!errorMessage.isEmpty()) {
        warning(msgRestoreFailedTitle(name), errorMessage);
    }
}
Esempio n. 6
0
void StashDialog::deleteSelection()
{
    const QList<int> rows = selectedRows();
    QTC_ASSERT(!rows.isEmpty(), return);
    const QString title = tr("Delete Stashes");
    if (!ask(title, tr("Do you want to delete %n stash(es)?", 0, rows.size())))
        return;
    QString errorMessage;
    QStringList errors;
    // Delete in reverse order as stashes rotate
    for (int r = rows.size() - 1; r >= 0; r--)
        if (!gitClient()->synchronousStashRemove(m_repository, m_model->at(rows.at(r)).name, &errorMessage))
            errors.push_back(errorMessage);
    refresh(m_repository, true);
    if (!errors.isEmpty())
        warning(title, errors.join(QLatin1Char('\n')));
}
Esempio n. 7
0
void StashDialog::refresh(const QString &repository, bool force)
{
    if (m_repository == repository && !force)
        return;
    // Refresh
    m_repository = repository;
    ui->repositoryLabel->setText(msgRepositoryLabel(repository));
    if (m_repository.isEmpty()) {
        m_model->setStashes(QList<Stash>());
    } else {
        QList<Stash> stashes;
        gitClient()->synchronousStashList(m_repository, &stashes);
        m_model->setStashes(stashes);
        if (!stashes.isEmpty()) {
            for (int c = 0; c < ColumnCount; c++)
                ui->stashView->resizeColumnToContents(c);
        }
    }
    enableButtons();
}
Esempio n. 8
0
void StashDialog::showCurrent()
{
    const int index = currentRow();
    QTC_ASSERT(index >= 0, return);
    gitClient()->show(m_repository, QString(m_model->at(index).name));
}
Esempio n. 9
0
void loadBranchData(Database *database, const QString  branch, const QString &qtPath)
{
    // Get history from git
    QStringList timestamps;

    GitClient gitClient(qtPath);
    timestamps =
            gitClient.runCommand(QStringList() << "log" << branch
                                               << "--no-merges"
                                               << "--pretty=format:%H %ct %at"
                                               << "--shortstat");

    qDebug() << "found commits: " << branch << timestamps.count() / 2;

    database->transaction();

    // Parse and add rows to database;
    for (int i = 0; i < timestamps.count(); i+=2) {
        const QString line = timestamps.at(i);
        const QString line2 = timestamps.at(i + 1);

        // qDebug() << "lines" << i << line << line2;
/*
        // stop when we reach existing commits.

        if (database->selectVariant(
                QString("select Time from Commits where Time=%1 AND Branch='%2'")
                .arg(timestamp).arg(branch)).isValid()) {
            qDebug() << "has walue";
            break;
        }
*/
        // format: sha1 commit-time author-time
        QStringList parts = line.split(" ");
        if (parts.count() < 3) {
            qDebug() << "parse error" << line;
            continue;
        }
        QString sha1 = parts[0];
        QString commitTime = parts[1];
        QString authorTime = parts[2];
        QString branchName = branch.mid(QString("origin/").count(), -1);


        // format: 1 files changed, 1 insertions(+), 1 deletions(-)
        QStringList parts2 = line2.split(",");
        if (parts2.count() < 3) {
            qDebug() << "parse error" << line2;
            continue;
        }

        QString inserted = parts2.at(1).simplified().split(' ').at(0);
        QString deleted = parts2.at(2).simplified().split(' ').at(0);
        int patchSize = inserted.toInt() + deleted.toInt();
      //  qDebug() << "patch size" <<  patchSize;


        database->insertRow("Commits", QStringList() << "Branch" << "Sha1" << "CommitTime" << "PatchSize" ,
                                      QList<QVariant>() << branchName << sha1 << commitTime << patchSize);

    }
    database->commit();
}