[git] IDEA-87513 Support quotes in file names (Git escapes them); remove quotes added by Git, surrounding file names, if they contain escaped sequences.

This commit is contained in:
Kirill Likhodedov
2012-06-21 20:06:54 +04:00
parent 40b86eaca2
commit e4225a5169
+19 -3
View File
@@ -552,13 +552,26 @@ public class GitUtil {
}
/**
* Unescape path returned by the Git
* <p>Unescape path returned by Git.</p>
* <p>
* If there are quotes in the file name, Git not only escapes them, but also encloses the file name into quotes:
* <code>"\"quote"</code>
* </p>
* <p>
* If there are spaces in the file name, Git displays the name as is, without escaping spaces and without enclosing name in quotes.
* </p>
*
* @param path a path to unescape
* @return unescaped path
* @return unescaped path ready to be searched in the VFS or file system.
* @throws com.intellij.openapi.vcs.VcsException if the path in invalid
*/
public static String unescapePath(String path) throws VcsException {
@NotNull
public static String unescapePath(@NotNull String path) throws VcsException {
final String QUOTE = "\"";
if (path.startsWith(QUOTE) && path.endsWith(QUOTE)) {
path = path.substring(1, path.length() - 1);
}
final int l = path.length();
StringBuilder rc = new StringBuilder(l);
for (int i = 0; i < path.length(); i++) {
@@ -580,6 +593,9 @@ public class GitUtil {
case 'n':
rc.append('\n');
break;
case '"':
rc.append('"');
break;
default:
if (VcsFileUtil.isOctal(e)) {
// collect sequence of characters as a byte array.