On 07/04/13 22:26, Pavel Sanda wrote:
>>
>> Indeed, git status --porcelain for a file *existent-on-the-FS* and 
>> existent-in-repo, as well as for a file non-existent on the FS and 
>> non-existent in repo, are the same, namely NOTHING.
> 
> Didn't you claim that file existent-on-the-FS is already checked? Then git 
> status should return what we want, no?

Yes, but the problem is that the ::findFile() machinery is called twice: first, 
it determines whether the fname is on the repo. Ok, we get it right, so we ask 
the user and if he/she answers yes we retrieve the file from the repo. Later, 
it's (probably, didn't check) called again to remember that the opened file is 
in the repo (set "version control" in the title etc.), but now it's existing 
and git status --porcelain changes behaviour

tommaso@mobiletom:~/lyx-trunk-ws/lyx$ rm README
tommaso@mobiletom:~/lyx-trunk-ws/lyx$ git status --porcelain README
 D README
tommaso@mobiletom:~/lyx-trunk-ws/lyx$ git checkout README
tommaso@mobiletom:~/lyx-trunk-ws/lyx$ git status --porcelain README
tommaso@mobiletom:~/lyx-trunk-ws/lyx$ 

Simply, it doesn't seem to me that git status has been thought with this kind 
of use in mind.

Anyway, my v3 patch is attached (2 patches, actually, one to fix 
checkparentdirs() for SVN & GIT, the other to fix GIT). Can u pls try these and 
see whether you can spot any problem now ?

Thx,

        T.

commit 5f62e189
Author: Tommaso Cucinotta <tomm...@lyx.org>
Date:   Sun Apr 7 23:52:39 2013 +0100

    Replacing git status --porcelain along with output parsing, with a simple git ls-files.
    
    git ls-files tells me straight whether or not a file-name is in the repo.
    I cannot say the same of git status --porcelain.
    See also discussion at: http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg177840.html

diff --git a/src/VCBackend.cpp b/src/VCBackend.cpp
index 70e42829..eb1ad72a 100644
--- a/src/VCBackend.cpp
+++ b/src/VCBackend.cpp
@@ -1831,32 +1831,14 @@ FileName const GIT::findFile(FileName const & file)
 		return FileName();
 	}
 
-	// --porcelain selects a format that is supposed to be stable across
-	// git versions
 	string const fname = onlyFileName(file.absFileName());
 	LYXERR(Debug::LYXVC, "LyXVC: Checking if file is under git control for `"
 			<< fname << '\'');
-	bool found = 0 == doVCCommandCall("git status --porcelain " +
-				quoteName(fname) + " > " +
-				quoteName(tmpf.toFilesystemEncoding()),
+	doVCCommandCall("git ls-files " +
+			quoteName(fname) + " > " +
+			quoteName(tmpf.toFilesystemEncoding()),
 			file.onlyPath());
-	if (found)
-	{
-		// The output is empty for file names NOT in repo.
-		// The output contains a line starting with "??" for unknown
-		// files, no line for known unmodified files and a line
-		// starting with "M" or something else for modified/deleted
-		// etc. files.
-		if (tmpf.isFileEmpty())
-			found = false;
-		else {
-			ifstream ifs(tmpf.toFilesystemEncoding().c_str());
-			string test;
-			if ((ifs >> test))
-				found = (test != "??");
-			// else is no error
-		}
-	}
+	bool found = !tmpf.isFileEmpty();
 	tmpf.removeFile();
 	LYXERR(Debug::LYXVC, "GIT control: " << (found ? "enabled" : "disabled"));
 	return found ? file : FileName();

commit e46f68f9
Author: Tommaso Cucinotta <tomm...@lyx.org>
Date:   Sun Apr 7 01:10:31 2013 +0100

    Avoid check mistakenly current folder for .git/.svn/.CVS, when going up the path checking for parents.

diff --git a/src/VCBackend.cpp b/src/VCBackend.cpp
index 72148f72..70e42829 100644
--- a/src/VCBackend.cpp
+++ b/src/VCBackend.cpp
@@ -102,20 +102,18 @@ bool VCS::makeRCSRevision(string const &version, string &revis) const
 bool VCS::checkparentdirs(FileName const & file, std::string const & pathname)
 {
 	FileName dirname = file.onlyPath();
-	FileName tocheck = FileName(addName(dirname.absFileName(),pathname));
-	LYXERR(Debug::LYXVC, "check file: " << tocheck.absFileName());
-	bool result = tocheck.exists();
-	while ( !result && !dirname.empty() ) {
+	do {
+		FileName tocheck = FileName(addName(dirname.absFileName(), pathname));
+		LYXERR(Debug::LYXVC, "check file: " << tocheck.absFileName());
+		if (tocheck.exists())
+			return true;
 		//this construct because of #8295
 		dirname = FileName(dirname.absFileName()).parentPath();
-		LYXERR(Debug::LYXVC, "check directory: " << dirname.absFileName());
-		tocheck = FileName(addName(dirname.absFileName(),pathname));
-		result = tocheck.exists();
-	}
-	return result;
+	} while (!dirname.empty());
+	return false;
 }
 
-	
+
 /////////////////////////////////////////////////////////////////////
 //
 // RCS

Reply via email to