bool Repository::setWorkingCopy(const QString& dirName) { const QFileInfo fi(dirName); const QString path = fi.absoluteFilePath(); // is this really a cvs-controlled directory? const QFileInfo cvsDirInfo(path + "/CVS"); if( !cvsDirInfo.exists() || !cvsDirInfo.isDir() || !QFile::exists( cvsDirInfo.filePath() + "/Entries" ) || !QFile::exists( cvsDirInfo.filePath() + "/Repository" ) || !QFile::exists( cvsDirInfo.filePath() + "/Root" ) ) return false; d->workingCopy = path; d->location.clear(); // determine path to the repository QFile rootFile(path + "/CVS/Root"); if( rootFile.open(QIODevice::ReadOnly) ) { QTextStream stream(&rootFile); d->location = stream.readLine(); } rootFile.close(); // add identities (ssh-add) to ssh-agent // TODO CL make sure this is called only once if( d->location.contains(":ext:", Qt::CaseInsensitive) ) { SshAgent ssh; ssh.addSshIdentities(); } QDir::setCurrent(path); d->readConfig(); return true; }
int CommandExec::exec(const QCommandLineParser *parser) { m_pCPart->parser = const_cast<QCommandLineParser*>(parser); m_pCPart->args = parser->positionalArguments(); if (m_pCPart->args.isEmpty()) { return -1; } m_lastMessages.clear(); m_lastMessagesLines = 0; m_pCPart->m_SvnWrapper->reInitClient(); bool dont_check_second = false; bool dont_check_all = false; bool path_only = false; bool no_revision = false; bool check_force = false; if (m_pCPart->args.count() >= 2) { m_pCPart->cmd = m_pCPart->args.at(1); m_pCPart->cmd = m_pCPart->cmd.toLower(); } QByteArray slotCmd; if (!QString::compare(m_pCPart->cmd, "log")) { slotCmd = SLOT(slotCmd_log()); } else if (!QString::compare(m_pCPart->cmd, "cat")) { slotCmd = SLOT(slotCmd_cat()); m_pCPart->single_revision = true; } else if (!QString::compare(m_pCPart->cmd, "get")) { slotCmd = SLOT(slotCmd_get()); m_pCPart->single_revision = true; } else if (!QString::compare(m_pCPart->cmd, "help")) { slotCmd = SLOT(slotCmd_help()); } else if (!QString::compare(m_pCPart->cmd, "blame") || !QString::compare(m_pCPart->cmd, "annotate")) { slotCmd = SLOT(slotCmd_blame()); } else if (!QString::compare(m_pCPart->cmd, "update")) { slotCmd = SLOT(slotCmd_update()); m_pCPart->single_revision = true; } else if (!QString::compare(m_pCPart->cmd, "diff")) { m_pCPart->start = svn::Revision::WORKING; slotCmd = SLOT(slotCmd_diff()); } else if (!QString::compare(m_pCPart->cmd, "info")) { slotCmd = SLOT(slotCmd_info()); m_pCPart->single_revision = true; } else if (!QString::compare(m_pCPart->cmd, "commit") || !QString::compare(m_pCPart->cmd, "ci")) { slotCmd = SLOT(slotCmd_commit()); } else if (!QString::compare(m_pCPart->cmd, "list") || !QString::compare(m_pCPart->cmd, "ls")) { slotCmd = SLOT(slotCmd_list()); } else if (!QString::compare(m_pCPart->cmd, "copy") || !QString::compare(m_pCPart->cmd, "cp")) { slotCmd = SLOT(slotCmd_copy()); dont_check_second = true; } else if (!QString::compare(m_pCPart->cmd, "move") || !QString::compare(m_pCPart->cmd, "rename") || !QString::compare(m_pCPart->cmd, "mv")) { slotCmd = SLOT(slotCmd_move()); dont_check_second = true; } else if (!QString::compare(m_pCPart->cmd, "checkout") || !QString::compare(m_pCPart->cmd, "co")) { slotCmd = SLOT(slotCmd_checkout()); dont_check_second = true; } else if (!QString::compare(m_pCPart->cmd, "checkoutto") || !QString::compare(m_pCPart->cmd, "coto")) { slotCmd = SLOT(slotCmd_checkoutto()); dont_check_second = true; } else if (!QString::compare(m_pCPart->cmd, "export")) { slotCmd = SLOT(slotCmd_export()); dont_check_second = true; } else if (!QString::compare(m_pCPart->cmd, "exportto")) { slotCmd = SLOT(slotCmd_exportto()); dont_check_second = true; } else if (!QString::compare(m_pCPart->cmd, "delete") || !QString::compare(m_pCPart->cmd, "del") || !QString::compare(m_pCPart->cmd, "rm") || !QString::compare(m_pCPart->cmd, "remove")) { slotCmd = SLOT(slotCmd_delete()); } else if (!QString::compare(m_pCPart->cmd, "add")) { slotCmd = SLOT(slotCmd_add()); dont_check_all = true; path_only = true; } else if (!QString::compare(m_pCPart->cmd, "undo") || !QString::compare(m_pCPart->cmd, "revert")) { slotCmd = SLOT(slotCmd_revert()); } else if (!QString::compare(m_pCPart->cmd, "checknew") || !QString::compare(m_pCPart->cmd, "addnew")) { slotCmd = SLOT(slotCmd_addnew()); } else if (!QString::compare(m_pCPart->cmd, "switch")) { slotCmd = SLOT(slotCmd_switch()); } else if (!QString::compare(m_pCPart->cmd, "tree")) { slotCmd = SLOT(slotCmd_tree()); } else if (!QString::compare(m_pCPart->cmd, "lock")) { slotCmd = SLOT(slotCmd_lock()); no_revision = true; check_force = true; } else if (!QString::compare(m_pCPart->cmd, "unlock")) { slotCmd = SLOT(slotCmd_unlock()); no_revision = true; check_force = true; } bool found = connect(this, SIGNAL(executeMe()), this, slotCmd.constData()); if (!found) { KMessageBox::sorry(0, i18n("Command \"%1\" not implemented or known", m_pCPart->cmd), i18n("SVN Error")); return -1; } QString tmp; QString mainProto; for (int j = 2; j < m_pCPart->args.count(); ++j) { QUrl tmpurl = QUrl::fromUserInput(m_pCPart->args.at(j), QDir::currentPath()); tmpurl.setScheme(svn::Url::transformProtokoll(tmpurl.scheme())); if (tmpurl.scheme().indexOf(QLatin1String("ssh")) != -1) { SshAgent ag; // this class itself checks if done before ag.addSshIdentities(); } m_pCPart->extraRevisions[j - 2] = svn::Revision::HEAD; if (tmpurl.isLocalFile() && (j == 2 || !dont_check_second) && !dont_check_all) { QUrl repoUrl; if (m_pCPart->m_SvnWrapper->isLocalWorkingCopy(tmpurl.path(), repoUrl)) { tmp = tmpurl.path(); m_pCPart->repoUrls[j - 2] = repoUrl; m_pCPart->extraRevisions[j - 2] = svn::Revision::WORKING; if (j == 2) { mainProto.clear(); } } else { tmp = tmpurl.url(); if (j == 2) { mainProto = QLatin1String("file://"); } } } else if (path_only) { tmp = tmpurl.path(); } else { tmp = tmpurl.url(); if (j == 2) { mainProto = tmpurl.scheme(); } } if ((j > 2 && dont_check_second) || dont_check_all) { if (mainProto.isEmpty()) { tmp = tmpurl.path(); } } const QStringList l = tmp.split(QLatin1Char('?'), QString::SkipEmptyParts); if (!l.isEmpty()) { tmp = l[0]; } while (tmp.endsWith(QLatin1Char('/'))) { tmp.chop(1); } m_pCPart->urls.append(tmp); if ((j > 2 && dont_check_second) || dont_check_all) { continue; } const QList<QPair<QString, QString> > q = QUrlQuery(tmpurl).queryItems(); for(int i = 0; i < q.size(); ++i) { if (q.at(i).first == QLatin1String("rev")) { svn::Revision re = q.at(i).second; if (re) { m_pCPart->extraRevisions[j - 2] = re; } } } } if (m_pCPart->urls.isEmpty()) { m_pCPart->urls.append(QLatin1String(".")); } if (!no_revision) { if (m_pCPart->parser->isSet("R")) { m_pCPart->ask_revision = true; if (!askRevision()) { return 0; } } else if (m_pCPart->parser->isSet("r")) { scanRevision(); } } m_pCPart->force = check_force && m_pCPart->parser->isSet("f"); if (m_pCPart->parser->isSet("o")) { m_pCPart->outfile_set = true; m_pCPart->outfile = m_pCPart->parser->value("o"); } if (m_pCPart->parser->isSet("l")) { QString s = m_pCPart->parser->value("l"); m_pCPart->log_limit = s.toInt(); if (m_pCPart->log_limit < 0) { m_pCPart->log_limit = 0; } } emit executeMe(); if (Kdesvnsettings::self()->cmdline_show_logwindow() && m_lastMessagesLines >= Kdesvnsettings::self()->cmdline_log_minline()) { QPointer<KSvnSimpleOkDialog> dlg(new KSvnSimpleOkDialog(QStringLiteral("kdesvn_cmd_log"), QApplication::activeModalWidget())); QTextBrowser *ptr = new QTextBrowser(dlg); ptr->setText(m_lastMessages); ptr->setReadOnly(true); dlg->addWidget(ptr); QString cmd = qApp->arguments().join(QLatin1Char(' ')); dlg->setWindowTitle(cmd); dlg->exec(); delete dlg; } return 0; }