bool SubversionBackend::AppendText(const QString path, const QString text) { QString repoPath(path); QString fileName = QFileInfo(path).baseName(); repoPath.replace(QRegExp("\\/[^\\/]+$"), ""); QTemporaryFile tmpFile("changelogger"); QString tmpPath; if (!tmpFile.open()) { return false; } tmpPath = tmpFile.fileName(); tmpFile.remove(); QDir(QDir::tempPath()).mkdir(tmpPath); tmpPath.prepend(QDir::separator()); tmpPath.prepend(QDir::tempPath()); if (QProcess::execute("svn", QStringList() << "co" << "--depth" << "files" << repoPath << tmpPath) != 0) { qDebug() << "Fehler beim auschecken nach: " << tmpPath; SubversionBackend::RecursiveRemove(tmpPath); return false; } qDebug() << "Checkout liegt in: " << tmpPath; qDebug() << "Filename ist: " << fileName; QString localChangeLogPath = tmpPath + QDir::separator() + fileName; QFile file(localChangeLogPath); if (!file.open(QFile::ReadOnly)) { qDebug() << localChangeLogPath + " kann nicht zum lesen geöffnet werden!"; SubversionBackend::RecursiveRemove(tmpPath); return false; } QString oldContent = QString::fromUtf8(file.readAll()); file.close(); if (!file.open(QFile::WriteOnly | QFile::Truncate)) { qDebug() << localChangeLogPath + " kann nicht zum schreiben geöffnet werden!"; SubversionBackend::RecursiveRemove(tmpPath); return false; } file.write(text.trimmed().toUtf8()); file.write("\n\n"); file.write(oldContent.trimmed().toUtf8()); file.write("\n"); file.close(); qDebug() << localChangeLogPath + " geschrieben!"; if (QProcess::execute("svn", QStringList() << "ci" << localChangeLogPath << "-m" << "Update via ChangeLogger") != 0) { qDebug() << "Fehler beim Check-In: " + tmpPath; return false; } SubversionBackend::RecursiveRemove(tmpPath); return true; }
bool SVNSourceControl::DetectRepository(const char *path) { BEntry entry(path); if (!entry.Exists()) return false; BPath repoPath(path); repoPath.Append(".svn"); entry.SetTo(repoPath.Path()); return entry.Exists(); }
status_t SVNSourceControl::DeleteRepository(const char *path) { if (!path || strlen(path) < 1) return B_ERROR; DPath workingDir(path); DPath repoPath(sRepoPath); repoPath << workingDir.GetFileName(); BString command("rm -r "); command << "'" << repoPath.GetFullPath() << "'"; BString out; RunCommand(command, out); return B_OK; }
status_t SVNSourceControl::CreateRepository(const char *path) { // The SourceControl class runs under the DSCM idea of the local directory // being a repository. Seeing how SVN doesn't allow for this, we create a // repository elsewhere on the hard drive, check it out to the path we were // given, and add the files to the repository. Checking in is not part of // this call, however. DPath workingDir(path); DPath repoPath(sRepoPath); repoPath << workingDir.GetFileName(); BDirectory dir(sRepoPath.String()); if (dir.InitCheck() != B_OK) create_directory(sRepoPath.String(), 0777); BString command("svnadmin create "); command << "'" << repoPath.GetFullPath() << "'"; BString out; RunCommand(command, out); BString repoURL = "file://"; repoURL << repoPath.GetFullPath(); SetURL(repoURL.String()); SetWorkingDirectory(path); CloneRepository(repoURL.String(), path); BPath svnpath(path); svnpath.Append(".svn"); if (!BEntry(svnpath.Path()).Exists()) return B_ERROR; command = ""; command << "cd '" << path << "'; " << "svn add --non-interactive *"; RunCommand(command, out); return B_OK; }