3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
8 * \author Angus Leeming
10 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
19 #include "VCBackend.h"
22 #include "frontends/alert.h"
24 #include "support/debug.h"
25 #include "support/filetools.h"
26 #include "support/gettext.h"
27 #include "support/lstrings.h"
30 using namespace lyx::support;
34 namespace Alert = frontend::Alert;
43 // for the sake of boost::scoped_ptr
48 bool LyXVC::fileInVC(FileName const & fn)
50 if (!RCS::findFile(fn).empty())
52 if (!CVS::findFile(fn).empty())
54 if (!SVN::findFile(fn).empty())
60 bool LyXVC::file_found_hook(FileName const & fn)
63 // Check if file is under RCS
64 if (!(found_file = RCS::findFile(fn)).empty()) {
65 vcs.reset(new RCS(found_file, owner_));
68 // Check if file is under CVS
69 if (!(found_file = CVS::findFile(fn)).empty()) {
70 vcs.reset(new CVS(found_file, owner_));
73 // Check if file is under SVN
74 if (!(found_file = SVN::findFile(fn)).empty()) {
75 vcs.reset(new SVN(found_file, owner_));
79 // file is not under any VCS.
85 bool LyXVC::file_not_found_hook(FileName const & fn)
87 // Check if file is under RCS.
88 // This happens if we are trying to load non existent
89 // file on disk, but existent in ,v version.
90 bool foundRCS = !RCS::findFile(fn).empty();
91 bool foundCVS = foundRCS ? false : !CVS::findFile(fn).empty();
92 bool foundSVN = (foundRCS || foundCVS) ? false : !SVN::findFile(fn).empty();
93 if (foundRCS || foundCVS || foundSVN) {
94 docstring const file = makeDisplayPath(fn.absFileName(), 20);
95 docstring const text =
96 bformat(_("Do you want to retrieve the document"
97 " %1$s from version control?"), file);
98 int const ret = Alert::prompt(_("Retrieve from version control?"),
99 text, 0, 1, _("&Retrieve"), _("&Cancel"));
102 // Since the retrieve commands are implemented using
103 // more general update commands we need to ensure that
104 // we do not change an existing file by accident.
108 return RCS::retrieve(fn);
110 return CVS::retrieve(fn);
112 return SVN::retrieve(fn);
119 void LyXVC::setBuffer(Buffer * buf)
125 bool LyXVC::registrer()
127 FileName const filename = owner_->fileName();
129 // there must be a file to save
130 if (!filename.isReadableFile()) {
131 Alert::error(_("Document not saved"),
132 _("You must save the document "
133 "before it can be registered."));
137 // it is very likely here that the vcs is not created yet...
139 //check in the root directory of the document
140 FileName const cvs_entries(onlyPath(filename.absFileName()) + "/CVS/Entries");
141 FileName const svn_entries(onlyPath(filename.absFileName()) + "/.svn/entries");
143 if (svn_entries.isReadableFile()) {
144 LYXERR(Debug::LYXVC, "LyXVC: registering "
145 << to_utf8(filename.displayName()) << " with SVN");
146 vcs.reset(new SVN(cvs_entries, owner_));
148 } else if (cvs_entries.isReadableFile()) {
149 LYXERR(Debug::LYXVC, "LyXVC: registering "
150 << to_utf8(filename.displayName()) << " with CVS");
151 vcs.reset(new CVS(cvs_entries, owner_));
154 LYXERR(Debug::LYXVC, "LyXVC: registering "
155 << to_utf8(filename.displayName()) << " with RCS");
156 vcs.reset(new RCS(FileName(), owner_));
160 LYXERR(Debug::LYXVC, "LyXVC: registrer");
162 bool ok = Alert::askForText(response, _("LyX VC: Initial description"),
163 _("(no initial description)"));
165 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
169 if (response.empty())
170 response = _("(no initial description)");
171 vcs->registrer(to_utf8(response));
176 string LyXVC::checkIn()
178 LYXERR(Debug::LYXVC, "LyXVC: checkIn");
181 docstring empty(_("(no log message)"));
185 if (vcs->isCheckInWithConfirmation())
186 ok = Alert::askForText(response, _("LyX VC: Log Message"));
188 if (response.empty())
191 response = subst(response, from_utf8("\""), from_utf8("\\\""));
192 log = vcs->checkIn(to_utf8(response));
194 // Reserve empty string for cancel button
196 log = to_utf8(empty);
198 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
204 string LyXVC::checkOut()
208 //RCS allows checkOut only in ReadOnly mode
209 if (vcs->toggleReadOnlyEnabled() && !owner_->isReadonly())
212 LYXERR(Debug::LYXVC, "LyXVC: checkOut");
213 return vcs->checkOut();
217 string LyXVC::repoUpdate()
219 LYXERR(Debug::LYXVC, "LyXVC: repoUpdate");
222 return vcs->repoUpdate();
226 string LyXVC::lockingToggle()
228 LYXERR(Debug::LYXVC, "LyXVC: toggle locking property");
231 return vcs->lockingToggle();
237 LYXERR(Debug::LYXVC, "LyXVC: revert");
241 docstring const file = owner_->fileName().displayName(20);
242 docstring text = bformat(_("Reverting to the stored version of the "
243 "document %1$s will lose all current changes.\n\n"
244 "Do you want to revert to the older version?"), file);
246 if (vcs->isRevertWithConfirmation())
247 ret = Alert::prompt(_("Revert to stored version of document?"),
248 text, 0, 1, _("&Revert"), _("&Cancel"));
250 return ret == 0 && vcs->revert();
254 void LyXVC::undoLast()
262 void LyXVC::toggleReadOnly()
266 if (!vcs->toggleReadOnlyEnabled())
269 switch (vcs->status()) {
271 LYXERR(Debug::LYXVC, "LyXVC: toggle to locked");
275 LYXERR(Debug::LYXVC, "LyXVC: toggle to unlocked");
284 bool LyXVC::inUse() const
292 string const LyXVC::versionString() const
296 return vcs->versionString();
300 bool LyXVC::locking() const
304 return vcs->status() != VCS::NOLOCKING;
308 string const LyXVC::getLogFile() const
313 FileName const tmpf = FileName::tempName("lyxvclog");
315 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
318 LYXERR(Debug::LYXVC, "Generating logfile " << tmpf);
320 return tmpf.absFileName();
324 string LyXVC::revisionInfo(RevisionInfo const info) const
329 return vcs->revisionInfo(info);
333 bool LyXVC::checkOutEnabled() const
335 return vcs && vcs->checkOutEnabled();
339 bool LyXVC::checkInEnabled() const
341 return vcs && vcs->checkInEnabled();
345 bool LyXVC::lockingToggleEnabled() const
347 return vcs && vcs->lockingToggleEnabled();
351 bool LyXVC::undoLastEnabled() const
353 return vcs && vcs->undoLastEnabled();
357 bool LyXVC::repoUpdateEnabled() const
359 return vcs && vcs->repoUpdateEnabled();
363 bool LyXVC::prepareFileRevision(string const & rev, std::string & f)
365 return vcs && vcs->prepareFileRevision(rev, f);
369 bool LyXVC::prepareFileRevisionEnabled()
371 return vcs && vcs->prepareFileRevisionEnabled();