]> git.lyx.org Git - lyx.git/blob - src/VCBackend.cpp
Transfer LyXfunc code to GuiApplication::dispatch() and getStatus(). Now
[lyx.git] / src / VCBackend.cpp
1 /**
2  * \file VCBackend.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "VCBackend.h"
14 #include "Buffer.h"
15 #include "LyX.h"
16 #include "FuncRequest.h"
17
18 #include "frontends/alert.h"
19 #include "frontends/Application.h"
20
21 #include "support/debug.h"
22 #include "support/filetools.h"
23 #include "support/gettext.h"
24 #include "support/lstrings.h"
25 #include "support/Path.h"
26 #include "support/Systemcall.h"
27
28 #include <boost/regex.hpp>
29
30 #include <fstream>
31
32 using namespace std;
33 using namespace lyx::support;
34
35 using boost::regex;
36 using boost::regex_match;
37 using boost::smatch;
38
39 namespace lyx {
40
41
42 int VCS::doVCCommandCall(string const & cmd, FileName const & path)
43 {
44         LYXERR(Debug::LYXVC, "doVCCommandCall: " << cmd);
45         Systemcall one;
46         support::PathChanger p(path);
47         return one.startscript(Systemcall::Wait, cmd, false);
48 }
49
50
51 int VCS::doVCCommand(string const & cmd, FileName const & path)
52 {
53         if (owner_)
54                 owner_->setBusy(true);
55
56         int const ret = doVCCommandCall(cmd, path);
57
58         if (owner_)
59                 owner_->setBusy(false);
60         if (ret)
61                 frontend::Alert::error(_("Revision control error."),
62                         bformat(_("Some problem occured while running the command:\n"
63                                   "'%1$s'."),
64                         from_utf8(cmd)));
65         return ret;
66 }
67
68
69 /////////////////////////////////////////////////////////////////////
70 //
71 // RCS
72 //
73 /////////////////////////////////////////////////////////////////////
74
75 RCS::RCS(FileName const & m)
76 {
77         master_ = m;
78         scanMaster();
79 }
80
81
82 FileName const RCS::findFile(FileName const & file)
83 {
84         // Check if *,v exists.
85         FileName tmp(file.absFilename() + ",v");
86         LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under rcs: " << tmp);
87         if (tmp.isReadableFile()) {
88                 LYXERR(Debug::LYXVC, "Yes, " << file << " is under rcs.");
89                 return tmp;
90         }
91
92         // Check if RCS/*,v exists.
93         tmp = FileName(addName(addPath(onlyPath(file.absFilename()), "RCS"), file.absFilename()) + ",v");
94         LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under rcs: " << tmp);
95         if (tmp.isReadableFile()) {
96                 LYXERR(Debug::LYXVC, "Yes, " << file << " is under rcs.");
97                 return tmp;
98         }
99
100         return FileName();
101 }
102
103
104 void RCS::retrieve(FileName const & file)
105 {
106         LYXERR(Debug::LYXVC, "LyXVC::RCS: retrieve.\n\t" << file);
107         doVCCommandCall("co -q -r " + quoteName(file.toFilesystemEncoding()),
108                          FileName());
109 }
110
111
112 void RCS::scanMaster()
113 {
114         if (master_.empty())
115                 return;
116
117         LYXERR(Debug::LYXVC, "LyXVC::RCS: scanMaster: " << master_);
118
119         ifstream ifs(master_.toFilesystemEncoding().c_str());
120
121         string token;
122         bool read_enough = false;
123
124         while (!read_enough && ifs >> token) {
125                 LYXERR(Debug::LYXVC, "LyXVC::scanMaster: current lex text: `"
126                         << token << '\'');
127
128                 if (token.empty())
129                         continue;
130                 else if (token == "head") {
131                         // get version here
132                         string tmv;
133                         ifs >> tmv;
134                         tmv = rtrim(tmv, ";");
135                         version_ = tmv;
136                         LYXERR(Debug::LYXVC, "LyXVC: version found to be " << tmv);
137                 } else if (contains(token, "access")
138                            || contains(token, "symbols")
139                            || contains(token, "strict")) {
140                         // nothing
141                 } else if (contains(token, "locks")) {
142                         // get locker here
143                         if (contains(token, ';')) {
144                                 locker_ = "Unlocked";
145                                 vcstatus = UNLOCKED;
146                                 continue;
147                         }
148                         string tmpt;
149                         string s1;
150                         string s2;
151                         do {
152                                 ifs >> tmpt;
153                                 s1 = rtrim(tmpt, ";");
154                                 // tmp is now in the format <user>:<version>
155                                 s1 = split(s1, s2, ':');
156                                 // s2 is user, and s1 is version
157                                 if (s1 == version_) {
158                                         locker_ = s2;
159                                         vcstatus = LOCKED;
160                                         break;
161                                 }
162                         } while (!contains(tmpt, ';'));
163
164                 } else if (token == "comment") {
165                         // we don't need to read any further than this.
166                         read_enough = true;
167                 } else {
168                         // unexpected
169                         LYXERR(Debug::LYXVC, "LyXVC::scanMaster(): unexpected token");
170                 }
171         }
172 }
173
174
175 void RCS::registrer(string const & msg)
176 {
177         string cmd = "ci -q -u -i -t-\"";
178         cmd += msg;
179         cmd += "\" ";
180         cmd += quoteName(onlyFilename(owner_->absFileName()));
181         doVCCommand(cmd, FileName(owner_->filePath()));
182 }
183
184
185 string RCS::checkIn(string const & msg)
186 {
187         int ret = doVCCommand("ci -q -u -m\"" + msg + "\" "
188                     + quoteName(onlyFilename(owner_->absFileName())),
189                     FileName(owner_->filePath()));
190         return ret ? string() : "RCS: Proceeded";
191 }
192
193
194 bool RCS::checkInEnabled()
195 {
196         return owner_ && !owner_->isReadonly();
197 }
198
199
200 string RCS::checkOut()
201 {
202         owner_->markClean();
203         int ret = doVCCommand("co -q -l " + quoteName(onlyFilename(owner_->absFileName())),
204                     FileName(owner_->filePath()));
205         return ret ? string() : "RCS: Proceeded";
206 }
207
208
209 bool RCS::checkOutEnabled()
210 {
211         return owner_ && owner_->isReadonly();
212 }
213
214
215 string RCS::repoUpdate()
216 {
217         lyxerr << "Sorry, not implemented." << endl;
218         return string();
219 }
220
221
222 bool RCS::repoUpdateEnabled()
223 {
224         return false;
225 }
226
227
228 string RCS::lockingToggle()
229 {
230         lyxerr << "Sorry, not implemented." << endl;
231         return string();
232 }
233
234
235 bool RCS::lockingToggleEnabled()
236 {
237         return false;
238 }
239
240
241 void RCS::revert()
242 {
243         doVCCommand("co -f -u" + version() + " "
244                     + quoteName(onlyFilename(owner_->absFileName())),
245                     FileName(owner_->filePath()));
246         // We ignore changes and just reload!
247         owner_->markClean();
248 }
249
250
251 void RCS::undoLast()
252 {
253         LYXERR(Debug::LYXVC, "LyXVC: undoLast");
254         doVCCommand("rcs -o" + version() + " "
255                     + quoteName(onlyFilename(owner_->absFileName())),
256                     FileName(owner_->filePath()));
257 }
258
259
260 bool RCS::undoLastEnabled()
261 {
262         return true;
263 }
264
265
266 void RCS::getLog(FileName const & tmpf)
267 {
268         doVCCommand("rlog " + quoteName(onlyFilename(owner_->absFileName()))
269                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
270                     FileName(owner_->filePath()));
271 }
272
273
274 bool RCS::toggleReadOnlyEnabled()
275 {
276         // This got broken somewhere along lfuns dispatch reorganization.
277         // reloadBuffer would be needed after this, but thats problematic
278         // since we are inside Buffer::dispatch.
279         // return true;
280         return false;
281 }
282
283
284 /////////////////////////////////////////////////////////////////////
285 //
286 // CVS
287 //
288 /////////////////////////////////////////////////////////////////////
289
290 CVS::CVS(FileName const & m, FileName const & f)
291 {
292         master_ = m;
293         file_ = f;
294         scanMaster();
295 }
296
297
298 FileName const CVS::findFile(FileName const & file)
299 {
300         // First we look for the CVS/Entries in the same dir
301         // where we have file.
302         FileName const entries(onlyPath(file.absFilename()) + "/CVS/Entries");
303         string const tmpf = '/' + onlyFilename(file.absFilename()) + '/';
304         LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under cvs in `" << entries
305                              << "' for `" << tmpf << '\'');
306         if (entries.isReadableFile()) {
307                 // Ok we are at least in a CVS dir. Parse the CVS/Entries
308                 // and see if we can find this file. We do a fast and
309                 // dirty parse here.
310                 ifstream ifs(entries.toFilesystemEncoding().c_str());
311                 string line;
312                 while (getline(ifs, line)) {
313                         LYXERR(Debug::LYXVC, "\tEntries: " << line);
314                         if (contains(line, tmpf))
315                                 return entries;
316                 }
317         }
318         return FileName();
319 }
320
321
322 void CVS::scanMaster()
323 {
324         LYXERR(Debug::LYXVC, "LyXVC::CVS: scanMaster. \n     Checking: " << master_);
325         // Ok now we do the real scan...
326         ifstream ifs(master_.toFilesystemEncoding().c_str());
327         string tmpf = '/' + onlyFilename(file_.absFilename()) + '/';
328         LYXERR(Debug::LYXVC, "\tlooking for `" << tmpf << '\'');
329         string line;
330         static regex const reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
331         while (getline(ifs, line)) {
332                 LYXERR(Debug::LYXVC, "\t  line: " << line);
333                 if (contains(line, tmpf)) {
334                         // Ok extract the fields.
335                         smatch sm;
336
337                         regex_match(line, sm, reg);
338
339                         //sm[0]; // whole matched string
340                         //sm[1]; // filename
341                         version_ = sm.str(2);
342                         string const file_date = sm.str(3);
343
344                         //sm[4]; // options
345                         //sm[5]; // tag or tagdate
346                         // FIXME: must double check file is stattable/existing
347                         time_t mod = file_.lastModified();
348                         string mod_date = rtrim(asctime(gmtime(&mod)), "\n");
349                         LYXERR(Debug::LYXVC, "Date in Entries: `" << file_date
350                                 << "'\nModification date of file: `" << mod_date << '\'');
351                         //FIXME this whole locking bussiness is not working under cvs and the machinery
352                         // conforms to the ci usage, not cvs.
353                         if (file_date == mod_date) {
354                                 locker_ = "Unlocked";
355                                 vcstatus = UNLOCKED;
356                         } else {
357                                 // Here we should also to some more checking
358                                 // to see if there are conflicts or not.
359                                 locker_ = "Locked";
360                                 vcstatus = LOCKED;
361                         }
362                         break;
363                 }
364         }
365 }
366
367
368 void CVS::registrer(string const & msg)
369 {
370         doVCCommand("cvs -q add -m \"" + msg + "\" "
371                     + quoteName(onlyFilename(owner_->absFileName())),
372                     FileName(owner_->filePath()));
373 }
374
375
376 string CVS::checkIn(string const & msg)
377 {
378         int ret = doVCCommand("cvs -q commit -m \"" + msg + "\" "
379                     + quoteName(onlyFilename(owner_->absFileName())),
380                     FileName(owner_->filePath()));
381         return ret ? string() : "CVS: Proceeded";
382 }
383
384
385 bool CVS::checkInEnabled()
386 {
387         return true;
388 }
389
390
391 string CVS::checkOut()
392 {
393         // cvs update or perhaps for cvs this should be a noop
394         // we need to detect conflict (eg "C" in output)
395         // before we can do this.
396         lyxerr << "Sorry, not implemented." << endl;
397         return string();
398 }
399
400
401 bool CVS::checkOutEnabled()
402 {
403         return false;
404 }
405
406
407 string CVS::repoUpdate()
408 {
409         lyxerr << "Sorry, not implemented." << endl;
410         return string();
411 }
412
413
414 bool CVS::repoUpdateEnabled()
415 {
416         return false;
417 }
418
419
420 string CVS::lockingToggle()
421 {
422         lyxerr << "Sorry, not implemented." << endl;
423         return string();
424 }
425
426
427 bool CVS::lockingToggleEnabled()
428 {
429         return false;
430 }
431
432
433 void CVS::revert()
434 {
435         // Reverts to the version in CVS repository and
436         // gets the updated version from the repository.
437         string const fil = quoteName(onlyFilename(owner_->absFileName()));
438         // This is sensitive operation, so at lest some check about
439         // existence of cvs program and its file
440         if (doVCCommand("cvs log "+ fil, FileName(owner_->filePath())))
441                 return;
442         FileName f(owner_->absFileName());
443         f.removeFile();
444         doVCCommand("cvs update " + fil,
445                     FileName(owner_->filePath()));
446         owner_->markClean();
447 }
448
449
450 void CVS::undoLast()
451 {
452         // merge the current with the previous version
453         // in a reverse patch kind of way, so that the
454         // result is to revert the last changes.
455         lyxerr << "Sorry, not implemented." << endl;
456 }
457
458
459 bool CVS::undoLastEnabled()
460 {
461         return false;
462 }
463
464
465 void CVS::getLog(FileName const & tmpf)
466 {
467         doVCCommand("cvs log " + quoteName(onlyFilename(owner_->absFileName()))
468                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
469                     FileName(owner_->filePath()));
470 }
471
472
473 bool CVS::toggleReadOnlyEnabled()
474 {
475         return false;
476 }
477
478 /////////////////////////////////////////////////////////////////////
479 //
480 // SVN
481 //
482 /////////////////////////////////////////////////////////////////////
483
484 SVN::SVN(FileName const & m, FileName const & f)
485 {
486         owner_ = 0;
487         master_ = m;
488         file_ = f;
489         locked_mode_ = 0;
490         scanMaster();
491 }
492
493
494 FileName const SVN::findFile(FileName const & file)
495 {
496         // First we look for the .svn/entries in the same dir
497         // where we have file.
498         FileName const entries(onlyPath(file.absFilename()) + "/.svn/entries");
499         string const tmpf = onlyFilename(file.absFilename());
500         LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn in `" << entries
501                              << "' for `" << tmpf << '\'');
502         if (entries.isReadableFile()) {
503                 // Ok we are at least in a SVN dir. Parse the .svn/entries
504                 // and see if we can find this file. We do a fast and
505                 // dirty parse here.
506                 ifstream ifs(entries.toFilesystemEncoding().c_str());
507                 string line, oldline;
508                 while (getline(ifs, line)) {
509                         if (line == "dir" || line == "file")
510                                 LYXERR(Debug::LYXVC, "\tEntries: " << oldline);
511                         if (oldline == tmpf && line == "file")
512                                 return entries;
513                         oldline = line;
514                 }
515         }
516         return FileName();
517 }
518
519
520 void SVN::scanMaster()
521 {
522         locker_.clear();
523         // vcstatus code is somewhat superflous, until we want
524         // to implement read-only toggle for svn.
525         vcstatus = NOLOCKING;
526         if (checkLockMode()) {
527                 if (isLocked()) {
528                         locker_ = "Locked";
529                         vcstatus = LOCKED;
530                 } else {
531                         locker_ = "Unlocked";
532                         vcstatus = UNLOCKED;
533                 }
534         }
535 }
536
537
538 bool SVN::checkLockMode()
539 {
540         FileName tmpf = FileName::tempName("lyxvcout");
541         if (tmpf.empty()){
542                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
543                 return N_("Error: Could not generate logfile.");
544         }
545
546         LYXERR(Debug::LYXVC, "Detecting locking mode...");
547         if (doVCCommandCall("svn proplist " + quoteName(file_.onlyFileName())
548                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
549                     file_.onlyPath()))
550                 return false;
551
552         ifstream ifs(tmpf.toFilesystemEncoding().c_str());
553         string line;
554         bool ret = false;
555
556         while (ifs) {
557                 getline(ifs, line);
558                 LYXERR(Debug::LYXVC, line);
559                 if (contains(line, "svn:needs-lock"))
560                         ret = true;
561         }
562         LYXERR(Debug::LYXVC, "Locking enabled: " << ret);
563         ifs.close();
564         locked_mode_ = ret;
565         return ret;
566
567 }
568
569
570 bool SVN::isLocked() const
571 {
572         file_.refresh();
573         return !file_.isReadOnly();
574 }
575
576
577 void SVN::registrer(string const & /*msg*/)
578 {
579         doVCCommand("svn add -q " + quoteName(onlyFilename(owner_->absFileName())),
580                     FileName(owner_->filePath()));
581 }
582
583
584 string SVN::checkIn(string const & msg)
585 {
586         FileName tmpf = FileName::tempName("lyxvcout");
587         if (tmpf.empty()){
588                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
589                 return N_("Error: Could not generate logfile.");
590         }
591
592         doVCCommand("svn commit -m \"" + msg + "\" "
593                     + quoteName(onlyFilename(owner_->absFileName()))
594                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
595                     FileName(owner_->filePath()));
596
597         string log;
598         string res = scanLogFile(tmpf, log);
599         if (!res.empty())
600                 frontend::Alert::error(_("Revision control error."),
601                                 _("Error when committing to repository.\n"
602                                 "You have to manually resolve the problem.\n"
603                                 "LyX will reopen the document after you press OK."));
604         else
605                 fileLock(false, tmpf, log);
606
607         tmpf.erase();
608         return log.empty() ? string() : "SVN: " + log;
609 }
610
611
612 bool SVN::checkInEnabled()
613 {
614         if (locked_mode_)
615                 return isLocked();
616         else
617                 return true;
618 }
619
620
621 // FIXME Correctly return code should be checked instead of this.
622 // This would need another solution than just plain startscript.
623 // Hint from Andre': QProcess::readAllStandardError()...
624 string SVN::scanLogFile(FileName const & f, string & status)
625 {
626         ifstream ifs(f.toFilesystemEncoding().c_str());
627         string line;
628
629         while (ifs) {
630                 getline(ifs, line);
631                 LYXERR(Debug::LYXVC, line << "\n");
632                 if (!line.empty()) 
633                         status += line + "; ";
634                 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
635                                          || contains(line, "Commit failed")) {
636                         ifs.close();
637                         return line;
638                 }
639                 if (contains(line, "svn:needs-lock")) {
640                         ifs.close();
641                         return line;
642                 }
643         }
644         ifs.close();
645         return string();
646 }
647
648
649 void SVN::fileLock(bool lock, FileName const & tmpf, string &status)
650 {
651         if (!locked_mode_ || (isLocked() == lock))
652                 return;
653
654         string const arg = lock ? "lock " : "unlock ";
655         doVCCommand("svn "+ arg + quoteName(onlyFilename(owner_->absFileName()))
656                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
657                     FileName(owner_->filePath()));
658
659         // Lock error messages go unfortunately on stderr and are unreachible this way.
660         ifstream ifs(tmpf.toFilesystemEncoding().c_str());
661         string line;
662         while (ifs) {
663                 getline(ifs, line);
664                 if (!line.empty()) status += line + "; ";
665         }
666         ifs.close();
667
668         if (!isLocked() && lock)
669                 frontend::Alert::error(_("Revision control error."),
670                         _("Error when acquiring write lock.\n"
671                         "Most probably another user is editing\n"
672                         "the current document now!\n"
673                         "Also check the access to the repository."));
674         if (isLocked() && !lock)
675                 frontend::Alert::error(_("Revision control error."),
676                         _("Error when releasing write lock.\n"
677                         "Check the access to the repository."));
678 }
679
680
681 string SVN::checkOut()
682 {
683         FileName tmpf = FileName::tempName("lyxvcout");
684         if (tmpf.empty()) {
685                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
686                 return N_("Error: Could not generate logfile.");
687         }
688
689         doVCCommand("svn update --non-interactive " + quoteName(onlyFilename(owner_->absFileName()))
690                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
691                     FileName(owner_->filePath()));
692
693         string log;
694         string res = scanLogFile(tmpf, log);
695         if (!res.empty())
696                 frontend::Alert::error(_("Revision control error."),
697                         bformat(_("Error when updating from repository.\n"
698                                 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
699                                 "After pressing OK, LyX will try to reopen the resolved document."),
700                         from_local8bit(res)));
701
702         fileLock(true, tmpf, log);
703
704         tmpf.erase();
705         return log.empty() ? string() : "SVN: " + log;
706 }
707
708
709 bool SVN::checkOutEnabled()
710 {
711         if (locked_mode_)
712                 return !isLocked();
713         else
714                 return true;
715 }
716
717
718 string SVN::repoUpdate()
719 {
720         FileName tmpf = FileName::tempName("lyxvcout");
721         if (tmpf.empty()) {
722                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
723                 return N_("Error: Could not generate logfile.");
724         }
725
726         doVCCommand("svn diff " + quoteName(owner_->filePath())
727         + " > " + quoteName(tmpf.toFilesystemEncoding()),
728         FileName(owner_->filePath()));
729         docstring res = tmpf.fileContents("UTF-8");
730         if (!res.empty()) {
731                 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
732                 docstring const file = from_utf8(owner_->filePath());
733                 docstring text = bformat(_("There were detected changes "
734                                 "in the working directory:\n%1$s\n\n"
735                                 "In case of file conflict version of the local directory files "
736                                 "will be preferred."
737                                 "\n\nContinue?"), file);
738                 int ret = frontend::Alert::prompt(_("Changes detected"),
739                                 text, 0, 1, _("&Yes"), _("&No"), _("View &Log ..."));
740                 if (ret == 2 ) {
741                         dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFilename()));
742                         ret = frontend::Alert::prompt(_("Changes detected"),
743                                 text, 0, 1, _("&Yes"), _("&No"));
744                         hideDialogs("file", 0);
745                 }
746                 if (ret == 1 ) {
747                         tmpf.erase();
748                         return string();
749                 }
750         }
751
752         // Reverting looks too harsh, see bug #6255.
753         // doVCCommand("svn revert -R " + quoteName(owner_->filePath())
754         // + " > " + quoteName(tmpf.toFilesystemEncoding()),
755         // FileName(owner_->filePath()));
756         // res = "Revert log:\n" + tmpf.fileContents("UTF-8");
757         doVCCommand("svn update --accept mine-full " + quoteName(owner_->filePath())
758                 + " > " + quoteName(tmpf.toFilesystemEncoding()),
759         FileName(owner_->filePath()));
760         res += "Update log:\n" + tmpf.fileContents("UTF-8");
761
762         LYXERR(Debug::LYXVC, res);
763         tmpf.erase();
764         return to_utf8(res);
765 }
766
767
768 bool SVN::repoUpdateEnabled()
769 {
770         return true;
771 }
772
773
774 string SVN::lockingToggle()
775 {
776         FileName tmpf = FileName::tempName("lyxvcout");
777         if (tmpf.empty()) {
778                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
779                 return N_("Error: Could not generate logfile.");
780         }
781
782         int ret = doVCCommand("svn proplist " + quoteName(onlyFilename(owner_->absFileName()))
783                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
784                     FileName(owner_->filePath()));
785         if (ret)
786                 return string();
787
788         string log;
789         string res = scanLogFile(tmpf, log);
790         bool locking = contains(res, "svn:needs-lock");
791         if (!locking)
792                 ret = doVCCommand("svn propset svn:needs-lock ON "
793                     + quoteName(onlyFilename(owner_->absFileName()))
794                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
795                     FileName(owner_->filePath()));
796         else
797                 ret = doVCCommand("svn propdel svn:needs-lock "
798                     + quoteName(onlyFilename(owner_->absFileName()))
799                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
800                     FileName(owner_->filePath()));
801         if (ret)
802                 return string();
803
804         tmpf.erase();
805         frontend::Alert::warning(_("VCN File Locking"),
806                 (locking ? _("Locking property unset.") : _("Locking property set.")) + "\n"
807                 + _("Do not forget to commit the locking property into the repository."),
808                 true);
809
810         return string("SVN: ") +  N_("Locking property set.");
811 }
812
813
814 bool SVN::lockingToggleEnabled()
815 {
816         return true;
817 }
818
819
820 void SVN::revert()
821 {
822         // Reverts to the version in CVS repository and
823         // gets the updated version from the repository.
824         string const fil = quoteName(onlyFilename(owner_->absFileName()));
825
826         doVCCommand("svn revert -q " + fil,
827                     FileName(owner_->filePath()));
828         owner_->markClean();
829 }
830
831
832 void SVN::undoLast()
833 {
834         // merge the current with the previous version
835         // in a reverse patch kind of way, so that the
836         // result is to revert the last changes.
837         lyxerr << "Sorry, not implemented." << endl;
838 }
839
840
841 bool SVN::undoLastEnabled()
842 {
843         return false;
844 }
845
846
847 void SVN::getLog(FileName const & tmpf)
848 {
849         doVCCommand("svn log " + quoteName(onlyFilename(owner_->absFileName()))
850                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
851                     FileName(owner_->filePath()));
852 }
853
854
855 bool SVN::toggleReadOnlyEnabled()
856 {
857         return false;
858 }
859
860
861 } // namespace lyx