Am 19.10.2010 um 03:34 schrieb Pavel Sanda:

> Stephan Witt wrote:
>> Pavel, can you have a look please?
> 
> hopefully towards the end of this week. actually it would be really helpful
> if we can proceed in usual incremental manner - different patches for 
> different
> issues, its much harder to keep your track if everything is muddled into
> one big patch, ie patch for CVS related stuff and fixing other bugs on the 
> top of it.
> 
> quick peek into diff - doVCCommand change looks ok (maybe call the param 
> reportError?).
> why 
> +       // to be sure test readonly state again...                            
>                                                                               
>                                            
> +       FileName fn(owner_->absFileName());                                   
>                                                                               
>                                            
> +       fn.refresh();                                                         
>                                                                               
>                                            
> +       if (!fn.isReadOnly())
> is not inside checkoutenabled?

I made a new patch to implement getDiff() and use it to avoid the query for log 
message
before checkIn() is done and the confirmation on revert when no diff is found.

Next patch follows later...

Stephan

Index: src/VCBackend.cpp
===================================================================
--- src/VCBackend.cpp   (Revision 35732)
+++ src/VCBackend.cpp   (Arbeitskopie)
@@ -47,7 +47,7 @@
 }
 
 
-int VCS::doVCCommand(string const & cmd, FileName const & path)
+int VCS::doVCCommand(string const & cmd, FileName const & path, bool 
reportError)
 {
        if (owner_)
                owner_->setBusy(true);
@@ -56,7 +56,7 @@
 
        if (owner_)
                owner_->setBusy(false);
-       if (ret)
+       if (ret && reportError)
                frontend::Alert::error(_("Revision control error."),
                        bformat(_("Some problem occured while running the 
command:\n"
                                  "'%1$s'."),
@@ -432,12 +432,82 @@
 }
 
 
+string const CVS::getTarget(OperationMode opmode)
+{
+       switch(opmode) {
+       case Directory:
+               return quoteName(owner_->filePath());
+       case File:
+               return quoteName(onlyFileName(owner_->absFileName()));
+       }
+       return string();
+}
+
+
+FileName const CVS::getDiff(OperationMode opmode)
+{
+       FileName tmpf = FileName::tempName("lyxvcout");
+       if (tmpf.empty()) {
+               LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
+               return tmpf;
+       }
+
+       doVCCommand("cvs diff " + getTarget(opmode)
+               + " > " + quoteName(tmpf.toFilesystemEncoding()),
+               FileName(owner_->filePath()), false);
+       return tmpf;
+}
+
+
+bool const CVS::hasDiff(OperationMode opmode)
+{
+       FileName tmpf = getDiff(opmode);
+       docstring res = tmpf.fileContents("UTF-8");
+       tmpf.removeFile();
+       return !res.empty();
+}
+
+
+int CVS::edit()
+{
+       vcstatus = LOCKED;
+       return doVCCommand("cvs -q edit "
+               + quoteName(onlyFileName(owner_->absFileName())),
+               FileName(owner_->filePath()));
+}
+
+
+int CVS::unedit()
+{
+       vcstatus = UNLOCKED;
+       return doVCCommand("cvs -q unedit "
+               + quoteName(onlyFileName(owner_->absFileName())),
+               FileName(owner_->filePath()));
+}
+
+
+int CVS::update(OperationMode opmode, FileName const tmpf)
+{
+       string const redirection = tmpf.empty() ? ""
+               : " > " + quoteName(tmpf.toFilesystemEncoding());
+
+       return doVCCommand("cvs -q update "
+               + getTarget(opmode) + redirection,
+               FileName(owner_->filePath()));
+}
+
+
 string CVS::checkIn(string const & msg)
 {
-       int ret = doVCCommand("cvs -q commit -m \"" + msg + "\" "
-                   + quoteName(onlyFileName(owner_->absFileName())),
+       if (!hasDiff()) {
+               unedit();
+               return "CVS: Proceeded";
+       }
+
+       int rc = doVCCommand("cvs -q commit -m \"" + msg + "\" "
+                       + quoteName(onlyFileName(owner_->absFileName())),
                    FileName(owner_->filePath()));
-       return ret ? string() : "CVS: Proceeded";
+       return rc ? string() : "CVS: Proceeded";
 }
 
 
@@ -453,22 +523,20 @@
        if (!checkOutEnabled())
                return string();
 
-       int ret = doVCCommand("cvs -q edit "
-                                                 + 
quoteName(onlyFileName(owner_->absFileName())),
-                                                 FileName(owner_->filePath()));
+       int ret = edit();
        if (ret)
                return string();
 
-       ret = doVCCommand("cvs update "
-                                         + 
quoteName(onlyFileName(owner_->absFileName())),
-                                         FileName(owner_->filePath()));
+       ret = update(File, FileName());
        return ret ? string() : "CVS: Proceeded";
 }
 
 
 bool CVS::checkOutEnabled()
 {
-       return owner_->isReadonly();
+       FileName fn(owner_->absFileName());
+       fn.refresh();
+       return fn.isReadOnly();
 }
 
 
@@ -509,8 +577,8 @@
                return;
        FileName f(owner_->absFileName());
        f.removeFile();
-       doVCCommand("cvs -q update " + fil,
-                   FileName(owner_->filePath()));
+       update(File, FileName());
+       unedit();
        owner_->markClean();
 }
 
@@ -715,7 +783,7 @@
        while (ifs) {
                getline(ifs, line);
                LYXERR(Debug::LYXVC, line << "\n");
-               if (!line.empty()) 
+               if (!line.empty())
                        status += line + "; ";
                if (prefixIs(line, "C ") || prefixIs(line, "CU ")
                                         || contains(line, "Commit failed")) {
Index: src/VCBackend.h
===================================================================
--- src/VCBackend.h     (Revision 35732)
+++ src/VCBackend.h     (Arbeitskopie)
@@ -42,6 +42,8 @@
        virtual std::string checkIn(std::string const & msg) = 0;
        // can be this operation processed in the current RCS?
        virtual bool checkInEnabled() = 0;
+       // should a log message provided for next checkin?
+       virtual bool checkInWithMessage() { return true; }
        /// check out for editing, returns log
        virtual std::string checkOut() = 0;
        // can be this operation processed in the current RCS?
@@ -54,6 +56,8 @@
        virtual std::string lockingToggle() = 0;
        // can be this operation processed in the current RCS?
        virtual bool lockingToggleEnabled() = 0;
+       // should a confirmation before revert requested?
+       virtual bool revertWithConfirmation() { return true; }
        /// revert current edits
        virtual void revert() = 0;
        /// FIXME
@@ -88,7 +92,7 @@
        virtual void scanMaster() = 0;
 
        // GUI container for doVCCommandCall
-       int doVCCommand(std::string const & cmd, support::FileName const & 
path);
+       int doVCCommand(std::string const & cmd, support::FileName const & 
path, bool reportError = true);
        /**
         * doVCCommandCall - call out to the version control utility
         * @param cmd the command to execute
@@ -190,6 +194,8 @@
 
        virtual bool checkInEnabled();
 
+       virtual bool checkInWithMessage() { return hasDiff(); }
+
        virtual std::string checkOut();
 
        virtual bool checkOutEnabled();
@@ -202,6 +208,8 @@
 
        virtual bool lockingToggleEnabled();
 
+       virtual bool revertWithConfirmation() { return hasDiff(); }
+
        virtual void revert();
 
        virtual void undoLast();
@@ -224,13 +232,26 @@
 
 protected:
        virtual void scanMaster();
-
+       /// the mode of operation for some VC commands
+       enum OperationMode {
+               Directory = 0,
+               File = 1
+       };
+       
 private:
        support::FileName file_;
        // revision number from scanMaster
        std::string version_;
        /// The user currently keeping the lock on the VC file.
        std::string locker_;
+
+       virtual std::string const getTarget(OperationMode opmode);
+       virtual support::FileName const getDiff(OperationMode opmode);
+       virtual int edit();
+       virtual int unedit();
+       virtual int update(OperationMode opmode, support::FileName const tmpf);
+       virtual bool const hasDiff(OperationMode opmode);
+       virtual bool const hasDiff() { return hasDiff(File); }
 };
 
 
Index: src/LyXVC.cpp
===================================================================
--- src/LyXVC.cpp       (Revision 35732)
+++ src/LyXVC.cpp       (Arbeitskopie)
@@ -163,9 +163,10 @@
        docstring empty(_("(no log message)"));
        docstring response;
        string log;
-       bool ok = Alert::askForText(response, _("LyX VC: Log Message"));
+       bool dolog = vcs->checkInWithMessage();
+       bool ok = !dolog || Alert::askForText(response, _("LyX VC: Log 
Message"));
        if (ok) {
-               if (response.empty())
+               if (dolog && response.empty())
                        response = empty;
                log = vcs->checkIn(to_utf8(response));
 
@@ -212,8 +213,9 @@
        docstring text = bformat(_("Reverting to the stored version of the "
                                "document %1$s will lose all current 
changes.\n\n"
                                "Do you want to revert to the older version?"), 
file);
-       int const ret = Alert::prompt(_("Revert to stored version of 
document?"),
-               text, 0, 1, _("&Revert"), _("&Cancel"));
+       bool const doask = vcs->revertWithConfirmation();
+       int const ret = doask ? Alert::prompt(_("Revert to stored version of 
document?"),
+               text, 0, 1, _("&Revert"), _("&Cancel")) : 0;
 
        if (ret == 0)
                vcs->revert();

Reply via email to