Forgot to attach. This time it is attached.

Baruch

Baruch Even wrote:
> Baruch Even wrote:
> 
>>p.s. I'm not subscribed, please CC me on correspondence. Thanks!
> 
> 
> Either the mail was eaten by the mail-server or I was ignored. gmane
> sucks since I can't get it to send the e-mail to my favourite e-mail
> program of the day.
> 
> I fixed most of the comments and attached the updated version.
> 
> This also solves a bug where for registering a new file LyX searches for
> the CVS/Entries (or .svn/entries) in the directory LyX was started in
> and not where the file is. Guess what VC it uses when /tmp/s/ has .svn
> dir and `pwd` is the LyX CVS tree?
> 
> I still ignore SVN locking since I don't have version 1.2 to work with.
> 
> Baruch


Index: src/ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/ChangeLog,v
retrieving revision 1.2196
diff -u -r1.2196 ChangeLog
--- src/ChangeLog	2005/06/07 16:50:00	1.2196
+++ src/ChangeLog	2005/06/08 20:29:55
@@ -1,3 +1,13 @@
+2005-06-08  Baruch Even <[EMAIL PROTECTED]>
+
+	* lyxvc.C: Fix bug where it searches for the VC type in the directory
+	it was started rather than in the directory the file is in.
+
+	* lyxvc.C:
+	* vc-backend.h:
+	* vc-backend.C: Added support for Subversion (SVN) version
+	control.
+
 2005-06-07  Georg Baum  <[EMAIL PROTECTED]>
 
 	* lyx_main.C (parse_execute): Fix last fix: is_gui = false
Index: src/lyxvc.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/lyxvc.C,v
retrieving revision 1.55
diff -u -r1.55 lyxvc.C
--- src/lyxvc.C	2004/02/25 12:00:48	1.55
+++ src/lyxvc.C	2005/06/08 20:29:55
@@ -25,11 +25,14 @@
 
 #include "support/filetools.h"
 #include "support/lyxlib.h"
+#include "support/path.h"
 
 using lyx::support::bformat;
 using lyx::support::IsFileReadable;
 using lyx::support::MakeDisplayPath;
 using lyx::support::tempName;
+using lyx::support::Path;
+using lyx::support::OnlyPath;
 
 using std::endl;
 using std::string;
@@ -62,6 +65,12 @@
 		vcs->owner(owner_);
 		return true;
 	}
+	// Check if file is under SVN
+	if (!(found_file = SVN::find_file(fn)).empty()) {
+		vcs.reset(new SVN(found_file));
+		vcs->owner(owner_);
+		return true;
+	}
 	// file is not under any VCS.
 	return false;
 }
@@ -74,6 +83,8 @@
 		return true;
 	if (!CVS::find_file(fn).empty())
 		return true;
+	if (!SVN::find_file(fn).empty())
+		return true;
 	return false;
 }
 
