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