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