@@ -99,6 +110,9 @@
 	// it is very likely here that the vcs is not created yet...
 	if (!vcs) {
 		string const cvs_entries = "CVS/Entries";
+		string const svn_entries = ".svn/entries";
+
+		Path path(OnlyPath(filename));
 
 		if (IsFileReadable(cvs_entries)) {
 			lyxerr[Debug::LYXVC]
@@ -106,7 +120,12 @@
 				<< MakeDisplayPath(filename)
 				<< " with CVS" << endl;
 			vcs.reset(new CVS(cvs_entries, filename));
-
+		} else if (IsFileReadable(svn_entries)) {
+			lyxerr[Debug::LYXVC]
+				<< "LyXVC: registering "
+				<< MakeDisplayPath(filename)
+				<< " with SVN" << endl;
+			vcs.reset(new SVN(filename));
 		} else {
 			lyxerr[Debug::LYXVC]
 				<< "LyXVC: registering "
Index: src/vc-backend.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/vc-backend.C,v
retrieving revision 1.52
diff -u -r1.52 vc-backend.C
--- src/vc-backend.C	2005/04/26 11:12:15	1.52
+++ src/vc-backend.C	2005/06/08 20:29:55
@@ -35,6 +35,11 @@
 using lyx::support::rtrim;
 using lyx::support::split;
 using lyx::support::Systemcall;
+using lyx::support::cmd_ret;
+using lyx::support::RunCommand;
+using lyx::support::token;
+using lyx::support::trim;
+using lyx::support::shellEscape;
 
 using boost::regex;
 using boost::regex_match;
@@ -347,6 +352,120 @@
 void CVS::getLog(string const & tmpf)
 {
 	doVCCommand("cvs log " + QuoteName(OnlyFilename(owner_->fileName()))
+		    + " > " + tmpf,
+		    owner_->filePath());
+}
+
+
+SVN::SVN(string const & f)
+{
+	file_ = f;
+	scanMaster();
+	vcstatus = UNLOCKED; // There is no locked state for Subversion
+}
+
+
+namespace {
+cmd_ret RunSVNInfo(string const & file)
+{
+	string const dir = OnlyPath(file);
+	string const filename = OnlyFilename(file);
+	Path p(dir);
+	string const svn_info = "LANG=C svn info ";
+
+	lyxerr[Debug::LYXVC] << "LyXVC: checking in `" << dir
+			     << "' for `" << filename << '\'' << endl;
+	return RunCommand(svn_info + filename);
+}
+}
+
+string const SVN::find_file(string const & file)
+{
+	cmd_ret ret = RunSVNInfo(file);
+	lyxerr[Debug::LYXVC] << "LyXVC: got errcode=" << ret.first
+	                     << " and string '" << ret.second << "'" << endl;
+	if (ret.first == 0 && !contains(ret.second, "Not a versioned resource")) {
+		lyxerr[Debug::LYXVC] << "LyXVC: success, returning " << file << endl;
+		return file;
+	}
+	return string();
+}
+
+
+void SVN::scanMaster(void)
+{
+	cmd_ret const ret = RunSVNInfo(file_);
+	string buffer = ret.second;
+	string head;
+	bool found = false;
+
+	while (buffer.length() > 0) {
+		buffer = split(buffer, head, '\n');
+		if (contains(head, "Revision:")) {
+			found = true;
+			break;
+		}
+	}
+
+	if (found) {
+		version_ = token(head, ':', 1);
+		version_ = trim(version_);
+		lyxerr[Debug::LYXVC] << "LyXVC: file " << file_
+		                     << " has version " << version_ << endl;
+	} else {
+		lyxerr[Debug::LYXVC] << "LyXVC: no version found for file "
+			             << file_ << endl;
+	}
+}
+
+
+void SVN::registrer(string const & msg)
+{
+	doVCCommand("svn -q add "
+		    + QuoteName(OnlyFilename(owner_->fileName())),
+		    owner_->filePath());
+	checkIn(msg);
+}
+
+
+void SVN::checkIn(string const & msg)
+{
+	doVCCommand("svn -q commit -m '" + shellEscape(msg) + "' "
+		    + QuoteName(OnlyFilename(owner_->fileName())),
+		    owner_->filePath());
+}
+
+
+void SVN::checkOut()
+{
+	doVCCommand("svn -q update " + owner_->fileName(),
+	            owner_->filePath());
+}
+
+
+void SVN::revert()
+{
+	// Reverts to the version in SVN repository and
+	// gets the updated version from the repository.
+	string const fil = QuoteName(OnlyFilename(owner_->fileName()));
+
+	doVCCommand("svn revert " + fil, owner_->filePath());
+	owner_->markClean();
+}
+
+
+void SVN::undoLast()
+{
+	// merge the current with the previous version
+	// in a reverse patch kind of way, so that the
+	// result is to revert the last changes.
+	lyxerr << "Sorry not implemented." << endl;
+}
+
+
+void SVN::getLog(string const & tmpf)
+{
+	doVCCommand("svn log " + QuoteName(OnlyFilename(owner_->fileName()))
 		    + " > " + tmpf,
 		    owner_->filePath());
 }
Index: src/vc-backend.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/vc-backend.h,v
retrieving revision 1.16
diff -u -r1.16 vc-backend.h
--- src/vc-backend.h	2003/10/06 15:42:43	1.16
+++ src/vc-backend.h	2005/06/08 20:29:56
@@ -155,4 +155,36 @@
 private:
 	std::string file_;
 };
+
+class SVN : public VCS {
+public:
+	explicit
+	SVN(std::string const & f);
+
+	/// return the revision file for the given file, if found
+	static std::string const find_file(std::string const & file);
+
+	virtual void registrer(std::string const & msg);
+
+	virtual void checkIn(std::string const & msg);
+
+	virtual void checkOut(void);
+
+	virtual void revert(void);
+
+	virtual void undoLast(void);
+
+	virtual void getLog(std::string const &);
+
+	virtual std::string const versionString() const {
+		return "SVN: " + version_;
+	}
+
+protected:
+	virtual void scanMaster(void);
+
+private:
+	std::string file_;
+};
+
 #endif // VCBACKEND_H
Index: src/support/ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/support/ChangeLog,v
retrieving revision 1.349
diff -u -r1.349 ChangeLog
--- src/support/ChangeLog	2005/05/07 14:31:16	1.349
+++ src/support/ChangeLog	2005/06/08 20:29:56
@@ -1,3 +1,9 @@
+2005-06-08  Baruch Even  <[EMAIL PROTECTED]>
+
+	* lstrings.h:
+	* lstrings.C: Add shellEscape function to escape arguments for
+	shell execution.
+
 2005-05-07  Rob Bearman  <[EMAIL PROTECTED]>
 
 	* fs_extras.C (copy_file): noclobber and CopyFile's bFailIfExists
Index: src/support/lstrings.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/support/lstrings.C,v
retrieving revision 1.90
diff -u -r1.90 lstrings.C
--- src/support/lstrings.C	2005/01/27 21:05:44	1.90
+++ src/support/lstrings.C	2005/06/08 20:29:56
@@ -481,6 +481,20 @@
 }
 
 
+string const shellEscape(string const & str)
+{
+	string esc;
+	for (string::size_type i = 0; i < str.length(); ++i) {
+		unsigned char c = str[i];
+		switch (c) {
+			case '\'': esc += "\\'"; break;
+			case '\\': esc += "\\\\"; break;
+			default: esc += c; break;
+		}
+	}
+	return esc;
+}
+
 /// gives a vector of stringparts which have the delimiter delim
 vector<string> const getVectorFromString(string const & str,
 					 string const & delim)
Index: src/support/lstrings.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/support/lstrings.h,v
retrieving revision 1.58
diff -u -r1.58 lstrings.h
--- src/support/lstrings.h	2005/01/27 21:05:44	1.58
+++ src/support/lstrings.h	2005/06/08 20:29:56
@@ -168,6 +168,9 @@
 /// Escapes non ASCII chars
 std::string const escape(std::string const & lab);
 
+/// Escape characters for shell execution
+std::string const shellEscape(std::string const & str);
+
 /// gives a vector of stringparts which have the delimiter delim
 std::vector<std::string> const getVectorFromString(std::string const & str,
 					      std::string const & delim = std::string(","));

Reply via email to