GitNewChangesCollector: don't unescape path.

git status --porcelain -z doesn't escape path, so we shouldn't unescape it.
Added a param to GitContentRevision.createRevision and .createPath.
This commit is contained in:
Kirill Likhodedov
2011-07-26 10:50:00 +04:00
parent 03f8618af2
commit fa238e2236
5 changed files with 32 additions and 28 deletions
@@ -132,11 +132,13 @@ public class GitContentRevision implements ContentRevision {
/**
* Create revision
*
*
* @param vcsRoot a vcs root for the repository
* @param path an path inside with possibly escape sequences
* @param revisionNumber a revision number, if null the current revision will be created
* @param project the context project
* @param isDeleted if true, the file is deleted
* @param unescapePath
* @return a created revision
* @throws com.intellij.openapi.vcs.VcsException
* if there is a problem with creating revision
@@ -145,8 +147,8 @@ public class GitContentRevision implements ContentRevision {
String path,
VcsRevisionNumber revisionNumber,
Project project,
boolean isDeleted, final boolean canBeDeleted) throws VcsException {
final FilePath file = createPath(vcsRoot, path, isDeleted, canBeDeleted);
boolean isDeleted, final boolean canBeDeleted, boolean unescapePath) throws VcsException {
final FilePath file = createPath(vcsRoot, path, isDeleted, canBeDeleted, unescapePath);
if (revisionNumber != null) {
return createRevisionImpl(file, (GitRevisionNumber)revisionNumber, project, null);
}
@@ -155,8 +157,9 @@ public class GitContentRevision implements ContentRevision {
}
}
public static FilePath createPath(VirtualFile vcsRoot, String path, boolean isDeleted, boolean canBeDeleted) throws VcsException {
final String absolutePath = vcsRoot.getPath() + "/" + GitUtil.unescapePath(path);
public static FilePath createPath(VirtualFile vcsRoot, String path, boolean isDeleted, boolean canBeDeleted, boolean unescapePath) throws VcsException {
final String unescapedPath = unescapePath ? GitUtil.unescapePath(path) : path;
final String absolutePath = vcsRoot.getPath() + "/" + unescapedPath;
FilePath file = isDeleted ? VcsUtil.getFilePathForDeletedFile(absolutePath, false) : VcsUtil.getFilePath(absolutePath, false);
if (canBeDeleted && (! SystemInfo.isFileSystemCaseSensitive) && VcsUtil.caseDiffers(file.getPath(), absolutePath)) {
// as for deleted file
@@ -183,7 +183,7 @@ public class GitChangeUtils {
case 'A':
before = null;
status = FileStatus.ADDED;
after = GitContentRevision.createRevision(vcsRoot, path, thisRevision, project, false, false);
after = GitContentRevision.createRevision(vcsRoot, path, thisRevision, project, false, false, true);
break;
case 'U':
status = FileStatus.MERGED_WITH_CONFLICTS;
@@ -191,18 +191,18 @@ public class GitChangeUtils {
if (status == null) {
status = FileStatus.MODIFIED;
}
before = GitContentRevision.createRevision(vcsRoot, path, parentRevision, project, false, true);
after = GitContentRevision.createRevision(vcsRoot, path, thisRevision, project, false, false);
before = GitContentRevision.createRevision(vcsRoot, path, parentRevision, project, false, true, true);
after = GitContentRevision.createRevision(vcsRoot, path, thisRevision, project, false, false, true);
break;
case 'D':
status = FileStatus.DELETED;
before = GitContentRevision.createRevision(vcsRoot, path, parentRevision, project, true, true);
before = GitContentRevision.createRevision(vcsRoot, path, parentRevision, project, true, true, true);
after = null;
break;
case 'R':
status = FileStatus.MODIFIED;
before = GitContentRevision.createRevision(vcsRoot, tokens[1], parentRevision, project, true, true);
after = GitContentRevision.createRevision(vcsRoot, path, thisRevision, project, false, false);
before = GitContentRevision.createRevision(vcsRoot, tokens[1], parentRevision, project, true, true, true);
after = GitContentRevision.createRevision(vcsRoot, path, thisRevision, project, false, false, true);
break;
default:
throw new VcsException("Unknown file status: " + Arrays.asList(tokens));
@@ -232,39 +232,39 @@ class GitNewChangesCollector extends GitChangesCollector {
}
private void reportUnversioned(String filepath) throws VcsException {
VirtualFile file = myVcsRoot.findFileByRelativePath(GitUtil.unescapePath(filepath));
VirtualFile file = myVcsRoot.findFileByRelativePath(filepath);
if (GitUtil.gitRootOrNull(file) == myVcsRoot) { // false if we've entered the sub-repository
myUnversionedFiles.add(file);
}
}
private void reportModified(String filepath, GitRevisionNumber head) throws VcsException {
ContentRevision before = GitContentRevision.createRevision(myVcsRoot, filepath, head, myProject, false, true);
ContentRevision after = GitContentRevision.createRevision(myVcsRoot, filepath, null, myProject, false, false);
ContentRevision before = GitContentRevision.createRevision(myVcsRoot, filepath, head, myProject, false, true, false);
ContentRevision after = GitContentRevision.createRevision(myVcsRoot, filepath, null, myProject, false, false, false);
reportChange(FileStatus.MODIFIED, before, after);
}
private void reportAdded(String filepath) throws VcsException {
ContentRevision before = null;
ContentRevision after = GitContentRevision.createRevision(myVcsRoot, filepath, null, myProject, false, false);
ContentRevision after = GitContentRevision.createRevision(myVcsRoot, filepath, null, myProject, false, false, false);
reportChange(FileStatus.ADDED, before, after);
}
private void reportDeleted(String filepath, GitRevisionNumber head) throws VcsException {
ContentRevision before = GitContentRevision.createRevision(myVcsRoot, filepath, head, myProject, true, true);
ContentRevision before = GitContentRevision.createRevision(myVcsRoot, filepath, head, myProject, true, true, false);
ContentRevision after = null;
reportChange(FileStatus.DELETED, before, after);
}
private void reportRename(GitRevisionNumber head, String filepath, String oldFilename) throws VcsException {
ContentRevision before = GitContentRevision.createRevision(myVcsRoot, oldFilename, head, myProject, true, true);
ContentRevision after = GitContentRevision.createRevision(myVcsRoot, filepath, null, myProject, false, false);
ContentRevision before = GitContentRevision.createRevision(myVcsRoot, oldFilename, head, myProject, true, true, false);
ContentRevision after = GitContentRevision.createRevision(myVcsRoot, filepath, null, myProject, false, false, false);
reportChange(FileStatus.MODIFIED, before, after);
}
private void reportConflict(GitRevisionNumber head, String filepath) throws VcsException {
ContentRevision before = GitContentRevision.createRevision(myVcsRoot, filepath, head, myProject, false, true);
ContentRevision after = GitContentRevision.createRevision(myVcsRoot, filepath, null, myProject, false, false);
ContentRevision before = GitContentRevision.createRevision(myVcsRoot, filepath, head, myProject, false, true, false);
ContentRevision after = GitContentRevision.createRevision(myVcsRoot, filepath, null, myProject, false, false, false);
reportChange(FileStatus.MERGED_WITH_CONFLICTS, before, after);
}
@@ -187,7 +187,7 @@ class GitOldChangesCollector extends GitChangesCollector {
StringTokenizer tokenizer = new StringTokenizer(output, "\n\r");
while (tokenizer.hasMoreTokens()) {
final String s = tokenizer.nextToken();
Change ch = new Change(null, GitContentRevision.createRevision(myVcsRoot, s, null, myProject, false, false), FileStatus.ADDED);
Change ch = new Change(null, GitContentRevision.createRevision(myVcsRoot, s, null, myProject, false, false, true), FileStatus.ADDED);
myChanges.add(ch);
}
}
@@ -258,8 +258,9 @@ class GitOldChangesCollector extends GitChangesCollector {
continue;
}
// assume modify-modify conflict
ContentRevision before = GitContentRevision.createRevision(myVcsRoot, file, new GitRevisionNumber("orig_head"), myProject, false, true);
ContentRevision after = GitContentRevision.createRevision(myVcsRoot, file, null, myProject, false, false);
ContentRevision before = GitContentRevision.createRevision(myVcsRoot, file, new GitRevisionNumber("orig_head"), myProject, false, true,
true);
ContentRevision after = GitContentRevision.createRevision(myVcsRoot, file, null, myProject, false, false, true);
myChanges.add(new Change(before, after, FileStatus.MERGED_WITH_CONFLICTS));
}
else {
@@ -208,7 +208,7 @@ class GitLogRecord {
case 'A':
before = null;
status = FileStatus.ADDED;
after = GitContentRevision.createRevision(vcsRoot, path, thisRevision, project, false, false);
after = GitContentRevision.createRevision(vcsRoot, path, thisRevision, project, false, false, true);
break;
case 'U':
status = FileStatus.MERGED_WITH_CONFLICTS;
@@ -216,21 +216,21 @@ class GitLogRecord {
if (status == null) {
status = FileStatus.MODIFIED;
}
final FilePath filePath = GitContentRevision.createPath(vcsRoot, path, false, true);
final FilePath filePath = GitContentRevision.createPath(vcsRoot, path, false, true, true);
before = GitContentRevision.createMultipleParentsRevision(project, filePath, parentRevisions);
after = GitContentRevision.createRevision(vcsRoot, path, thisRevision, project, false, false);
after = GitContentRevision.createRevision(vcsRoot, path, thisRevision, project, false, false, true);
break;
case 'D':
status = FileStatus.DELETED;
final FilePath filePathDeleted = GitContentRevision.createPath(vcsRoot, path, true, true);
final FilePath filePathDeleted = GitContentRevision.createPath(vcsRoot, path, true, true, true);
before = GitContentRevision.createMultipleParentsRevision(project, filePathDeleted, parentRevisions);
after = null;
break;
case 'R':
status = FileStatus.MODIFIED;
final FilePath filePathAfterRename = GitContentRevision.createPath(vcsRoot, parts.get(2), false, false);
final FilePath filePathAfterRename = GitContentRevision.createPath(vcsRoot, parts.get(2), false, false, true);
after = GitContentRevision.createMultipleParentsRevision(project, filePathAfterRename, parentRevisions);
before = GitContentRevision.createRevision(vcsRoot, path, thisRevision, project, true, true);
before = GitContentRevision.createRevision(vcsRoot, path, thisRevision, project, true, true, true);
break;
default:
throw new VcsException("Unknown file status: " + Arrays.asList(parts));