]> git.lyx.org Git - lyx.git/blob - src/VCBackend.cpp
680af815a1b810c7125d099bf2840b3328793326
[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  * \author Pavel Sanda
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "VCBackend.h"
15 #include "Buffer.h"
16 #include "LyX.h"
17 #include "FuncRequest.h"
18
19 #include "frontends/alert.h"
20 #include "frontends/Application.h"
21
22 #include "support/convert.h"
23 #include "support/debug.h"
24 #include "support/filetools.h"
25 #include "support/gettext.h"
26 #include "support/lstrings.h"
27 #include "support/PathChanger.h"
28 #include "support/Systemcall.h"
29 #include "support/TempFile.h"
30
31 #include <fstream>
32 #include <iomanip>
33 #include <regex>
34 #include <sstream>
35
36 using namespace std;
37 using namespace lyx::support;
38
39
40 namespace lyx {
41
42
43 int VCS::doVCCommandCall(string const & cmd, FileName const & path)
44 {
45         LYXERR(Debug::LYXVC, "doVCCommandCall: " << cmd);
46         Systemcall one;
47         support::PathChanger p(path);
48         return one.startscript(Systemcall::Wait, cmd, string(), string(), false);
49 }
50
51
52 int VCS::doVCCommand(string const & cmd, FileName const & path, bool reportError)
53 {
54         if (owner_)
55                 owner_->setBusy(true);
56
57         int const ret = doVCCommandCall(cmd, path);
58
59         if (owner_)
60                 owner_->setBusy(false);
61         if (ret && reportError) {
62                 docstring rcsmsg;
63                 if (prefixIs(cmd, "ci "))
64                         rcsmsg = "\n" + _("Perhaps the RCS package is not installed on your system?");
65                 frontend::Alert::error(_("Revision control error."),
66                         bformat(_("Some problem occurred while running the command:\n"
67                                   "'%1$s'.") + rcsmsg,
68                         from_utf8(cmd)));
69         }
70         return ret;
71 }
72
73
74 bool VCS::makeRCSRevision(string const &version, string &revis) const
75 {
76         string rev = revis;
77
78         if (isStrInt(rev)) {
79                 int back = convert<int>(rev);
80                 // if positive use as the last number in the whole revision string
81                 if (back > 0) {
82                         string base;
83                         rsplit(version, base , '.');
84                         rev = base + '.' + rev;
85                 }
86                 if (back == 0)
87                         rev = version;
88                 // we care about the last number from revision string
89                 // in case of backward indexing
90                 if (back < 0) {
91                         string cur, base;
92                         cur = rsplit(version, base , '.');
93                         if (!isStrInt(cur))
94                                 return false;
95                         int want = convert<int>(cur) + back;
96                         if (want <= 0)
97                                 return false;
98
99                         rev = base + '.' + convert<string>(want);
100                 }
101         }
102
103         revis = rev;
104         return true;
105 }
106
107
108 FileName VCS::checkParentDirs(FileName const & start, std::string const & file)
109 {
110         static FileName empty;
111         FileName dirname = start.onlyPath();
112         do {
113                 FileName tocheck = FileName(addPathName(dirname.absFileName(), file));
114                 LYXERR(Debug::LYXVC, "check file: " << tocheck.absFileName());
115                 if (tocheck.exists())
116                         return tocheck;
117                 // this construct because of #8295
118                 dirname = FileName(dirname.absFileName()).parentPath();
119         } while (!dirname.empty());
120         return empty;
121 }
122
123
124 /////////////////////////////////////////////////////////////////////
125 //
126 // RCS
127 //
128 /////////////////////////////////////////////////////////////////////
129
130 RCS::RCS(FileName const & m, Buffer * b) : VCS(b)
131 {
132         // Here we know that the buffer file is either already in RCS or
133         // about to be registered
134         master_ = m;
135         scanMaster();
136 }
137
138
139 FileName const RCS::findFile(FileName const & file)
140 {
141         // Check if *,v exists.
142         FileName tmp(file.absFileName() + ",v");
143         LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under rcs: " << tmp);
144         if (tmp.isReadableFile()) {
145                 LYXERR(Debug::LYXVC, "Yes, " << file << " is under rcs.");
146                 return tmp;
147         }
148
149         // Check if RCS/*,v exists.
150         tmp = FileName(addName(addPath(onlyPath(file.absFileName()), "RCS"), file.absFileName()) + ",v");
151         LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under rcs: " << tmp);
152         if (tmp.isReadableFile()) {
153                 LYXERR(Debug::LYXVC, "Yes, " << file << " is under rcs.");
154                 return tmp;
155         }
156
157         return FileName();
158 }
159
160
161 bool RCS::retrieve(FileName const & file)
162 {
163         LYXERR(Debug::LYXVC, "LyXVC::RCS: retrieve.\n\t" << file);
164         // The caller ensures that file does not exist, so no need to check that.
165         return doVCCommandCall("co -q -r " + quoteName(file.toFilesystemEncoding()),
166                                FileName()) == 0;
167 }
168
169
170 void RCS::scanMaster()
171 {
172         if (master_.empty())
173                 return;
174
175         LYXERR(Debug::LYXVC, "LyXVC::RCS: scanMaster: " << master_);
176
177         ifstream ifs(master_.toFilesystemEncoding().c_str());
178         // limit the size of strings we read to avoid memory problems
179         ifs >> setw(65636);
180
181         string token;
182         bool read_enough = false;
183
184         while (!read_enough && ifs >> token) {
185                 LYXERR(Debug::LYXVC, "LyXVC::scanMaster: current lex text: `"
186                         << token << '\'');
187
188                 if (token.empty())
189                         continue;
190                 else if (token == "head") {
191                         // get version here
192                         string tmv;
193                         ifs >> tmv;
194                         tmv = rtrim(tmv, ";");
195                         version_ = tmv;
196                         LYXERR(Debug::LYXVC, "LyXVC: version found to be " << tmv);
197                 } else if (contains(token, "access")
198                            || contains(token, "symbols")
199                            || contains(token, "strict")) {
200                         // nothing
201                 } else if (contains(token, "locks")) {
202                         // get locker here
203                         if (contains(token, ';')) {
204                                 locker_ = "Unlocked";
205                                 vcstatus_ = UNLOCKED;
206                                 continue;
207                         }
208                         string tmpt;
209                         string s1;
210                         string s2;
211                         do {
212                                 ifs >> tmpt;
213                                 s1 = rtrim(tmpt, ";");
214                                 // tmp is now in the format <user>:<version>
215                                 s1 = split(s1, s2, ':');
216                                 // s2 is user, and s1 is version
217                                 if (s1 == version_) {
218                                         locker_ = s2;
219                                         vcstatus_ = LOCKED;
220                                         break;
221                                 }
222                         } while (!contains(tmpt, ';'));
223
224                 } else if (token == "comment") {
225                         // we don't need to read any further than this.
226                         read_enough = true;
227                 } else {
228                         // unexpected
229                         LYXERR(Debug::LYXVC, "LyXVC::scanMaster(): unexpected token");
230                 }
231         }
232 }
233
234
235 void RCS::registrer(string const & msg)
236 {
237         string cmd = "ci -q -u -i -t-\"";
238         cmd += msg;
239         cmd += "\" ";
240         cmd += quoteName(onlyFileName(owner_->absFileName()));
241         doVCCommand(cmd, FileName(owner_->filePath()));
242 }
243
244
245 bool RCS::renameEnabled()
246 {
247         return false;
248 }
249
250
251 string RCS::rename(support::FileName const & /*newFile*/, string const & /*msg*/)
252 {
253         // not implemented, since a left-over file.lyx,v would be confusing.
254         return string();
255 }
256
257
258 bool RCS::copyEnabled()
259 {
260         return true;
261 }
262
263
264 string RCS::copy(support::FileName const & newFile, string const & msg)
265 {
266         // RCS has no real copy command, so we create a poor mans version
267         support::FileName const oldFile(owner_->absFileName());
268         if (!oldFile.copyTo(newFile))
269                 return string();
270         FileName path(oldFile.onlyPath());
271         string relFile(to_utf8(newFile.relPath(path.absFileName())));
272         string cmd = "ci -q -u -i -t-\"";
273         cmd += msg;
274         cmd += "\" ";
275         cmd += quoteName(relFile);
276         return doVCCommand(cmd, path) ? string() : "RCS: Proceeded";
277 }
278
279
280 LyXVC::CommandResult RCS::checkIn(string const & msg, string & log)
281 {
282         int ret = doVCCommand("ci -q -u -m\"" + msg + "\" "
283                     + quoteName(onlyFileName(owner_->absFileName())),
284                     FileName(owner_->filePath()));
285         if (ret)
286                 return LyXVC::ErrorCommand;
287         log = "RCS: Proceeded";
288         return LyXVC::VCSuccess;
289 }
290
291
292 bool RCS::checkInEnabled()
293 {
294         return owner_ && !owner_->hasReadonlyFlag();
295 }
296
297
298 bool RCS::isCheckInWithConfirmation()
299 {
300         // FIXME one day common getDiff for all backends
301         // docstring diff;
302         // if (getDiff(file, diff) && diff.empty())
303         //      return false;
304
305         TempFile tempfile("lyxvcout");
306         FileName tmpf = tempfile.name();
307         if (tmpf.empty()) {
308                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
309                 return true;
310         }
311
312         doVCCommandCall("rcsdiff " + quoteName(owner_->absFileName())
313                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
314                 FileName(owner_->filePath()));
315
316         docstring diff = tmpf.fileContents("UTF-8");
317
318         if (diff.empty())
319                 return false;
320
321         return true;
322 }
323
324
325 string RCS::checkOut()
326 {
327         owner_->markClean();
328         int ret = doVCCommand("co -q -l " + quoteName(onlyFileName(owner_->absFileName())),
329                     FileName(owner_->filePath()));
330         return ret ? string() : "RCS: Proceeded";
331 }
332
333
334 bool RCS::checkOutEnabled()
335 {
336         return owner_ && owner_->hasReadonlyFlag();
337 }
338
339
340 string RCS::repoUpdate()
341 {
342         lyxerr << "Sorry, not implemented." << endl;
343         return string();
344 }
345
346
347 bool RCS::repoUpdateEnabled()
348 {
349         return false;
350 }
351
352
353 string RCS::lockingToggle()
354 {
355         //FIXME this might be actually possible, study rcs -U, rcs -L.
356         //State should be easy to get inside scanMaster.
357         //It would fix #4370 and make rcs/svn usage even more closer.
358         lyxerr << "Sorry, not implemented." << endl;
359         return string();
360 }
361
362
363 bool RCS::lockingToggleEnabled()
364 {
365         return false;
366 }
367
368
369 bool RCS::revert()
370 {
371         if (doVCCommand("co -f -u" + version_ + ' '
372                     + quoteName(onlyFileName(owner_->absFileName())),
373                     FileName(owner_->filePath())))
374                 return false;
375         // We ignore changes and just reload!
376         owner_->markClean();
377         return true;
378 }
379
380
381 bool RCS::isRevertWithConfirmation()
382 {
383         //FIXME owner && diff ?
384         return true;
385 }
386
387
388 void RCS::undoLast()
389 {
390         LYXERR(Debug::LYXVC, "LyXVC: undoLast");
391         doVCCommand("rcs -o" + version_ + ' '
392                     + quoteName(onlyFileName(owner_->absFileName())),
393                     FileName(owner_->filePath()));
394 }
395
396
397 bool RCS::undoLastEnabled()
398 {
399         return owner_->hasReadonlyFlag();
400 }
401
402
403 void RCS::getLog(FileName const & tmpf)
404 {
405         doVCCommand("rlog " + quoteName(onlyFileName(owner_->absFileName()))
406                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
407                     FileName(owner_->filePath()));
408 }
409
410
411 bool RCS::toggleReadOnlyEnabled()
412 {
413         // This got broken somewhere along lfuns dispatch reorganization.
414         // reloadBuffer would be needed after this, but thats problematic
415         // since we are inside Buffer::dispatch.
416         // return true;
417         return false;
418 }
419
420
421 string RCS::revisionInfo(LyXVC::RevisionInfo const info)
422 {
423         if (info == LyXVC::File)
424                 return version_;
425         // fill the rest of the attributes for a single file
426         if (rev_date_cache_.empty())
427                 if (!getRevisionInfo())
428                         return string();
429
430         switch (info) {
431                 case LyXVC::Author:
432                         return rev_author_cache_;
433                 case LyXVC::Date:
434                         return rev_date_cache_;
435                 case LyXVC::Time:
436                         return rev_time_cache_;
437                 default:
438                         break;
439         }
440
441         return string();
442 }
443
444
445 bool RCS::getRevisionInfo()
446 {
447         TempFile tempfile("lyxvcout");
448         FileName tmpf = tempfile.name();
449         if (tmpf.empty()) {
450                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
451                 return false;
452         }
453         doVCCommand("rlog -r " + quoteName(onlyFileName(owner_->absFileName()))
454                 + " > " + quoteName(tmpf.toFilesystemEncoding()),
455                 FileName(owner_->filePath()));
456
457         if (tmpf.empty())
458                 return false;
459
460         ifstream ifs(tmpf.toFilesystemEncoding().c_str());
461         string line;
462
463         // we reached to the entry, i.e. after initial log message
464         bool entry=false;
465         // line with critical info, e.g:
466         //"date: 2011/07/02 11:02:54;  author: sanda;  state: Exp;  lines: +17 -2"
467         string result;
468
469         while (ifs) {
470                 getline(ifs, line);
471                 LYXERR(Debug::LYXVC, line);
472                 if (entry && prefixIs(line, "date:")) {
473                         result = line;
474                         break;
475                 }
476                 if (prefixIs(line, "revision"))
477                         entry = true;
478         }
479         if (result.empty())
480                 return false;
481
482         rev_date_cache_ = token(result, ' ', 1);
483         rev_time_cache_ = rtrim(token(result, ' ', 2), ";");
484         rev_author_cache_ = trim(token(token(result, ';', 1), ':', 1));
485
486         return !rev_author_cache_.empty();
487 }
488
489 bool RCS::prepareFileRevision(string const &revis, string & f)
490 {
491         string rev = revis;
492         if (!VCS::makeRCSRevision(version_, rev))
493                 return false;
494
495         TempFile tempfile("lyxvcrev_" + rev + '_');
496         tempfile.setAutoRemove(false);
497         FileName tmpf = tempfile.name();
498         if (tmpf.empty()) {
499                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
500                 return false;
501         }
502
503         doVCCommand("co -p" + rev + ' '
504                       + quoteName(onlyFileName(owner_->absFileName()))
505                       + " > " + quoteName(tmpf.toFilesystemEncoding()),
506                 FileName(owner_->filePath()));
507         tmpf.refresh();
508         if (tmpf.isFileEmpty())
509                 return false;
510
511         f = tmpf.absFileName();
512         return true;
513 }
514
515
516 bool RCS::prepareFileRevisionEnabled()
517 {
518         return true;
519 }
520
521
522 /////////////////////////////////////////////////////////////////////
523 //
524 // CVS
525 //
526 /////////////////////////////////////////////////////////////////////
527
528 CVS::CVS(FileName const & m, Buffer * b) : VCS(b)
529 {
530         // Here we know that the buffer file is either already in CVS or
531         // about to be registered
532         master_ = m;
533         have_rev_info_ = false;
534         scanMaster();
535 }
536
537
538 FileName const CVS::findFile(FileName const & file)
539 {
540         // First we look for the CVS/Entries in the same dir
541         // where we have file.
542         // Note that it is not necessary to search parent directories, since
543         // there will be a CVS/Entries file in every subdirectory.
544         FileName const entries(onlyPath(file.absFileName()) + "/CVS/Entries");
545         string const tmpf = '/' + onlyFileName(file.absFileName()) + '/';
546         LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under cvs in `" << entries
547                              << "' for `" << tmpf << '\'');
548         if (entries.isReadableFile()) {
549                 // Ok we are at least in a CVS dir. Parse the CVS/Entries
550                 // and see if we can find this file. We do a fast and
551                 // dirty parse here.
552                 ifstream ifs(entries.toFilesystemEncoding().c_str());
553                 string line;
554                 while (getline(ifs, line)) {
555                         LYXERR(Debug::LYXVC, "\tEntries: " << line);
556                         if (contains(line, tmpf))
557                                 return entries;
558                 }
559         }
560         return FileName();
561 }
562
563
564 void CVS::scanMaster()
565 {
566         LYXERR(Debug::LYXVC, "LyXVC::CVS: scanMaster. \n     Checking: " << master_);
567         // Ok now we do the real scan...
568         ifstream ifs(master_.toFilesystemEncoding().c_str());
569         string const name = onlyFileName(owner_->absFileName());
570         string const tmpf = '/' + name + '/';
571         LYXERR(Debug::LYXVC, "\tlooking for `" << tmpf << '\'');
572         string line;
573         static regex const reg("/(.*)/(.*)/(.*)/(.*)/(.*)");
574         while (getline(ifs, line)) {
575                 LYXERR(Debug::LYXVC, "\t  line: " << line);
576                 if (contains(line, tmpf)) {
577                         // Ok extract the fields.
578                         smatch sm;
579                         if (!regex_match(line, sm, reg)) {
580                                 LYXERR(Debug::LYXVC, "\t  Cannot parse line. Skipping.");
581                                 continue;
582                         }
583
584                         //sm[0]; // whole matched string
585                         //sm[1]; // filename
586                         version_ = sm.str(2);
587                         string const file_date = sm.str(3);
588
589                         //sm[4]; // options
590                         //sm[5]; // tag or tagdate
591                         FileName file(owner_->absFileName());
592                         if (file.isReadableFile()) {
593                                 time_t const mod = file.lastModified();
594                                 string const mod_date = rtrim(asctime(gmtime(&mod)), "\n");
595                                 LYXERR(Debug::LYXVC, "Date in Entries: `" << file_date
596                                         << "'\nModification date of file: `" << mod_date << '\'');
597                                 if (file.isReadOnly()) {
598                                         // readonly checkout is unlocked
599                                         vcstatus_ = UNLOCKED;
600                                 } else {
601                                         FileName bdir(addPath(master_.onlyPath().absFileName(),"Base"));
602                                         FileName base(addName(bdir.absFileName(),name));
603                                         // if base version is existent "cvs edit" was used to lock
604                                         vcstatus_ = base.isReadableFile() ? LOCKED : NOLOCKING;
605                                 }
606                         } else {
607                                 vcstatus_ = NOLOCKING;
608                         }
609                         break;
610                 }
611         }
612 }
613
614
615 bool CVS::retrieve(FileName const & file)
616 {
617         LYXERR(Debug::LYXVC, "LyXVC::CVS: retrieve.\n\t" << file);
618         // The caller ensures that file does not exist, so no need to check that.
619         return doVCCommandCall("cvs -q update " + quoteName(file.toFilesystemEncoding()),
620                                file.onlyPath()) == 0;
621 }
622
623
624 string const CVS::getTarget(OperationMode opmode) const
625 {
626         switch(opmode) {
627         case Directory:
628                 // in client server mode CVS does not like full path operand for directory operation
629                 // since LyX switches to the repo dir "." is good enough as target
630                 return ".";
631         case File:
632                 return quoteName(onlyFileName(owner_->absFileName()));
633         }
634         return string();
635 }
636
637
638 docstring CVS::toString(CvsStatus status) const
639 {
640         switch (status) {
641         case UpToDate:
642                 return _("Up-to-date");
643         case LocallyModified:
644                 return _("Locally Modified");
645         case LocallyAdded:
646                 return _("Locally Added");
647         case NeedsMerge:
648                 return _("Needs Merge");
649         case NeedsCheckout:
650                 return _("Needs Checkout");
651         case NoCvsFile:
652                 return _("No CVS file");
653         case StatusError:
654                 return _("Cannot retrieve CVS status");
655         }
656         return docstring();
657 }
658
659
660 int CVS::doVCCommandWithOutput(string const & cmd, FileName const & path,
661         FileName const & output, bool reportError)
662 {
663         string redirection = output.empty() ? "" : " > " + quoteName(output.toFilesystemEncoding());
664         return doVCCommand(cmd + redirection, path, reportError);
665 }
666
667
668 int CVS::doVCCommandCallWithOutput(std::string const & cmd,
669         support::FileName const & path,
670         support::FileName const & output)
671 {
672         string redirection = output.empty() ? "" : " > " + quoteName(output.toFilesystemEncoding());
673         return doVCCommandCall(cmd + redirection, path);
674 }
675
676
677 CVS::CvsStatus CVS::getStatus()
678 {
679         TempFile tempfile("lyxvout");
680         FileName tmpf = tempfile.name();
681         if (tmpf.empty()) {
682                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
683                 return StatusError;
684         }
685
686         if (doVCCommandCallWithOutput("cvs status " + getTarget(File),
687                 FileName(owner_->filePath()), tmpf)) {
688                 return StatusError;
689         }
690
691         ifstream ifs(tmpf.toFilesystemEncoding().c_str());
692         CvsStatus status = NoCvsFile;
693
694         while (ifs) {
695                 string line;
696                 getline(ifs, line);
697                 LYXERR(Debug::LYXVC, line << '\n');
698                 if (prefixIs(line, "File:")) {
699                         if (contains(line, "Up-to-date"))
700                                 status = UpToDate;
701                         else if (contains(line, "Locally Modified"))
702                                 status = LocallyModified;
703                         else if (contains(line, "Locally Added"))
704                                 status = LocallyAdded;
705                         else if (contains(line, "Needs Merge"))
706                                 status = NeedsMerge;
707                         else if (contains(line, "Needs Checkout"))
708                                 status = NeedsCheckout;
709                 }
710         }
711         return status;
712 }
713
714 void CVS::getRevisionInfo()
715 {
716         if (have_rev_info_)
717                 return;
718         have_rev_info_ = true;
719         TempFile tempfile("lyxvout");
720         FileName tmpf = tempfile.name();
721         if (tmpf.empty()) {
722                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
723                 return;
724         }
725
726         int rc = doVCCommandCallWithOutput("cvs log -r" + version_
727                 + ' ' + getTarget(File),
728                 FileName(owner_->filePath()), tmpf);
729         if (rc) {
730                 LYXERR(Debug::LYXVC, "cvs log failed with exit code " << rc);
731                 return;
732         }
733
734         ifstream ifs(tmpf.toFilesystemEncoding().c_str());
735         static regex const reg("date: (.*) (.*) (.*);  author: (.*);  state: (.*);(.*)");
736
737         while (ifs) {
738                 string line;
739                 getline(ifs, line);
740                 LYXERR(Debug::LYXVC, line << '\n');
741                 if (prefixIs(line, "date:")) {
742                         smatch sm;
743                         if (regex_match(line, sm, reg)) {
744                           //sm[0]; // whole matched string
745                           rev_date_cache_ = sm[1];
746                           rev_time_cache_ = sm[2];
747                           //sm[3]; // GMT offset
748                           rev_author_cache_ = sm[4];
749                         } else
750                           LYXERR(Debug::LYXVC, "\tCannot parse line. Skipping."); 
751                         break;
752                 }
753         }
754         if (rev_author_cache_.empty())
755                 LYXERR(Debug::LYXVC,
756                    "Could not retrieve revision info for " << version_ <<
757                    " of " << getTarget(File));
758 }
759
760
761 void CVS::registrer(string const & msg)
762 {
763         doVCCommand("cvs -q add -m \"" + msg + "\" "
764                 + getTarget(File),
765                 FileName(owner_->filePath()));
766 }
767
768
769 bool CVS::renameEnabled()
770 {
771         return true;
772 }
773
774
775 string CVS::rename(support::FileName const & newFile, string const & msg)
776 {
777         // CVS has no real rename command, so we create a poor mans version
778         support::FileName const oldFile(owner_->absFileName());
779         string ret = copy(newFile, msg);
780         if (ret.empty())
781                 return ret;
782         string cmd = "cvs -q remove -m \"" + msg + "\" " +
783                 quoteName(oldFile.onlyFileName());
784         FileName path(oldFile.onlyPath());
785         return doVCCommand(cmd, path) ? string() : ret;
786 }
787
788
789 bool CVS::copyEnabled()
790 {
791         return true;
792 }
793
794
795 string CVS::copy(support::FileName const & newFile, string const & msg)
796 {
797         // CVS has no real copy command, so we create a poor mans version
798         support::FileName const oldFile(owner_->absFileName());
799         if (!oldFile.copyTo(newFile))
800                 return string();
801         FileName path(oldFile.onlyPath());
802         string relFile(to_utf8(newFile.relPath(path.absFileName())));
803         string cmd("cvs -q add -m \"" + msg + "\" " + quoteName(relFile));
804         return doVCCommand(cmd, path) ? string() : "CVS: Proceeded";
805 }
806
807
808 void CVS::getDiff(OperationMode opmode, FileName const & tmpf)
809 {
810         doVCCommandWithOutput("cvs diff " + getTarget(opmode),
811                 FileName(owner_->filePath()), tmpf, false);
812 }
813
814
815 int CVS::edit()
816 {
817         vcstatus_ = LOCKED;
818         return doVCCommand("cvs -q edit " + getTarget(File),
819                 FileName(owner_->filePath()));
820 }
821
822
823 int CVS::unedit()
824 {
825         vcstatus_ = UNLOCKED;
826         return doVCCommand("cvs -q unedit " + getTarget(File),
827                 FileName(owner_->filePath()));
828 }
829
830
831 int CVS::update(OperationMode opmode, FileName const & tmpf)
832 {
833         return doVCCommandWithOutput("cvs -q update "
834                 + getTarget(opmode),
835                 FileName(owner_->filePath()), tmpf, false);
836 }
837
838
839 string CVS::scanLogFile(FileName const & f, string & status)
840 {
841         ifstream ifs(f.toFilesystemEncoding().c_str());
842
843         while (ifs) {
844                 string line;
845                 getline(ifs, line);
846                 LYXERR(Debug::LYXVC, line << '\n');
847                 if (!line.empty())
848                         status += line + "; ";
849                 if (prefixIs(line, "C ")) {
850                         ifs.close();
851                         return line;
852                 }
853         }
854         ifs.close();
855         return string();
856 }
857
858
859 LyXVC::CommandResult CVS::checkIn(string const & msg, string & log)
860 {
861         CvsStatus status = getStatus();
862         switch (status) {
863         case UpToDate:
864                 if (vcstatus_ != NOLOCKING)
865                         if (unedit())
866                                 return LyXVC::ErrorCommand;
867                 log = "CVS: Proceeded";
868                 return LyXVC::VCSuccess;
869         case LocallyModified:
870         case LocallyAdded: {
871                 int rc = doVCCommand("cvs -q commit -m \"" + msg + "\" "
872                         + getTarget(File),
873                     FileName(owner_->filePath()));
874                 if (rc)
875                         return LyXVC::ErrorCommand;
876                 log = "CVS: Proceeded";
877                 return LyXVC::VCSuccess;
878         }
879         case NeedsMerge:
880         case NeedsCheckout:
881                 frontend::Alert::error(_("Revision control error."),
882                         _("The repository version is newer then the current check out.\n"
883                           "You have to update from repository first or revert your changes.")) ;
884                 break;
885         default:
886                 frontend::Alert::error(_("Revision control error."),
887                         bformat(_("Bad status when checking in changes.\n"
888                                           "\n'%1$s'\n\n"),
889                                 toString(status)));
890                 break;
891         }
892         return LyXVC::ErrorBefore;
893 }
894
895
896 bool CVS::isLocked() const
897 {
898         FileName fn(owner_->absFileName());
899         fn.refresh();
900         return !fn.isReadOnly();
901 }
902
903
904 bool CVS::checkInEnabled()
905 {
906         if (vcstatus_ != NOLOCKING)
907                 return isLocked();
908         else
909                 return true;
910 }
911
912
913 bool CVS::isCheckInWithConfirmation()
914 {
915         CvsStatus status = getStatus();
916         return status == LocallyModified || status == LocallyAdded;
917 }
918
919
920 string CVS::checkOut()
921 {
922         if (vcstatus_ != NOLOCKING && edit())
923                 return string();
924         TempFile tempfile("lyxvout");
925         FileName tmpf = tempfile.name();
926         if (tmpf.empty()) {
927                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
928                 return string();
929         }
930
931         int rc = update(File, tmpf);
932         string log;
933         string const res = scanLogFile(tmpf, log);
934         if (!res.empty()) {
935                 frontend::Alert::error(_("Revision control error."),
936                         bformat(_("Error when updating from repository.\n"
937                                 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
938                                 "After pressing OK, LyX will try to reopen the resolved document."),
939                                 from_local8bit(res)));
940                 rc = 0;
941         }
942
943         return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
944 }
945
946
947 bool CVS::checkOutEnabled()
948 {
949         if (vcstatus_ != NOLOCKING)
950                 return !isLocked();
951         else
952                 return true;
953 }
954
955
956 string CVS::repoUpdate()
957 {
958         TempFile tempfile("lyxvout");
959         FileName tmpf = tempfile.name();
960         if (tmpf.empty()) {
961                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
962                 return string();
963         }
964
965         getDiff(Directory, tmpf);
966         docstring res = tmpf.fileContents("UTF-8");
967         if (!res.empty()) {
968                 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
969                 docstring const file = from_utf8(owner_->filePath());
970                 docstring text = bformat(_("There were detected changes "
971                                 "in the working directory:\n%1$s\n\n"
972                                 "Possible file conflicts must be then resolved manually "
973                                 "or you will need to revert back to the repository version."), file);
974                 int ret = frontend::Alert::prompt(_("Changes detected"),
975                                 text, 0, 1, _("&Continue"), _("&Abort"), _("View &Log ..."));
976                 if (ret == 2) {
977                         dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
978                         ret = frontend::Alert::prompt(_("Changes detected"),
979                                 text, 0, 1, _("&Continue"), _("&Abort"));
980                         hideDialogs("file", nullptr);
981                 }
982                 if (ret == 1)
983                         return string();
984         }
985
986         int rc = update(Directory, tmpf);
987         res += "Update log:\n" + tmpf.fileContents("UTF-8");
988         LYXERR(Debug::LYXVC, res);
989
990         string log;
991         string sres = scanLogFile(tmpf, log);
992         if (!sres.empty()) {
993                 docstring const file = owner_->fileName().displayName(20);
994                 frontend::Alert::error(_("Revision control error."),
995                         bformat(_("Error when updating document %1$s from repository.\n"
996                                           "You have to manually resolve the conflicts NOW!\n'%2$s'.\n\n"
997                                           "After pressing OK, LyX will try to reopen the resolved document."),
998                                 file, from_local8bit(sres)));
999                 rc = 0;
1000         }
1001
1002         return rc ? string() : log.empty() ? "CVS: Proceeded" : "CVS: " + log;
1003 }
1004
1005
1006 bool CVS::repoUpdateEnabled()
1007 {
1008         return true;
1009 }
1010
1011
1012 string CVS::lockingToggle()
1013 {
1014         lyxerr << "Sorry, not implemented." << endl;
1015         return string();
1016 }
1017
1018
1019 bool CVS::lockingToggleEnabled()
1020 {
1021         return false;
1022 }
1023
1024
1025 bool CVS::isRevertWithConfirmation()
1026 {
1027         CvsStatus status = getStatus();
1028         return !owner_->isClean() || status == LocallyModified || status == NeedsMerge;
1029 }
1030
1031
1032 bool CVS::revert()
1033 {
1034         // Reverts to the version in CVS repository and
1035         // gets the updated version from the repository.
1036         CvsStatus status = getStatus();
1037         switch (status) {
1038         case UpToDate:
1039                 if (vcstatus_ != NOLOCKING)
1040                         return 0 == unedit();
1041                 break;
1042         case NeedsMerge:
1043         case NeedsCheckout:
1044         case LocallyModified: {
1045                 FileName f(owner_->absFileName());
1046                 f.removeFile();
1047                 update(File, FileName());
1048                 owner_->markClean();
1049                 break;
1050         }
1051         case LocallyAdded: {
1052                 docstring const file = owner_->fileName().displayName(20);
1053                 frontend::Alert::error(_("Revision control error."),
1054                         bformat(_("The document %1$s is not in repository.\n"
1055                                   "You have to check in the first revision before you can revert."),
1056                                 file)) ;
1057                 return false;
1058         }
1059         default: {
1060                 docstring const file = owner_->fileName().displayName(20);
1061                 frontend::Alert::error(_("Revision control error."),
1062                         bformat(_("Cannot revert document %1$s to repository version.\n"
1063                                   "The status '%2$s' is unexpected."),
1064                                 file, toString(status)));
1065                 return false;
1066                 }
1067         }
1068         return true;
1069 }
1070
1071
1072 void CVS::undoLast()
1073 {
1074         // merge the current with the previous version
1075         // in a reverse patch kind of way, so that the
1076         // result is to revert the last changes.
1077         lyxerr << "Sorry, not implemented." << endl;
1078 }
1079
1080
1081 bool CVS::undoLastEnabled()
1082 {
1083         return false;
1084 }
1085
1086
1087 void CVS::getLog(FileName const & tmpf)
1088 {
1089         doVCCommandWithOutput("cvs log " + getTarget(File),
1090                 FileName(owner_->filePath()),
1091                 tmpf);
1092 }
1093
1094
1095 bool CVS::toggleReadOnlyEnabled()
1096 {
1097         return false;
1098 }
1099
1100
1101 string CVS::revisionInfo(LyXVC::RevisionInfo const info)
1102 {
1103         if (!version_.empty()) {
1104                 getRevisionInfo();
1105                 switch (info) {
1106                 case LyXVC::File:
1107                         return version_;
1108                 case LyXVC::Author:
1109                         return rev_author_cache_;
1110                 case LyXVC::Date:
1111                         return rev_date_cache_;
1112                 case LyXVC::Time:
1113                         return rev_time_cache_;
1114                 default:
1115                         break;
1116                 }
1117         }
1118         return string();
1119 }
1120
1121
1122 bool CVS::prepareFileRevision(string const & revis, string & f)
1123 {
1124         string rev = revis;
1125         if (!VCS::makeRCSRevision(version_, rev))
1126                 return false;
1127
1128         TempFile tempfile("lyxvcrev_" + rev + '_');
1129         tempfile.setAutoRemove(false);
1130         FileName tmpf = tempfile.name();
1131         if (tmpf.empty()) {
1132                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1133                 return false;
1134         }
1135
1136         doVCCommandWithOutput("cvs update -p -r" + rev + ' '
1137                 + getTarget(File),
1138                 FileName(owner_->filePath()), tmpf);
1139         tmpf.refresh();
1140         if (tmpf.isFileEmpty())
1141                 return false;
1142
1143         f = tmpf.absFileName();
1144         return true;
1145 }
1146
1147
1148 bool CVS::prepareFileRevisionEnabled()
1149 {
1150         return true;
1151 }
1152
1153
1154 /////////////////////////////////////////////////////////////////////
1155 //
1156 // SVN
1157 //
1158 /////////////////////////////////////////////////////////////////////
1159
1160 SVN::SVN(FileName const & m, Buffer * b) : VCS(b)
1161 {
1162         // Here we know that the buffer file is either already in SVN or
1163         // about to be registered
1164         master_ = m;
1165         locked_mode_ = false;
1166         scanMaster();
1167 }
1168
1169
1170 FileName const SVN::findFile(FileName const & file)
1171 {
1172         // First we check the existence of repository meta data.
1173         if (VCS::checkParentDirs(file, ".svn").empty()) {
1174                 LYXERR(Debug::LYXVC, "Cannot find SVN meta data for " << file);
1175                 return FileName();
1176         }
1177
1178         // Now we check the status of the file.
1179         string const fname = onlyFileName(file.absFileName());
1180         LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under svn control for `" << fname << '\'');
1181         bool found = 0 == doVCCommandCall("svn info " + quoteName(fname),
1182                                                 file.onlyPath());
1183         LYXERR(Debug::LYXVC, "SVN control: " << (found ? "enabled" : "disabled"));
1184         return found ? file : FileName();
1185 }
1186
1187
1188 void SVN::scanMaster()
1189 {
1190         // vcstatus code is somewhat superflous,
1191         // until we want to implement read-only toggle for svn.
1192         vcstatus_ = NOLOCKING;
1193         if (checkLockMode()) {
1194                 if (isLocked())
1195                         vcstatus_ = LOCKED;
1196                 else
1197                         vcstatus_ = UNLOCKED;
1198         }
1199 }
1200
1201
1202 bool SVN::checkLockMode()
1203 {
1204         TempFile tempfile("lyxvcout");
1205         FileName tmpf = tempfile.name();
1206         if (tmpf.empty()){
1207                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1208                 return false;
1209         }
1210
1211         LYXERR(Debug::LYXVC, "Detecting locking mode...");
1212         if (doVCCommandCall("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
1213                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
1214                     FileName(owner_->filePath())))
1215                 return false;
1216
1217         ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1218         string line;
1219         bool ret = false;
1220
1221         while (ifs && !ret) {
1222                 getline(ifs, line);
1223                 LYXERR(Debug::LYXVC, line);
1224                 if (contains(line, "svn:needs-lock"))
1225                         ret = true;
1226         }
1227         LYXERR(Debug::LYXVC, "Locking enabled: " << ret);
1228         ifs.close();
1229         locked_mode_ = ret;
1230         return ret;
1231
1232 }
1233
1234
1235 bool SVN::isLocked() const
1236 {
1237         FileName file(owner_->absFileName());
1238         file.refresh();
1239         return !file.isReadOnly();
1240 }
1241
1242
1243 bool SVN::retrieve(FileName const & file)
1244 {
1245         LYXERR(Debug::LYXVC, "LyXVC::SVN: retrieve.\n\t" << file);
1246         // The caller ensures that file does not exist, so no need to check that.
1247         return doVCCommandCall("svn update -q --non-interactive " + quoteName(file.onlyFileName()),
1248                                file.onlyPath()) == 0;
1249 }
1250
1251
1252 void SVN::registrer(string const & /*msg*/)
1253 {
1254         doVCCommand("svn add -q " + quoteName(onlyFileName(owner_->absFileName())),
1255                     FileName(owner_->filePath()));
1256 }
1257
1258
1259 bool SVN::renameEnabled()
1260 {
1261         return true;
1262 }
1263
1264
1265 string SVN::rename(support::FileName const & newFile, string const & msg)
1266 {
1267         // svn move does not require a log message, since it does not commit.
1268         // In LyX we commit immediately afterwards, otherwise it could be
1269         // confusing to the user to have two uncommitted files.
1270         FileName path(owner_->filePath());
1271         string relFile(to_utf8(newFile.relPath(path.absFileName())));
1272         string cmd("svn move -q " + quoteName(onlyFileName(owner_->absFileName())) +
1273                    ' ' + quoteName(relFile));
1274         if (doVCCommand(cmd, path)) {
1275                 cmd = "svn revert -q " +
1276                         quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1277                         quoteName(relFile);
1278                 doVCCommand(cmd, path);
1279                 if (newFile.exists())
1280                         newFile.removeFile();
1281                 return string();
1282         }
1283         vector<support::FileName> f;
1284         f.push_back(owner_->fileName());
1285         f.push_back(newFile);
1286         string log;
1287         if (checkIn(f, msg, log) != LyXVC::VCSuccess) {
1288                 cmd = "svn revert -q " +
1289                         quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1290                         quoteName(relFile);
1291                 doVCCommand(cmd, path);
1292                 if (newFile.exists())
1293                         newFile.removeFile();
1294                 return string();
1295         }
1296         return log;
1297 }
1298
1299
1300 bool SVN::copyEnabled()
1301 {
1302         return true;
1303 }
1304
1305
1306 string SVN::copy(support::FileName const & newFile, string const & msg)
1307 {
1308         // svn copy does not require a log message, since it does not commit.
1309         // In LyX we commit immediately afterwards, otherwise it could be
1310         // confusing to the user to have an uncommitted file.
1311         FileName path(owner_->filePath());
1312         string relFile(to_utf8(newFile.relPath(path.absFileName())));
1313         string cmd("svn copy -q " + quoteName(onlyFileName(owner_->absFileName())) +
1314                    ' ' + quoteName(relFile));
1315         if (doVCCommand(cmd, path))
1316                 return string();
1317         vector<support::FileName> f(1, newFile);
1318         string log;
1319         if (checkIn(f, msg, log) == LyXVC::VCSuccess)
1320                 return log;
1321         return string();
1322 }
1323
1324
1325 LyXVC::CommandResult SVN::checkIn(string const & msg, string & log)
1326 {
1327         vector<support::FileName> f(1, owner_->fileName());
1328         return checkIn(f, msg, log);
1329 }
1330
1331
1332 LyXVC::CommandResult
1333 SVN::checkIn(vector<support::FileName> const & f, string const & msg, string & log)
1334 {
1335         TempFile tempfile("lyxvcout");
1336         FileName tmpf = tempfile.name();
1337         if (tmpf.empty()){
1338                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1339                 log = N_("Error: Could not generate logfile.");
1340                 return LyXVC::ErrorBefore;
1341         }
1342
1343         ostringstream os;
1344         os << "svn commit -m \"" << msg << '"';
1345         for (size_t i = 0; i < f.size(); ++i)
1346                 os << ' ' << quoteName(f[i].onlyFileName());
1347         os << " > " << quoteName(tmpf.toFilesystemEncoding());
1348         LyXVC::CommandResult ret =
1349                 doVCCommand(os.str(), FileName(owner_->filePath())) ?
1350                         LyXVC::ErrorCommand : LyXVC::VCSuccess;
1351
1352         string res = scanLogFile(tmpf, log);
1353         if (!res.empty()) {
1354                 frontend::Alert::error(_("Revision control error."),
1355                                 _("Error when committing to repository.\n"
1356                                 "You have to manually resolve the problem.\n"
1357                                 "LyX will reopen the document after you press OK."));
1358                 ret = LyXVC::ErrorCommand;
1359         }
1360         else
1361                 if (!fileLock(false, tmpf, log))
1362                         ret = LyXVC::ErrorCommand;
1363
1364         if (!log.empty())
1365                 log.insert(0, "SVN: ");
1366         if (ret == LyXVC::VCSuccess && log.empty())
1367                 log = "SVN: Proceeded";
1368         return ret;
1369 }
1370
1371
1372 bool SVN::checkInEnabled()
1373 {
1374         if (locked_mode_)
1375                 return isLocked();
1376         else
1377                 return true;
1378 }
1379
1380
1381 bool SVN::isCheckInWithConfirmation()
1382 {
1383         // FIXME one day common getDiff and perhaps OpMode for all backends
1384
1385         TempFile tempfile("lyxvcout");
1386         FileName tmpf = tempfile.name();
1387         if (tmpf.empty()) {
1388                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1389                 return true;
1390         }
1391
1392         doVCCommandCall("svn diff " + quoteName(owner_->absFileName())
1393                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
1394                 FileName(owner_->filePath()));
1395
1396         docstring diff = tmpf.fileContents("UTF-8");
1397
1398         if (diff.empty())
1399                 return false;
1400
1401         return true;
1402 }
1403
1404
1405 // FIXME Correctly return code should be checked instead of this.
1406 // This would need another solution than just plain startscript.
1407 // Hint from Andre': QProcess::readAllStandardError()...
1408 string SVN::scanLogFile(FileName const & f, string & status)
1409 {
1410         ifstream ifs(f.toFilesystemEncoding().c_str());
1411         string line;
1412
1413         while (ifs) {
1414                 getline(ifs, line);
1415                 LYXERR(Debug::LYXVC, line << '\n');
1416                 if (!line.empty())
1417                         status += line + "; ";
1418                 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
1419                                          || contains(line, "Commit failed")) {
1420                         ifs.close();
1421                         return line;
1422                 }
1423                 if (contains(line, "svn:needs-lock")) {
1424                         ifs.close();
1425                         return line;
1426                 }
1427         }
1428         ifs.close();
1429         return string();
1430 }
1431
1432
1433 bool SVN::fileLock(bool lock, FileName const & tmpf, string &status)
1434 {
1435         if (!locked_mode_ || (isLocked() == lock))
1436                 return true;
1437
1438         string const arg = lock ? "lock " : "unlock ";
1439         doVCCommand("svn "+ arg + quoteName(onlyFileName(owner_->absFileName()))
1440                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
1441                     FileName(owner_->filePath()));
1442
1443         // Lock error messages go unfortunately on stderr and are unreachable this way.
1444         ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1445         string line;
1446         while (ifs) {
1447                 getline(ifs, line);
1448                 if (!line.empty()) status += line + "; ";
1449         }
1450         ifs.close();
1451
1452         if (isLocked() == lock)
1453                 return true;
1454
1455         if (lock)
1456                 frontend::Alert::error(_("Revision control error."),
1457                         _("Error while acquiring write lock.\n"
1458                         "Another user is most probably editing\n"
1459                         "the current document now!\n"
1460                         "Also check the access to the repository."));
1461         else
1462                 frontend::Alert::error(_("Revision control error."),
1463                         _("Error while releasing write lock.\n"
1464                         "Check the access to the repository."));
1465         return false;
1466 }
1467
1468
1469 string SVN::checkOut()
1470 {
1471         TempFile tempfile("lyxvcout");
1472         FileName tmpf = tempfile.name();
1473         if (tmpf.empty()) {
1474                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1475                 return N_("Error: Could not generate logfile.");
1476         }
1477
1478         doVCCommand("svn update --non-interactive " + quoteName(onlyFileName(owner_->absFileName()))
1479                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
1480                     FileName(owner_->filePath()));
1481
1482         string log;
1483         string const res = scanLogFile(tmpf, log);
1484         if (!res.empty())
1485                 frontend::Alert::error(_("Revision control error."),
1486                         bformat(_("Error when updating from repository.\n"
1487                                 "You have to manually resolve the conflicts NOW!\n'%1$s'.\n\n"
1488                                 "After pressing OK, LyX will try to reopen the resolved document."),
1489                         from_local8bit(res)));
1490
1491         fileLock(true, tmpf, log);
1492
1493         return log.empty() ? string() : "SVN: " + log;
1494 }
1495
1496
1497 bool SVN::checkOutEnabled()
1498 {
1499         if (locked_mode_)
1500                 return !isLocked();
1501         else
1502                 return true;
1503 }
1504
1505
1506 string SVN::repoUpdate()
1507 {
1508         TempFile tempfile("lyxvcout");
1509         FileName tmpf = tempfile.name();
1510         if (tmpf.empty()) {
1511                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1512                 return N_("Error: Could not generate logfile.");
1513         }
1514
1515         doVCCommand("svn diff " + quoteName(owner_->filePath())
1516                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
1517                 FileName(owner_->filePath()));
1518         docstring res = tmpf.fileContents("UTF-8");
1519         if (!res.empty()) {
1520                 LYXERR(Debug::LYXVC, "Diff detected:\n" << res);
1521                 docstring const file = from_utf8(owner_->filePath());
1522                 docstring text = bformat(_("There were detected changes "
1523                                 "in the working directory:\n%1$s\n\n"
1524                                 "In case of file conflict version of the local directory files "
1525                                 "will be preferred."
1526                                 "\n\nContinue?"), file);
1527                 int ret = frontend::Alert::prompt(_("Changes detected"),
1528                                 text, 0, 1, _("&Yes"), _("&No"), _("View &Log ..."));
1529                 if (ret == 2) {
1530                         dispatch(FuncRequest(LFUN_DIALOG_SHOW, "file " + tmpf.absFileName()));
1531                         ret = frontend::Alert::prompt(_("Changes detected"),
1532                                 text, 0, 1, _("&Yes"), _("&No"));
1533                         hideDialogs("file", nullptr);
1534                 }
1535                 if (ret == 1)
1536                         return string();
1537         }
1538
1539         // Reverting looks too harsh, see bug #6255.
1540         // doVCCommand("svn revert -R " + quoteName(owner_->filePath())
1541         // + " > " + quoteName(tmpf.toFilesystemEncoding()),
1542         // FileName(owner_->filePath()));
1543         // res = "Revert log:\n" + tmpf.fileContents("UTF-8");
1544         doVCCommand("svn update --accept mine-full " + quoteName(owner_->filePath())
1545                 + " > " + quoteName(tmpf.toFilesystemEncoding()),
1546                 FileName(owner_->filePath()));
1547         res += "Update log:\n" + tmpf.fileContents("UTF-8");
1548
1549         LYXERR(Debug::LYXVC, res);
1550         return to_utf8(res);
1551 }
1552
1553
1554 bool SVN::repoUpdateEnabled()
1555 {
1556         return true;
1557 }
1558
1559
1560 string SVN::lockingToggle()
1561 {
1562         TempFile tempfile("lyxvcout");
1563         FileName tmpf = tempfile.name();
1564         if (tmpf.empty()) {
1565                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1566                 return N_("Error: Could not generate logfile.");
1567         }
1568
1569         int ret = doVCCommand("svn proplist " + quoteName(onlyFileName(owner_->absFileName()))
1570                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
1571                     FileName(owner_->filePath()));
1572         if (ret)
1573                 return string();
1574
1575         string log;
1576         string res = scanLogFile(tmpf, log);
1577         bool locking = contains(res, "svn:needs-lock");
1578         if (!locking)
1579                 ret = doVCCommand("svn propset svn:needs-lock ON "
1580                     + quoteName(onlyFileName(owner_->absFileName()))
1581                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
1582                     FileName(owner_->filePath()));
1583         else
1584                 ret = doVCCommand("svn propdel svn:needs-lock "
1585                     + quoteName(onlyFileName(owner_->absFileName()))
1586                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
1587                     FileName(owner_->filePath()));
1588         if (ret)
1589                 return string();
1590
1591         frontend::Alert::warning(_("SVN File Locking"),
1592                 (locking ? _("Locking property unset.") : _("Locking property set.")) + '\n'
1593                 + _("Do not forget to commit the locking property into the repository."),
1594                 true);
1595
1596         return string("SVN: ") + (locking ?
1597                 N_("Locking property unset.") : N_("Locking property set."));
1598 }
1599
1600
1601 bool SVN::lockingToggleEnabled()
1602 {
1603         return true;
1604 }
1605
1606
1607 bool SVN::revert()
1608 {
1609         // Reverts to the version in SVN repository and
1610         // gets the updated version from the repository.
1611         string const fil = quoteName(onlyFileName(owner_->absFileName()));
1612
1613         if (doVCCommand("svn revert -q " + fil,
1614                     FileName(owner_->filePath())))
1615                 return false;
1616         owner_->markClean();
1617         return true;
1618 }
1619
1620
1621 bool SVN::isRevertWithConfirmation()
1622 {
1623         //FIXME owner && diff
1624         return true;
1625 }
1626
1627
1628 void SVN::undoLast()
1629 {
1630         // merge the current with the previous version
1631         // in a reverse patch kind of way, so that the
1632         // result is to revert the last changes.
1633         lyxerr << "Sorry, not implemented." << endl;
1634 }
1635
1636
1637 bool SVN::undoLastEnabled()
1638 {
1639         return false;
1640 }
1641
1642
1643 string SVN::revisionInfo(LyXVC::RevisionInfo const info)
1644 {
1645         if (info == LyXVC::Tree) {
1646                 if (rev_tree_cache_.empty())
1647                         if (!getTreeRevisionInfo())
1648                                 rev_tree_cache_ = "?";
1649                 if (rev_tree_cache_ == "?")
1650                         return string();
1651
1652                 return rev_tree_cache_;
1653         }
1654
1655         // fill the rest of the attributes for a single file
1656         if (rev_file_cache_.empty())
1657                 if (!getFileRevisionInfo())
1658                         rev_file_cache_ = "?";
1659
1660         switch (info) {
1661                 case LyXVC::File:
1662                         if (rev_file_cache_ == "?")
1663                                 return string();
1664                         return rev_file_cache_;
1665                 case LyXVC::Author:
1666                         return rev_author_cache_;
1667                 case LyXVC::Date:
1668                         return rev_date_cache_;
1669                 case LyXVC::Time:
1670                         return rev_time_cache_;
1671                 default:
1672                         break;
1673         }
1674
1675         return string();
1676 }
1677
1678
1679 bool SVN::getFileRevisionInfo()
1680 {
1681         TempFile tempfile("lyxvcout");
1682         FileName tmpf = tempfile.name();
1683         if (tmpf.empty()) {
1684                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1685                 return false;
1686         }
1687
1688         doVCCommand("svn info --xml " + quoteName(onlyFileName(owner_->absFileName()))
1689                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
1690                     FileName(owner_->filePath()));
1691
1692         if (tmpf.empty())
1693                 return false;
1694
1695         ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1696         string line;
1697         // commit log part
1698         bool c = false;
1699         string rev;
1700
1701         while (ifs) {
1702                 getline(ifs, line);
1703                 LYXERR(Debug::LYXVC, line);
1704                 if (prefixIs(line, "<commit"))
1705                         c = true;
1706                 if (c && prefixIs(line, "   revision=\"") && suffixIs(line, "\">")) {
1707                         string l1 = subst(line, "revision=\"", "");
1708                         string l2 = trim(subst(l1, "\">", ""));
1709                         if (isStrInt(l2))
1710                                 rev_file_cache_ = rev = l2;
1711                 }
1712                 if (c && prefixIs(line, "<author>") && suffixIs(line, "</author>")) {
1713                         string l1 = subst(line, "<author>", "");
1714                         string l2 = subst(l1, "</author>", "");
1715                         rev_author_cache_ = l2;
1716                 }
1717                 if (c && prefixIs(line, "<date>") && suffixIs(line, "</date>")) {
1718                         string l1 = subst(line, "<date>", "");
1719                         string l2 = subst(l1, "</date>", "");
1720                         l2 = split(l2, l1, 'T');
1721                         rev_date_cache_ = l1;
1722                         l2 = split(l2, l1, '.');
1723                         rev_time_cache_ = l1;
1724                 }
1725         }
1726
1727         ifs.close();
1728         return !rev.empty();
1729 }
1730
1731
1732 bool SVN::getTreeRevisionInfo()
1733 {
1734         TempFile tempfile("lyxvcout");
1735         FileName tmpf = tempfile.name();
1736         if (tmpf.empty()) {
1737                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1738                 return false;
1739         }
1740
1741         doVCCommand("svnversion -n . > " + quoteName(tmpf.toFilesystemEncoding()),
1742                     FileName(owner_->filePath()));
1743
1744         if (tmpf.empty())
1745                 return false;
1746
1747         // only first line in case something bad happens.
1748         ifstream ifs(tmpf.toFilesystemEncoding().c_str());
1749         string line;
1750         getline(ifs, line);
1751         ifs.close();
1752
1753         rev_tree_cache_ = line;
1754         return !line.empty();
1755 }
1756
1757
1758 void SVN::getLog(FileName const & tmpf)
1759 {
1760         doVCCommand("svn log " + quoteName(onlyFileName(owner_->absFileName()))
1761                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
1762                     FileName(owner_->filePath()));
1763 }
1764
1765
1766 bool SVN::prepareFileRevision(string const & revis, string & f)
1767 {
1768         if (!isStrInt(revis))
1769                 return false;
1770
1771         int rev = convert<int>(revis);
1772         if (rev <= 0)
1773                 if (!getFileRevisionInfo())
1774                         return false;
1775         if (rev == 0)
1776                 rev = convert<int>(rev_file_cache_);
1777         // go back for minus rev
1778         else if (rev < 0) {
1779                 rev = rev + convert<int>(rev_file_cache_);
1780                 if (rev < 1)
1781                         return false;
1782         }
1783
1784         string revname = convert<string>(rev);
1785         TempFile tempfile("lyxvcrev_" + revname + '_');
1786         tempfile.setAutoRemove(false);
1787         FileName tmpf = tempfile.name();
1788         if (tmpf.empty()) {
1789                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1790                 return false;
1791         }
1792
1793         doVCCommand("svn cat -r " + revname + ' '
1794                       + quoteName(onlyFileName(owner_->absFileName()))
1795                       + " > " + quoteName(tmpf.toFilesystemEncoding()),
1796                 FileName(owner_->filePath()));
1797         tmpf.refresh();
1798         if (tmpf.isFileEmpty())
1799                 return false;
1800
1801         f = tmpf.absFileName();
1802         return true;
1803 }
1804
1805
1806 bool SVN::prepareFileRevisionEnabled()
1807 {
1808         return true;
1809 }
1810
1811
1812
1813 bool SVN::toggleReadOnlyEnabled()
1814 {
1815         return false;
1816 }
1817
1818
1819 /////////////////////////////////////////////////////////////////////
1820 //
1821 // GIT
1822 //
1823 /////////////////////////////////////////////////////////////////////
1824
1825 GIT::GIT(FileName const & m, Buffer * b) : VCS(b)
1826 {
1827         // Here we know that the buffer file is either already in GIT or
1828         // about to be registered
1829         master_ = m;
1830         scanMaster();
1831 }
1832
1833
1834 FileName const GIT::findFile(FileName const & file)
1835 {
1836         // First we check the existence of repository meta data.
1837         if (VCS::checkParentDirs(file, ".git").empty()) {
1838                 LYXERR(Debug::LYXVC, "Cannot find GIT meta data for " << file);
1839                 return FileName();
1840         }
1841
1842         // Now we check the status of the file.
1843         TempFile tempfile("lyxvcout");
1844         FileName tmpf = tempfile.name();
1845         if (tmpf.empty()) {
1846                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1847                 return FileName();
1848         }
1849
1850         string const fname = onlyFileName(file.absFileName());
1851         LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under git control for `"
1852                         << fname << '\'');
1853         doVCCommandCall("git ls-files " +
1854                         quoteName(fname) + " > " +
1855                         quoteName(tmpf.toFilesystemEncoding()),
1856                         file.onlyPath());
1857         tmpf.refresh();
1858         bool found = !tmpf.isFileEmpty();
1859         LYXERR(Debug::LYXVC, "GIT control: " << (found ? "enabled" : "disabled"));
1860         return found ? file : FileName();
1861 }
1862
1863
1864 void GIT::scanMaster()
1865 {
1866         // vcstatus code is somewhat superflous,
1867         // until we want to implement read-only toggle for git.
1868         vcstatus_ = NOLOCKING;
1869 }
1870
1871
1872 bool GIT::retrieve(FileName const & file)
1873 {
1874         LYXERR(Debug::LYXVC, "LyXVC::GIT: retrieve.\n\t" << file);
1875         // The caller ensures that file does not exist, so no need to check that.
1876         return doVCCommandCall("git checkout -q " + quoteName(file.onlyFileName()),
1877                                file.onlyPath()) == 0;
1878 }
1879
1880
1881 void GIT::registrer(string const & /*msg*/)
1882 {
1883         doVCCommand("git add " + quoteName(onlyFileName(owner_->absFileName())),
1884                     FileName(owner_->filePath()));
1885 }
1886
1887
1888 bool GIT::renameEnabled()
1889 {
1890         return true;
1891 }
1892
1893
1894 string GIT::rename(support::FileName const & newFile, string const & msg)
1895 {
1896         // git mv does not require a log message, since it does not commit.
1897         // In LyX we commit immediately afterwards, otherwise it could be
1898         // confusing to the user to have two uncommitted files.
1899         FileName path(owner_->filePath());
1900         string relFile(to_utf8(newFile.relPath(path.absFileName())));
1901         string cmd("git mv " + quoteName(onlyFileName(owner_->absFileName())) +
1902                    ' ' + quoteName(relFile));
1903         if (doVCCommand(cmd, path)) {
1904                 cmd = "git checkout -q " +
1905                         quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1906                         quoteName(relFile);
1907                 doVCCommand(cmd, path);
1908                 if (newFile.exists())
1909                         newFile.removeFile();
1910                 return string();
1911         }
1912         vector<support::FileName> f;
1913         f.push_back(owner_->fileName());
1914         f.push_back(newFile);
1915         string log;
1916         if (checkIn(f, msg, log) != LyXVC::VCSuccess) {
1917                 cmd = "git checkout -q " +
1918                         quoteName(onlyFileName(owner_->absFileName())) + ' ' +
1919                         quoteName(relFile);
1920                 doVCCommand(cmd, path);
1921                 if (newFile.exists())
1922                         newFile.removeFile();
1923                 return string();
1924         }
1925         return log;
1926 }
1927
1928
1929 bool GIT::copyEnabled()
1930 {
1931         return false;
1932 }
1933
1934
1935 string GIT::copy(support::FileName const & /*newFile*/, string const & /*msg*/)
1936 {
1937         // git does not support copy with history preservation
1938         return string();
1939 }
1940
1941
1942 LyXVC::CommandResult GIT::checkIn(string const & msg, string & log)
1943 {
1944         vector<support::FileName> f(1, owner_->fileName());
1945         return checkIn(f, msg, log);
1946 }
1947
1948
1949 LyXVC::CommandResult
1950 GIT::checkIn(vector<support::FileName> const & f, string const & msg, string & log)
1951 {
1952         TempFile tempfile("lyxvcout");
1953         FileName tmpf = tempfile.name();
1954         if (tmpf.empty()){
1955                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
1956                 log = N_("Error: Could not generate logfile.");
1957                 return LyXVC::ErrorBefore;
1958         }
1959
1960         ostringstream os;
1961         os << "git commit -m \"" << msg << '"';
1962         for (size_t i = 0; i < f.size(); ++i)
1963                 os << ' ' << quoteName(f[i].onlyFileName());
1964         os << " > " << quoteName(tmpf.toFilesystemEncoding());
1965         LyXVC::CommandResult ret =
1966                 doVCCommand(os.str(), FileName(owner_->filePath())) ?
1967                         LyXVC::ErrorCommand : LyXVC::VCSuccess;
1968
1969         string res = scanLogFile(tmpf, log);
1970         if (!res.empty()) {
1971                 frontend::Alert::error(_("Revision control error."),
1972                                 _("Error when committing to repository.\n"
1973                                 "You have to manually resolve the problem.\n"
1974                                 "LyX will reopen the document after you press OK."));
1975                 ret = LyXVC::ErrorCommand;
1976         }
1977
1978         if (!log.empty())
1979                 log.insert(0, "GIT: ");
1980         if (ret == LyXVC::VCSuccess && log.empty())
1981                 log = "GIT: Proceeded";
1982         return ret;
1983 }
1984
1985
1986 bool GIT::checkInEnabled()
1987 {
1988         return true;
1989 }
1990
1991
1992 bool GIT::isCheckInWithConfirmation()
1993 {
1994         // FIXME one day common getDiff and perhaps OpMode for all backends
1995
1996         TempFile tempfile("lyxvcout");
1997         FileName tmpf = tempfile.name();
1998         if (tmpf.empty()) {
1999                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
2000                 return true;
2001         }
2002
2003         doVCCommandCall("git diff " + quoteName(owner_->absFileName())
2004                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
2005                 FileName(owner_->filePath()));
2006
2007         docstring diff = tmpf.fileContents("UTF-8");
2008
2009         if (diff.empty())
2010                 return false;
2011
2012         return true;
2013 }
2014
2015
2016 // FIXME Correctly return code should be checked instead of this.
2017 // This would need another solution than just plain startscript.
2018 // Hint from Andre': QProcess::readAllStandardError()...
2019 string GIT::scanLogFile(FileName const & f, string & status)
2020 {
2021         ifstream ifs(f.toFilesystemEncoding().c_str());
2022         string line;
2023
2024         while (ifs) {
2025                 getline(ifs, line);
2026                 LYXERR(Debug::LYXVC, line << "\n");
2027                 if (!line.empty())
2028                         status += line + "; ";
2029                 if (prefixIs(line, "C ") || prefixIs(line, "CU ")
2030                                          || contains(line, "Commit failed")) {
2031                         ifs.close();
2032                         return line;
2033                 }
2034         }
2035         ifs.close();
2036         return string();
2037 }
2038
2039
2040 string GIT::checkOut()
2041 {
2042         return string();
2043 }
2044
2045
2046 bool GIT::checkOutEnabled()
2047 {
2048         return false;
2049 }
2050
2051
2052 string GIT::repoUpdate()
2053 {
2054         return string();
2055 }
2056
2057
2058 bool GIT::repoUpdateEnabled()
2059 {
2060         return false;
2061 }
2062
2063
2064 string GIT::lockingToggle()
2065 {
2066         return string();
2067 }
2068
2069
2070 bool GIT::lockingToggleEnabled()
2071 {
2072         return false;
2073 }
2074
2075
2076 bool GIT::revert()
2077 {
2078         // Reverts to the version in GIT repository and
2079         // gets the updated version from the repository.
2080         string const fil = quoteName(onlyFileName(owner_->absFileName()));
2081
2082         if (doVCCommand("git checkout -q " + fil,
2083                     FileName(owner_->filePath())))
2084                 return false;
2085         owner_->markClean();
2086         return true;
2087 }
2088
2089
2090 bool GIT::isRevertWithConfirmation()
2091 {
2092         //FIXME owner && diff
2093         return true;
2094 }
2095
2096
2097 void GIT::undoLast()
2098 {
2099         // merge the current with the previous version
2100         // in a reverse patch kind of way, so that the
2101         // result is to revert the last changes.
2102         lyxerr << "Sorry, not implemented." << endl;
2103 }
2104
2105
2106 bool GIT::undoLastEnabled()
2107 {
2108         return false;
2109 }
2110
2111
2112 string GIT::revisionInfo(LyXVC::RevisionInfo const info)
2113 {
2114         if (info == LyXVC::Tree) {
2115                 if (rev_tree_cache_.empty())
2116                         if (!getTreeRevisionInfo())
2117                                 rev_tree_cache_ = "?";
2118                 if (rev_tree_cache_ == "?")
2119                         return string();
2120
2121                 return rev_tree_cache_;
2122         }
2123
2124         // fill the rest of the attributes for a single file
2125         if (rev_file_cache_.empty())
2126                 if (!getFileRevisionInfo()) {
2127                         rev_file_cache_ = "?";
2128                         rev_file_abbrev_cache_ = "?";
2129     }
2130
2131         switch (info) {
2132                 case LyXVC::File:
2133                         if (rev_file_cache_ == "?")
2134                                 return string();
2135                         return rev_file_cache_;
2136                 case LyXVC::FileAbbrev:
2137                         if (rev_file_abbrev_cache_ == "?")
2138                                 return string();
2139                         return rev_file_abbrev_cache_;
2140                 case LyXVC::Author:
2141                         return rev_author_cache_;
2142                 case LyXVC::Date:
2143                         return rev_date_cache_;
2144                 case LyXVC::Time:
2145                         return rev_time_cache_;
2146                 default:
2147                         break;
2148         }
2149
2150         return string();
2151 }
2152
2153
2154 bool GIT::getFileRevisionInfo()
2155 {
2156         TempFile tempfile("lyxvcout");
2157         FileName tmpf = tempfile.name();
2158         if (tmpf.empty()) {
2159                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
2160                 return false;
2161         }
2162
2163         doVCCommand("git log -n 1 --pretty=format:%H%n%h%n%an%n%ai " + quoteName(onlyFileName(owner_->absFileName()))
2164                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
2165                     FileName(owner_->filePath()));
2166
2167         if (tmpf.empty())
2168                 return false;
2169
2170         ifstream ifs(tmpf.toFilesystemEncoding().c_str());
2171
2172         if (ifs)
2173                 getline(ifs, rev_file_cache_);
2174         if (ifs)
2175                 getline(ifs, rev_file_abbrev_cache_);
2176         if (ifs)
2177                 getline(ifs, rev_author_cache_);
2178         if (ifs) {
2179                 string line;
2180                 getline(ifs, line);
2181                 rev_time_cache_ = split(line, rev_date_cache_, ' ');
2182         }
2183
2184         ifs.close();
2185         return !rev_file_cache_.empty();
2186 }
2187
2188
2189 bool GIT::getTreeRevisionInfo()
2190 {
2191         TempFile tempfile("lyxvcout");
2192         FileName tmpf = tempfile.name();
2193         if (tmpf.empty()) {
2194                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
2195                 return false;
2196         }
2197
2198         doVCCommand("git describe --abbrev --dirty --long > " + quoteName(tmpf.toFilesystemEncoding()),
2199                     FileName(owner_->filePath()),
2200                     false); //git describe returns $?=128 when no tag found (but git repo still exists)
2201
2202         if (tmpf.empty())
2203                 return false;
2204
2205         // only first line in case something bad happens.
2206         ifstream ifs(tmpf.toFilesystemEncoding().c_str());
2207         getline(ifs, rev_tree_cache_);
2208         ifs.close();
2209
2210         return !rev_tree_cache_.empty();
2211 }
2212
2213
2214 void GIT::getLog(FileName const & tmpf)
2215 {
2216         doVCCommand("git log " + quoteName(onlyFileName(owner_->absFileName()))
2217                     + " > " + quoteName(tmpf.toFilesystemEncoding()),
2218                     FileName(owner_->filePath()));
2219 }
2220
2221
2222 //at this moment we don't accept revision SHA, but just number of revision steps back
2223 //GUI and infrastucture needs to be changed first
2224 bool GIT::prepareFileRevision(string const & revis, string & f)
2225 {
2226         // anything positive means we got hash, not "0" or minus revision
2227         int rev = 1;
2228
2229         // hash is rarely number and should be long
2230         if (isStrInt(revis) && revis.length()<20)
2231                 rev = convert<int>(revis);
2232
2233         // revision and filename
2234         string pointer;
2235
2236         // go back for "minus" revisions
2237         if (rev <= 0)
2238                 pointer = "HEAD~" + convert<string>(-rev);
2239         // normal hash
2240         else
2241                 pointer = revis;
2242
2243         pointer += ':';
2244
2245         TempFile tempfile("lyxvcrev_" + revis + '_');
2246         tempfile.setAutoRemove(false);
2247         FileName tmpf = tempfile.name();
2248         if (tmpf.empty()) {
2249                 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
2250                 return false;
2251         }
2252
2253         doVCCommand("git show " + pointer + "./"
2254                       + quoteName(onlyFileName(owner_->absFileName()))
2255                       + " > " + quoteName(tmpf.toFilesystemEncoding()),
2256                 FileName(owner_->filePath()));
2257         tmpf.refresh();
2258         if (tmpf.isFileEmpty())
2259                 return false;
2260
2261         f = tmpf.absFileName();
2262         return true;
2263 }
2264
2265
2266 bool GIT::prepareFileRevisionEnabled()
2267 {
2268         return true;
2269 }
2270
2271
2272 bool GIT::toggleReadOnlyEnabled()
2273 {
2274         return true;
2275 }
2276
2277
2278 } // namespace lyx