Moved several utility methods from GitFileUtils & GitUtil to VcsFileUtil so that...
authorKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Mon, 25 Apr 2011 16:50:21 +0000 (20:50 +0400)
committerKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Tue, 26 Apr 2011 12:25:37 +0000 (16:25 +0400)
21 files changed:
platform/vcs-impl/src/com/intellij/vcsUtil/VcsFileUtil.java [new file with mode: 0644]
plugins/git4idea/src/git4idea/GitBinaryContentRevision.java
plugins/git4idea/src/git4idea/GitContentRevision.java
plugins/git4idea/src/git4idea/GitFileRevision.java
plugins/git4idea/src/git4idea/GitUtil.java
plugins/git4idea/src/git4idea/actions/BasicAction.java
plugins/git4idea/src/git4idea/actions/GitInit.java
plugins/git4idea/src/git4idea/actions/GitRepositoryAction.java
plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java
plugins/git4idea/src/git4idea/checkin/GitPushActiveBranchesDialog.java
plugins/git4idea/src/git4idea/checkout/branches/GitBranchesWidget.java
plugins/git4idea/src/git4idea/commands/GitFileUtils.java
plugins/git4idea/src/git4idea/commands/GitHandler.java
plugins/git4idea/src/git4idea/diff/GitTreeDiffProvider.java
plugins/git4idea/src/git4idea/merge/GitMergeProvider.java
plugins/git4idea/src/git4idea/rollback/GitRollbackEnvironment.java
plugins/git4idea/src/git4idea/ui/GitConvertFilesDialog.java
plugins/git4idea/src/git4idea/vfs/GitConfigTracker.java
plugins/git4idea/src/git4idea/vfs/GitIgnoreTracker.java
plugins/git4idea/src/git4idea/vfs/GitVFSListener.java
plugins/git4idea/tests/git4idea/tests/GitUpperDirectorySearchTest.java

diff --git a/platform/vcs-impl/src/com/intellij/vcsUtil/VcsFileUtil.java b/platform/vcs-impl/src/com/intellij/vcsUtil/VcsFileUtil.java
new file mode 100644 (file)
index 0000000..e6cf9d5
--- /dev/null
@@ -0,0 +1,357 @@
+/*
+ * Copyright 2000-2011 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.vcsUtil;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.SystemInfo;
+import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.openapi.vcs.FilePath;
+import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager;
+import com.intellij.openapi.vfs.VfsUtil;
+import com.intellij.openapi.vfs.VirtualFile;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author Kirill Likhodedov
+ */
+public class VcsFileUtil {
+  /**
+   * If multiple paths are specified on the command line, this limit is used to split paths into chunks.
+   * The limit is less than OS limit to leave space to quoting, spaces, charset conversion, and commands arguments.
+   */
+  public static final int FILE_PATH_LIMIT = 7600;
+
+  /**
+   * Chunk paths on the command line
+   *
+   * @param files the paths to chunk
+   * @return the a list of list of relative paths
+   */
+  public static List<List<String>> chunkRelativePaths(List<String> files) {
+    ArrayList<List<String>> rc = new ArrayList<List<String>>();
+    int start = 0;
+    int size = 0;
+    int i = 0;
+    for (; i < files.size(); i++) {
+      String p = files.get(i);
+      if (size + p.length() > FILE_PATH_LIMIT) {
+        if (start == i) {
+          rc.add(files.subList(i, i + 1));
+          start = i + 1;
+        }
+        else {
+          rc.add(files.subList(start, i));
+          start = i;
+        }
+        size = 0;
+      }
+      else {
+        size += p.length();
+      }
+    }
+    if (start != files.size()) {
+      rc.add(files.subList(start, i));
+    }
+    return rc;
+  }
+
+  /**
+   * The chunk paths
+   *
+   * @param root  the vcs root
+   * @param files the file list
+   * @return chunked relative paths
+   */
+  public static List<List<String>> chunkPaths(VirtualFile root, Collection<FilePath> files) {
+    return chunkRelativePaths(toRelativePaths(root, files));
+  }
+
+  /**
+   * The chunk paths
+   *
+   * @param root  the vcs root
+   * @param files the file list
+   * @return chunked relative paths
+   */
+  public static List<List<String>> chunkFiles(VirtualFile root, Collection<VirtualFile> files) {
+    return chunkRelativePaths(toRelativeFiles(root, files));
+  }
+
+  public static String getRelativeFilePath(VirtualFile file, @NotNull final VirtualFile baseDir) {
+    return getRelativeFilePath(file.getPath(), baseDir);
+  }
+
+  public static String getRelativeFilePath(FilePath file, @NotNull final VirtualFile baseDir) {
+    return getRelativeFilePath(file.getPath(), baseDir);
+  }
+
+  public static String getRelativeFilePath(String file, @NotNull final VirtualFile baseDir) {
+    if (SystemInfo.isWindows) {
+      file = file.replace('\\', '/');
+    }
+    final String basePath = baseDir.getPath();
+    if (!file.startsWith(basePath)) {
+      return file;
+    }
+    else if (file.equals(basePath)) return ".";
+    return file.substring(baseDir.getPath().length() + 1);
+  }
+
+  /**
+   * Check if character is octal digit
+   *
+   * @param ch a character to test
+   * @return true if the octal digit, false otherwise
+   */
+  public static boolean isOctal(char ch) {
+    return '0' <= ch && ch <= '7';
+  }
+
+  /**
+   * Get relative path
+   *
+   * @param root a root path
+   * @param path a path to file (possibly deleted file)
+   * @return a relative path
+   * @throws IllegalArgumentException if path is not under root.
+   */
+  public static String relativePath(final VirtualFile root, FilePath path) {
+    return relativePath(VfsUtil.virtualToIoFile(root), path.getIOFile());
+  }
+
+  /**
+   * Get relative path
+   *
+   * @param root a root path
+   * @param path a path to file (possibly deleted file)
+   * @return a relative path
+   * @throws IllegalArgumentException if path is not under root.
+   */
+  public static String relativePath(final File root, FilePath path) {
+    return relativePath(root, path.getIOFile());
+  }
+
+  /**
+   * Get relative path
+   *
+   * @param root a root path
+   * @param file a virtual file
+   * @return a relative path
+   * @throws IllegalArgumentException if path is not under root.
+   */
+  public static String relativePath(final File root, VirtualFile file) {
+    return relativePath(root, VfsUtil.virtualToIoFile(file));
+  }
+
+  /**
+   * Get relative path
+   *
+   * @param root a root file
+   * @param file a virtual file
+   * @return a relative path
+   * @throws IllegalArgumentException if path is not under root.
+   */
+  public static String relativePath(final VirtualFile root, VirtualFile file) {
+    return relativePath(VfsUtil.virtualToIoFile(root), VfsUtil.virtualToIoFile(file));
+  }
+
+  /**
+   * Get relative path
+   *
+   * @param root a root file
+   * @param file a virtual file
+   * @return a relative path
+   * @throws IllegalArgumentException if path is not under root.
+   */
+  public static String relativeOrFullPath(final VirtualFile root, VirtualFile file) {
+    if (root == null) {
+      file.getPath();
+    }
+    return relativePath(VfsUtil.virtualToIoFile(root), VfsUtil.virtualToIoFile(file));
+  }
+
+  /**
+   * Get relative path
+   *
+   * @param root a root path
+   * @param path a path to file (possibly deleted file)
+   * @return a relative path
+   * @throws IllegalArgumentException if path is not under root.
+   */
+  public static String relativePath(final File root, File path) {
+    String rc = FileUtil.getRelativePath(root, path);
+    if (rc == null) {
+      throw new IllegalArgumentException("The file " + path + " cannot be made relative to " + root);
+    }
+    return rc.replace(File.separatorChar, '/');
+  }
+
+  /**
+   * Covert list of files to relative paths
+   *
+   * @param root      a vcs root
+   * @param filePaths a parameters to convert
+   * @return a list of relative paths
+   * @throws IllegalArgumentException if some path is not under root.
+   */
+  public static List<String> toRelativePaths(@NotNull VirtualFile root, @NotNull final Collection<FilePath> filePaths) {
+    ArrayList<String> rc = new ArrayList<String>(filePaths.size());
+    for (FilePath path : filePaths) {
+      rc.add(relativePath(root, path));
+    }
+    return rc;
+  }
+
+  /**
+   * Covert list of files to relative paths
+   *
+   * @param root  a vcs root
+   * @param files a parameters to convert
+   * @return a list of relative paths
+   * @throws IllegalArgumentException if some path is not under root.
+   */
+  public static List<String> toRelativeFiles(@NotNull VirtualFile root, @NotNull final Collection<VirtualFile> files) {
+    ArrayList<String> rc = new ArrayList<String>(files.size());
+    for (VirtualFile file : files) {
+      rc.add(relativePath(root, file));
+    }
+    return rc;
+  }
+
+  /**
+   * Refresh files
+   *
+   * @param project       a project
+   * @param affectedFiles affected files and directories
+   */
+  public static void refreshFiles(@NotNull final Project project, @NotNull final Collection<VirtualFile> affectedFiles) {
+    final VcsDirtyScopeManager dirty = VcsDirtyScopeManager.getInstance(project);
+    for (VirtualFile file : affectedFiles) {
+      if (!file.isValid()) {
+        continue;
+      }
+      file.refresh(false, true);
+      if (file.isDirectory()) {
+        dirty.dirDirtyRecursively(file);
+      }
+      else {
+        dirty.fileDirty(file);
+      }
+    }
+  }
+
+  /**
+   * Refresh files
+   *
+   * @param project       a project
+   * @param affectedFiles affected files and directories
+   */
+  public static void markFilesDirty(@NotNull final Project project, @NotNull final Collection<VirtualFile> affectedFiles) {
+    final VcsDirtyScopeManager dirty = VcsDirtyScopeManager.getInstance(project);
+    for (VirtualFile file : affectedFiles) {
+      if (!file.isValid()) {
+        continue;
+      }
+      if (file.isDirectory()) {
+        dirty.dirDirtyRecursively(file);
+      }
+      else {
+        dirty.fileDirty(file);
+      }
+    }
+  }
+
+  /**
+   * Mark files dirty
+   *
+   * @param project       a project
+   * @param affectedFiles affected files and directories
+   */
+  public static void markFilesDirty(Project project, List<FilePath> affectedFiles) {
+    final VcsDirtyScopeManager dirty = VcsDirtyScopeManager.getInstance(project);
+    for (FilePath file : affectedFiles) {
+      if (file.isDirectory()) {
+        dirty.dirDirtyRecursively(file);
+      }
+      else {
+        dirty.fileDirty(file);
+      }
+    }
+  }
+
+  /**
+   * Refresh files
+   *
+   * @param project       a project
+   * @param affectedFiles affected files and directories
+   */
+  public static void refreshFiles(Project project, List<FilePath> affectedFiles) {
+    final VcsDirtyScopeManager dirty = VcsDirtyScopeManager.getInstance(project);
+    for (FilePath file : affectedFiles) {
+      VirtualFile vFile = VcsUtil.getVirtualFile(file.getIOFile());
+      if (vFile != null) {
+        vFile.refresh(false, true);
+      }
+      if (file.isDirectory()) {
+        dirty.dirDirtyRecursively(file);
+      }
+      else {
+        dirty.fileDirty(file);
+      }
+    }
+  }
+
+  /**
+   * The get the possible base for the path. It tries to find the parent for the provided path.
+   *
+   * @param file the file to get base for
+   * @param path the path to to check
+   * @return the file base
+   */
+  @Nullable
+  public static VirtualFile getPossibleBase(final VirtualFile file, final String... path) {
+    if (file == null || path.length == 0) return null;
+
+    VirtualFile current = file;
+    final List<VirtualFile> backTrace = new ArrayList<VirtualFile>();
+    int idx = path.length - 1;
+    while (current != null) {
+      if (SystemInfo.isFileSystemCaseSensitive ? current.getName().equals(path[idx]) : current.getName().equalsIgnoreCase(path[idx])) {
+        if (idx == 0) {
+          return current;
+        }
+        -- idx;
+      } else if (idx != path.length - 1) {
+        int diff = path.length - 1 - idx - 1;
+        for (int i = 0; i < diff; i++) {
+          current = backTrace.remove(backTrace.size() - 1);
+        }
+        idx = path.length - 1;
+        continue;
+      }
+      backTrace.add(current);
+      current = current.getParent();
+    }
+
+    return null;
+  }
+}
index 2725612966bf8261816a70128818680a7ee3ccd0..36fba58ffd46ef31cce3936c55ec15dad24e6c16 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.openapi.vcs.FilePath;
 import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vcs.changes.BinaryContentRevision;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.vcsUtil.VcsFileUtil;
 import git4idea.commands.GitFileUtils;
 import org.jetbrains.annotations.NotNull;
 
@@ -39,6 +40,6 @@ public class GitBinaryContentRevision extends GitContentRevision implements Bina
       return null;
     }
     final VirtualFile root = GitUtil.getGitRoot(myFile);
-    return GitFileUtils.getFileContent(myProject, root, myRevision.getRev(), GitUtil.relativePath(root, myFile));
+    return GitFileUtils.getFileContent(myProject, root, myRevision.getRev(), VcsFileUtil.relativePath(root, myFile));
   }
 }
index 98c870b8adb7337f7fb0f2fd91072ed58619b082..3378881e64a5059685bbea6b3f4eda251b074d27 100644 (file)
@@ -25,6 +25,7 @@ import com.intellij.openapi.vcs.changes.CurrentContentRevision;
 import com.intellij.openapi.vcs.history.VcsRevisionNumber;
 import com.intellij.openapi.vfs.CharsetToolkit;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.vcsUtil.VcsFileUtil;
 import com.intellij.vcsUtil.VcsUtil;
 import git4idea.commands.GitFileUtils;
 import git4idea.history.wholeTree.GitBinaryMultipleContentsRevision;
@@ -70,7 +71,7 @@ public class GitContentRevision implements ContentRevision {
       return null;
     }
     VirtualFile root = GitUtil.getGitRoot(myFile);
-    byte[] result = GitFileUtils.getFileContent(myProject, root, myRevision.getRev(), GitUtil.relativePath(root, myFile));
+    byte[] result = GitFileUtils.getFileContent(myProject, root, myRevision.getRev(), VcsFileUtil.relativePath(root, myFile));
     if (myCharset == null) {
       myCharset = myFile.getCharset(myProject);
     }
index 38bf92c11ba051ce3de757c3d7c50f91b3d25219..2728d94dd610b40cf020a2f99c83ef014dfa626d 100644 (file)
@@ -23,6 +23,7 @@ import com.intellij.openapi.vcs.history.VcsFileRevision;
 import com.intellij.openapi.vcs.history.VcsFileRevisionEx;
 import com.intellij.openapi.vcs.history.VcsRevisionNumber;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.vcsUtil.VcsFileUtil;
 import git4idea.commands.GitFileUtils;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -110,7 +111,7 @@ public class GitFileRevision extends VcsFileRevisionEx implements Comparable<Vcs
   public synchronized void loadContent() throws VcsException {
     final VirtualFile root = GitUtil.getGitRoot(path);
     if (content == null) {
-      content = GitFileUtils.getFileContent(project, root, revision.getRev(), GitUtil.relativePath(root, path));
+      content = GitFileUtils.getFileContent(project, root, revision.getRev(), VcsFileUtil.relativePath(root, path));
       if (content == null) {
         content = new byte[0];
       }
index 54e17021f122fb25699ca42d95f4bb484cf4b4b6..e856243da9a739306caa50911da201f93682834b 100644 (file)
@@ -17,18 +17,15 @@ package git4idea;
 
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.SystemInfo;
-import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vcs.FilePath;
 import com.intellij.openapi.vcs.ProjectLevelVcsManager;
 import com.intellij.openapi.vcs.VcsException;
-import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager;
 import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
 import com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile;
 import com.intellij.openapi.vfs.LocalFileSystem;
-import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.util.Consumer;
+import com.intellij.vcsUtil.VcsFileUtil;
 import com.intellij.vcsUtil.VcsUtil;
 import git4idea.changes.GitChangeUtils;
 import git4idea.commands.GitCommand;
@@ -128,26 +125,6 @@ public class GitUtil {
     return result;
   }
 
-  public static String getRelativeFilePath(VirtualFile file, @NotNull final VirtualFile baseDir) {
-    return getRelativeFilePath(file.getPath(), baseDir);
-  }
-
-  public static String getRelativeFilePath(FilePath file, @NotNull final VirtualFile baseDir) {
-    return getRelativeFilePath(file.getPath(), baseDir);
-  }
-
-  public static String getRelativeFilePath(String file, @NotNull final VirtualFile baseDir) {
-    if (SystemInfo.isWindows) {
-      file = file.replace('\\', '/');
-    }
-    final String basePath = baseDir.getPath();
-    if (!file.startsWith(basePath)) {
-      return file;
-    }
-    else if (file.equals(basePath)) return ".";
-    return file.substring(baseDir.getPath().length() + 1);
-  }
-
   /**
    * Sort files by vcs root
    *
@@ -206,105 +183,6 @@ public class GitUtil {
     return rc;
   }
 
-  /**
-   * Unescape path returned by the Git
-   *
-   * @param path a path to unescape
-   * @return unescaped path
-   * @throws VcsException if the path in invalid
-   */
-  public static String unescapePath(String path) throws VcsException {
-    final int l = path.length();
-    StringBuilder rc = new StringBuilder(l);
-    for (int i = 0; i < path.length(); i++) {
-      char c = path.charAt(i);
-      if (c == '\\') {
-        //noinspection AssignmentToForLoopParameter
-        i++;
-        if (i >= l) {
-          throw new VcsException("Unterminated escape sequence in the path: " + path);
-        }
-        final char e = path.charAt(i);
-        switch (e) {
-          case '\\':
-            rc.append('\\');
-            break;
-          case 't':
-            rc.append('\t');
-            break;
-          case 'n':
-            rc.append('\n');
-            break;
-          default:
-            if (isOctal(e)) {
-              // collect sequence of characters as a byte array.
-              // count bytes first
-              int n = 0;
-              for (int j = i; j < l;) {
-                if (isOctal(path.charAt(j))) {
-                  n++;
-                  for (int k = 0; k < 3 && j < l && isOctal(path.charAt(j)); k++) {
-                    //noinspection AssignmentToForLoopParameter
-                    j++;
-                  }
-                }
-                if (j + 1 >= l || path.charAt(j) != '\\' || !isOctal(path.charAt(j + 1))) {
-                  break;
-                }
-                //noinspection AssignmentToForLoopParameter
-                j++;
-              }
-              // convert to byte array
-              byte[] b = new byte[n];
-              n = 0;
-              while (i < l) {
-                if (isOctal(path.charAt(i))) {
-                  int code = 0;
-                  for (int k = 0; k < 3 && i < l && isOctal(path.charAt(i)); k++) {
-                    code = code * 8 + (path.charAt(i) - '0');
-                    //noinspection AssignmentToForLoopParameter
-                    i++;
-                  }
-                  b[n++] = (byte)code;
-                }
-                if (i + 1 >= l || path.charAt(i) != '\\' || !isOctal(path.charAt(i + 1))) {
-                  break;
-                }
-                //noinspection AssignmentToForLoopParameter
-                i++;
-              }
-              assert n == b.length;
-              // add them to string
-              final String encoding = GitConfigUtil.getFileNameEncoding();
-              try {
-                rc.append(new String(b, encoding));
-              }
-              catch (UnsupportedEncodingException e1) {
-                throw new IllegalStateException("The file name encoding is unsuported: " + encoding);
-              }
-            }
-            else {
-              throw new VcsException("Unknown escape sequence '\\" + path.charAt(i) + "' in the path: " + path);
-            }
-        }
-      }
-      else {
-        rc.append(c);
-      }
-    }
-    return rc.toString();
-  }
-
-  /**
-   * Check if character is octal digit
-   *
-   * @param ch a character to test
-   * @return true if the octal digit, false otherwise
-   */
-  private static boolean isOctal(char ch) {
-    return '0' <= ch && ch <= '7';
-  }
-
   /**
    * Parse UNIX timestamp as it is returned by the git
    *
@@ -449,201 +327,6 @@ public class GitUtil {
     return gitRootOrNull(vFile) != null;
   }
 
-  /**
-   * Get relative path
-   *
-   * @param root a root path
-   * @param path a path to file (possibly deleted file)
-   * @return a relative path
-   * @throws IllegalArgumentException if path is not under root.
-   */
-  public static String relativePath(final VirtualFile root, FilePath path) {
-    return relativePath(VfsUtil.virtualToIoFile(root), path.getIOFile());
-  }
-
-
-  /**
-   * Get relative path
-   *
-   * @param root a root path
-   * @param path a path to file (possibly deleted file)
-   * @return a relative path
-   * @throws IllegalArgumentException if path is not under root.
-   */
-  public static String relativePath(final File root, FilePath path) {
-    return relativePath(root, path.getIOFile());
-  }
-
-  /**
-   * Get relative path
-   *
-   * @param root a root path
-   * @param file a virtual file
-   * @return a relative path
-   * @throws IllegalArgumentException if path is not under root.
-   */
-  public static String relativePath(final File root, VirtualFile file) {
-    return relativePath(root, VfsUtil.virtualToIoFile(file));
-  }
-
-  /**
-   * Get relative path
-   *
-   * @param root a root file
-   * @param file a virtual file
-   * @return a relative path
-   * @throws IllegalArgumentException if path is not under root.
-   */
-  public static String relativePath(final VirtualFile root, VirtualFile file) {
-    return relativePath(VfsUtil.virtualToIoFile(root), VfsUtil.virtualToIoFile(file));
-  }
-
-  /**
-   * Get relative path
-   *
-   * @param root a root file
-   * @param file a virtual file
-   * @return a relative path
-   * @throws IllegalArgumentException if path is not under root.
-   */
-  public static String relativeOrFullPath(final VirtualFile root, VirtualFile file) {
-    if (root == null) {
-      file.getPath();
-    }
-    return relativePath(VfsUtil.virtualToIoFile(root), VfsUtil.virtualToIoFile(file));
-  }
-
-  /**
-   * Get relative path
-   *
-   * @param root a root path
-   * @param path a path to file (possibly deleted file)
-   * @return a relative path
-   * @throws IllegalArgumentException if path is not under root.
-   */
-  public static String relativePath(final File root, File path) {
-    String rc = FileUtil.getRelativePath(root, path);
-    if (rc == null) {
-      throw new IllegalArgumentException("The file " + path + " cannot be made relative to " + root);
-    }
-    return rc.replace(File.separatorChar, '/');
-  }
-
-  /**
-   * Covert list of files to relative paths
-   *
-   * @param root      a vcs root
-   * @param filePaths a parameters to convert
-   * @return a list of relative paths
-   * @throws IllegalArgumentException if some path is not under root.
-   */
-  public static List<String> toRelativePaths(@NotNull VirtualFile root, @NotNull final Collection<FilePath> filePaths) {
-    ArrayList<String> rc = new ArrayList<String>(filePaths.size());
-    for (FilePath path : filePaths) {
-      rc.add(relativePath(root, path));
-    }
-    return rc;
-  }
-
-  /**
-   * Covert list of files to relative paths
-   *
-   * @param root  a vcs root
-   * @param files a parameters to convert
-   * @return a list of relative paths
-   * @throws IllegalArgumentException if some path is not under root.
-   */
-  public static List<String> toRelativeFiles(@NotNull VirtualFile root, @NotNull final Collection<VirtualFile> files) {
-    ArrayList<String> rc = new ArrayList<String>(files.size());
-    for (VirtualFile file : files) {
-      rc.add(relativePath(root, file));
-    }
-    return rc;
-  }
-
-  /**
-   * Refresh files
-   *
-   * @param project       a project
-   * @param affectedFiles affected files and directories
-   */
-  public static void refreshFiles(@NotNull final Project project, @NotNull final Collection<VirtualFile> affectedFiles) {
-    final VcsDirtyScopeManager dirty = VcsDirtyScopeManager.getInstance(project);
-    for (VirtualFile file : affectedFiles) {
-      if (!file.isValid()) {
-        continue;
-      }
-      file.refresh(false, true);
-      if (file.isDirectory()) {
-        dirty.dirDirtyRecursively(file);
-      }
-      else {
-        dirty.fileDirty(file);
-      }
-    }
-  }
-
-  /**
-   * Refresh files
-   *
-   * @param project       a project
-   * @param affectedFiles affected files and directories
-   */
-  public static void markFilesDirty(@NotNull final Project project, @NotNull final Collection<VirtualFile> affectedFiles) {
-    final VcsDirtyScopeManager dirty = VcsDirtyScopeManager.getInstance(project);
-    for (VirtualFile file : affectedFiles) {
-      if (!file.isValid()) {
-        continue;
-      }
-      if (file.isDirectory()) {
-        dirty.dirDirtyRecursively(file);
-      }
-      else {
-        dirty.fileDirty(file);
-      }
-    }
-  }
-
-
-  /**
-   * Mark files dirty
-   *
-   * @param project       a project
-   * @param affectedFiles affected files and directories
-   */
-  public static void markFilesDirty(Project project, List<FilePath> affectedFiles) {
-    final VcsDirtyScopeManager dirty = VcsDirtyScopeManager.getInstance(project);
-    for (FilePath file : affectedFiles) {
-      if (file.isDirectory()) {
-        dirty.dirDirtyRecursively(file);
-      }
-      else {
-        dirty.fileDirty(file);
-      }
-    }
-  }
-
-  /**
-   * Refresh files
-   *
-   * @param project       a project
-   * @param affectedFiles affected files and directories
-   */
-  public static void refreshFiles(Project project, List<FilePath> affectedFiles) {
-    final VcsDirtyScopeManager dirty = VcsDirtyScopeManager.getInstance(project);
-    for (FilePath file : affectedFiles) {
-      VirtualFile vFile = VcsUtil.getVirtualFile(file.getIOFile());
-      if (vFile != null) {
-        vFile.refresh(false, true);
-      }
-      if (file.isDirectory()) {
-        dirty.dirDirtyRecursively(file);
-      }
-      else {
-        dirty.fileDirty(file);
-      }
-    }
-  }
 
   /**
    * Return committer name based on author name and committer name
@@ -708,41 +391,6 @@ public class GitUtil {
     return String.format("%015x%x", (rev >>> 4), rev & 0xF);
   }
 
-  /**
-   * The get the possible base for the path. It tries to find the parent for the provided path.
-   *
-   * @param file the file to get base for
-   * @param path the path to to check
-   * @return the file base
-   */
-  @Nullable
-  public static VirtualFile getPossibleBase(final VirtualFile file, final String... path) {
-    if (file == null || path.length == 0) return null;
-
-    VirtualFile current = file;
-    final List<VirtualFile> backTrace = new ArrayList<VirtualFile>();
-    int idx = path.length - 1;
-    while (current != null) {
-      if (SystemInfo.isFileSystemCaseSensitive ? current.getName().equals(path[idx]) : current.getName().equalsIgnoreCase(path[idx])) {
-        if (idx == 0) {
-          return current;
-        }
-        -- idx;
-      } else if (idx != path.length - 1) {
-        int diff = path.length - 1 - idx - 1;
-        for (int i = 0; i < diff; i++) {
-          current = backTrace.remove(backTrace.size() - 1);
-        }
-        idx = path.length - 1;
-        continue;
-      }
-      backTrace.add(current);
-      current = current.getParent();
-    }
-
-    return null;
-  }
-
   public static void getLocalCommittedChanges(final Project project,
                                               final VirtualFile root,
                                               final Consumer<GitSimpleHandler> parametersSpecifier,
@@ -795,21 +443,91 @@ public class GitUtil {
   }
 
   /**
-   * Cast or wrap exception into a vcs exception, errors and runtime exceptions are just thrown throw.
+   * Unescape path returned by the Git
    *
-   * @param t an exception to throw
-   * @return a wrapped exception
+   * @param path a path to unescape
+   * @return unescaped path
+   * @throws com.intellij.openapi.vcs.VcsException if the path in invalid
    */
-  public static VcsException rethrowVcsException(Throwable t) {
-    if (t instanceof Error) {
-      throw (Error)t;
-    }
-    if (t instanceof RuntimeException) {
-      throw (RuntimeException)t;
-    }
-    if (t instanceof VcsException) {
-      return (VcsException)t;
+  public static String unescapePath(String path) throws VcsException {
+    final int l = path.length();
+    StringBuilder rc = new StringBuilder(l);
+    for (int i = 0; i < path.length(); i++) {
+      char c = path.charAt(i);
+      if (c == '\\') {
+        //noinspection AssignmentToForLoopParameter
+        i++;
+        if (i >= l) {
+          throw new VcsException("Unterminated escape sequence in the path: " + path);
+        }
+        final char e = path.charAt(i);
+        switch (e) {
+          case '\\':
+            rc.append('\\');
+            break;
+          case 't':
+            rc.append('\t');
+            break;
+          case 'n':
+            rc.append('\n');
+            break;
+          default:
+            if (VcsFileUtil.isOctal(e)) {
+              // collect sequence of characters as a byte array.
+              // count bytes first
+              int n = 0;
+              for (int j = i; j < l;) {
+                if (VcsFileUtil.isOctal(path.charAt(j))) {
+                  n++;
+                  for (int k = 0; k < 3 && j < l && VcsFileUtil.isOctal(path.charAt(j)); k++) {
+                    //noinspection AssignmentToForLoopParameter
+                    j++;
+                  }
+                }
+                if (j + 1 >= l || path.charAt(j) != '\\' || !VcsFileUtil.isOctal(path.charAt(j + 1))) {
+                  break;
+                }
+                //noinspection AssignmentToForLoopParameter
+                j++;
+              }
+              // convert to byte array
+              byte[] b = new byte[n];
+              n = 0;
+              while (i < l) {
+                if (VcsFileUtil.isOctal(path.charAt(i))) {
+                  int code = 0;
+                  for (int k = 0; k < 3 && i < l && VcsFileUtil.isOctal(path.charAt(i)); k++) {
+                    code = code * 8 + (path.charAt(i) - '0');
+                    //noinspection AssignmentToForLoopParameter
+                    i++;
+                  }
+                  b[n++] = (byte)code;
+                }
+                if (i + 1 >= l || path.charAt(i) != '\\' || !VcsFileUtil.isOctal(path.charAt(i + 1))) {
+                  break;
+                }
+                //noinspection AssignmentToForLoopParameter
+                i++;
+              }
+              assert n == b.length;
+              // add them to string
+              final String encoding = GitConfigUtil.getFileNameEncoding();
+              try {
+                rc.append(new String(b, encoding));
+              }
+              catch (UnsupportedEncodingException e1) {
+                throw new IllegalStateException("The file name encoding is unsuported: " + encoding);
+              }
+            }
+            else {
+              throw new VcsException("Unknown escape sequence '\\" + path.charAt(i) + "' in the path: " + path);
+            }
+        }
+      }
+      else {
+        rc.append(c);
+      }
     }
-    return new VcsException(t.getMessage(), t);
+    return rc.toString();
   }
 }
index 4d2adf59eab386dc2485818774858fe9c49991f7..0f0ad9e3ee397ccc078cc30770b58ecebd9a72e0 100644 (file)
@@ -30,7 +30,7 @@ import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.util.Consumer;
 import com.intellij.util.ui.UIUtil;
-import git4idea.GitUtil;
+import com.intellij.vcsUtil.VcsFileUtil;
 import git4idea.GitVcs;
 import git4idea.ui.GitUIUtil;
 import org.jetbrains.annotations.NotNull;
@@ -71,7 +71,7 @@ public abstract class BasicAction extends DumbAwareAction {
       vcs.runInBackground(new Task.Backgroundable(project, getActionName()) {
 
         public void run(@NotNull ProgressIndicator indicator) {
-          GitUtil.refreshFiles(project, Arrays.asList(affectedFiles));
+          VcsFileUtil.refreshFiles(project, Arrays.asList(affectedFiles));
           UIUtil.invokeLaterIfNeeded(new Runnable() {
             public void run() {
               GitUIUtil.showOperationErrors(project, exceptions, actionName);
@@ -115,7 +115,7 @@ public abstract class BasicAction extends DumbAwareAction {
       
       public void run(@NotNull ProgressIndicator indicator) {
         action.consume(indicator);
-        GitUtil.refreshFiles(project, Arrays.asList(affectedFiles));
+        VcsFileUtil.refreshFiles(project, Arrays.asList(affectedFiles));
         UIUtil.invokeLaterIfNeeded(new Runnable() {
           public void run() {
             GitUIUtil.showOperationErrors(project, exceptions, getActionName());
index ae31838a3d88cca4122248b00c4f34e25c7c5670..e2881162af4d78f9ccb5167495e554a2718481c6 100644 (file)
@@ -30,6 +30,7 @@ import com.intellij.openapi.vcs.ProjectLevelVcsManager;
 import com.intellij.openapi.vcs.VcsDirectoryMapping;
 import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.vcsUtil.VcsFileUtil;
 import git4idea.Git;
 import git4idea.GitUtil;
 import git4idea.GitVcs;
@@ -120,7 +121,7 @@ public class GitInit extends DumbAwareAction {
     }
     vcs.setDirectoryMappings(vcsDirectoryMappings);
     vcs.updateActiveVcss();
-    GitUtil.refreshFiles(project, Collections.singleton(root));
+    VcsFileUtil.refreshFiles(project, Collections.singleton(root));
   }
 
 }
index ff3a683a9c5c614277c3709f11a0b6c7d84a6b4e..19c2b9ab204ad7667312b9e2b5ec36ba12206288 100644 (file)
@@ -29,6 +29,7 @@ import com.intellij.openapi.vcs.ProjectLevelVcsManager;
 import com.intellij.openapi.vcs.TransactionRunnable;
 import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.vcsUtil.VcsFileUtil;
 import git4idea.GitUtil;
 import git4idea.GitVcs;
 import git4idea.i18n.GitBundle;
@@ -97,7 +98,7 @@ public abstract class GitRepositoryAction extends DumbAwareAction {
         catch (VcsException e) {
           exceptions.add(e);
         }
-        GitUtil.refreshFiles(project, affectedRoots);
+        VcsFileUtil.refreshFiles(project, affectedRoots);
         for (TransactionRunnable task : myDelayedTasks) {
           task.run(exceptions);
         }
index 847b2d9cb0cb4af5dae856cc74a3476f0d8b34c0..5588ae0b606a1860724ae6ef5de87e1ff1b8c503 100644 (file)
@@ -37,6 +37,7 @@ import com.intellij.util.NullableFunction;
 import com.intellij.util.PairConsumer;
 import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.ui.UIUtil;
+import com.intellij.vcsUtil.VcsFileUtil;
 import com.intellij.vcsUtil.VcsUtil;
 import git4idea.GitUtil;
 import git4idea.commands.GitCommand;
@@ -442,7 +443,7 @@ public class GitCheckinEnvironment implements CheckinEnvironment {
                              boolean nextCommitAmend)
     throws VcsException {
     boolean amend = nextCommitAmend;
-    for (List<String> paths : GitFileUtils.chunkPaths(root, files)) {
+    for (List<String> paths : VcsFileUtil.chunkPaths(root, files)) {
       GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.COMMIT);
       handler.setNoSSH(true);
       if (amend) {
index 6e1bc8338c1685bc0590c9a6c132bff2535dbd55..f6939e289a445cece5f4cdd7254279c49c8a6659 100644 (file)
@@ -41,9 +41,9 @@ import com.intellij.util.continuation.ContinuationContext;
 import com.intellij.util.text.DateFormatUtil;
 import com.intellij.util.ui.UIUtil;
 import com.intellij.util.ui.tree.TreeUtil;
+import com.intellij.vcsUtil.VcsFileUtil;
 import git4idea.GitBranch;
 import git4idea.GitRevisionNumber;
-import git4idea.GitUtil;
 import git4idea.GitVcs;
 import git4idea.actions.GitRepositoryAction;
 import git4idea.actions.GitShowAllSubmittedFilesAction;
@@ -271,7 +271,7 @@ public class GitPushActiveBranchesDialog extends DialogWrapper {
               notifyMessage(myProject, "Failed to rebase", null, NotificationType.ERROR, true, exceptions);
               return;
             }
-            GitUtil.refreshFiles(myProject, rebaseInfo.roots);
+            VcsFileUtil.refreshFiles(myProject, rebaseInfo.roots);
           }
         }
         notifyMessage(myProject, "Failed to push", "Update project and push again", NotificationType.ERROR, true, pushExceptions);
@@ -418,7 +418,7 @@ public class GitPushActiveBranchesDialog extends DialogWrapper {
       GitUIUtil.showOperationErrors(myProject, exceptions, "git rebase");
     }
     refreshTree(false, rebaseInfo.uncheckedCommits);
-    GitUtil.refreshFiles(myProject, rebaseInfo.roots);
+    VcsFileUtil.refreshFiles(myProject, rebaseInfo.roots);
   }
 
   private boolean executeRebase(final List<VcsException> exceptions, RebaseInfo rebaseInfo) {
index 6c15a5a0170147f0076788609018db2baa5c9ec1..bf1c2e7433a1fbcf531e57e941f850c8ba355630 100644 (file)
@@ -42,6 +42,7 @@ import com.intellij.openapi.wm.WindowManager;
 import com.intellij.openapi.wm.impl.status.TextPanel;
 import com.intellij.ui.awt.RelativePoint;
 import com.intellij.util.ui.UIUtil;
+import com.intellij.vcsUtil.VcsFileUtil;
 import git4idea.GitUtil;
 import git4idea.GitVcs;
 import git4idea.commands.GitCommand;
@@ -629,7 +630,7 @@ public class GitBranchesWidget extends TextPanel implements CustomStatusBarWidge
               GitLineHandler h = new GitLineHandler(myProject, root, GitCommand.FETCH);
               h.addParameters("--all", "-v");
               final Collection<VcsException> e = GitHandlerUtil
-                .doSynchronouslyWithExceptions(h, indicator, "Fetching all for " + GitUtil.relativePath(myProject.getBaseDir(), root));
+                .doSynchronouslyWithExceptions(h, indicator, "Fetching all for " + VcsFileUtil.relativePath(myProject.getBaseDir(), root));
               exceptions.addAll(e);
             }
           }
index 88711b9af5f88e7e5262148cd07d3536b5e3ad49..31d09e596a0a358d4b872f050f52b206f8cf63d7 100644 (file)
@@ -19,10 +19,9 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vcs.FilePath;
 import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vfs.VirtualFile;
-import git4idea.GitUtil;
+import com.intellij.vcsUtil.VcsFileUtil;
 import org.jetbrains.annotations.Nullable;
 
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
@@ -31,11 +30,6 @@ import java.util.List;
  * File utilities for the git
  */
 public class GitFileUtils {
-  /**
-   * If multiple paths are specified on the command line, this limit is used to split paths into chunks.
-   * The limit is less than OS limit to leave space to quoting, spaces, charset conversion, and commands arguments.
-   */
-  public static final int FILE_PATH_LIMIT = 7600;
 
   /**
    * The private constructor for static utility class
@@ -44,62 +38,6 @@ public class GitFileUtils {
     // do nothing
   }
 
-  /**
-   * Chunk paths on the command line
-   *
-   * @param files the paths to chunk
-   * @return the a list of list of relative paths
-   */
-  public static List<List<String>> chunkRelativePaths(List<String> files) {
-    ArrayList<List<String>> rc = new ArrayList<List<String>>();
-    int start = 0;
-    int size = 0;
-    int i = 0;
-    for (; i < files.size(); i++) {
-      String p = files.get(i);
-      if (size + p.length() > FILE_PATH_LIMIT) {
-        if (start == i) {
-          rc.add(files.subList(i, i + 1));
-          start = i + 1;
-        }
-        else {
-          rc.add(files.subList(start, i));
-          start = i;
-        }
-        size = 0;
-      }
-      else {
-        size += p.length();
-      }
-    }
-    if (start != files.size()) {
-      rc.add(files.subList(start, i));
-    }
-    return rc;
-  }
-
-  /**
-   * The chunk paths
-   *
-   * @param root  the vcs root
-   * @param files the file list
-   * @return chunked relative paths
-   */
-  public static List<List<String>> chunkPaths(VirtualFile root, Collection<FilePath> files) {
-    return chunkRelativePaths(GitUtil.toRelativePaths(root, files));
-  }
-
-  /**
-   * The chunk paths
-   *
-   * @param root  the vcs root
-   * @param files the file list
-   * @return chunked relative paths
-   */
-  public static List<List<String>> chunkFiles(VirtualFile root, Collection<VirtualFile> files) {
-    return chunkRelativePaths(GitUtil.toRelativeFiles(root, files));
-  }
-
   /**
    * Delete files
    *
@@ -112,7 +50,7 @@ public class GitFileUtils {
 
   public static void delete(Project project, VirtualFile root, Collection<FilePath> files, String... additionalOptions)
     throws VcsException {
-    for (List<String> paths : chunkPaths(root, files)) {
+    for (List<String> paths : VcsFileUtil.chunkPaths(root, files)) {
       GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.RM);
       handler.addParameters(additionalOptions);
       handler.endOptions();
@@ -141,7 +79,7 @@ public class GitFileUtils {
    * @throws VcsException in case of git problem
    */
   public static void deleteFiles(Project project, VirtualFile root, List<VirtualFile> files) throws VcsException {
-    for (List<String> paths : chunkFiles(root, files)) {
+    for (List<String> paths : VcsFileUtil.chunkFiles(root, files)) {
       GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.RM);
       handler.endOptions();
       handler.addParameters(paths);
@@ -173,7 +111,7 @@ public class GitFileUtils {
    * @throws VcsException in case of git problem
    */
   public static void addFiles(Project project, VirtualFile root, Collection<VirtualFile> files) throws VcsException {
-    for (List<String> paths : chunkFiles(root, files)) {
+    for (List<String> paths : VcsFileUtil.chunkFiles(root, files)) {
       GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.ADD);
       handler.endOptions();
       handler.addParameters(paths);
@@ -205,7 +143,7 @@ public class GitFileUtils {
    * @throws VcsException in case of git problem
    */
   public static void addPaths(Project project, VirtualFile root, Collection<FilePath> files) throws VcsException {
-    for (List<String> paths : chunkPaths(root, files)) {
+    for (List<String> paths : VcsFileUtil.chunkPaths(root, files)) {
       GitSimpleHandler handler = new GitSimpleHandler(project, root, GitCommand.ADD);
       handler.endOptions();
       handler.addParameters(paths);
@@ -248,23 +186,4 @@ public class GitFileUtils {
     return result;
   }
 
-  /**
-   * Returns the GitFileRevision for given parameters.
-   * @param revisionOrBranch full hash of the revision, or branch name, or tag name - any will do.
-   * @param loadContent should the content be preloaded in the returned VcsFileRevision.
-   * @return VcsFileRevision for the given parameters.
-   */
-  //@Nullable
-  //public static VcsFileRevision getFileRevision(Project project, VirtualFile vcsRoot, String revisionOrBranch, String relativePath, boolean loadContent) {
-  //  GitSimpleHandler h = new GitSimpleHandler(project, vcsRoot, GitCommand.SHOW);
-  //  h.setNoSSH(true);
-  //  h.setSilent(true);
-  //  h.addParameters(revisionOrBranch + ":" + relativePath);
-  //
-  //  if (!loadContent) {
-  //    h.addParameters("--name-only");
-  //  }
-  //
-  //}
-  
 }
index 3022dceb6d819c0395dae39c976dfee770ab263a..2f1b90faec3aef2d360ac4adc2d298110403dc49 100644 (file)
@@ -28,7 +28,7 @@ import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.util.EventDispatcher;
 import com.intellij.util.Processor;
-import git4idea.GitUtil;
+import com.intellij.vcsUtil.VcsFileUtil;
 import git4idea.GitVcs;
 import git4idea.config.GitVcsApplicationSettings;
 import git4idea.config.GitVcsSettings;
@@ -302,7 +302,7 @@ public abstract class GitHandler {
   public void addRelativePaths(@NotNull final Collection<FilePath> filePaths) {
     checkNotStarted();
     for (FilePath path : filePaths) {
-      myCommandLine.addParameter(GitUtil.relativePath(myWorkingDirectory, path));
+      myCommandLine.addParameter(VcsFileUtil.relativePath(myWorkingDirectory, path));
     }
   }
 
@@ -315,7 +315,7 @@ public abstract class GitHandler {
   public void addRelativePathsForFiles(@NotNull final Collection<File> files) {
     checkNotStarted();
     for (File file : files) {
-      myCommandLine.addParameter(GitUtil.relativePath(myWorkingDirectory, file));
+      myCommandLine.addParameter(VcsFileUtil.relativePath(myWorkingDirectory, file));
     }
   }
 
@@ -329,7 +329,7 @@ public abstract class GitHandler {
   public void addRelativeFiles(@NotNull final Collection<VirtualFile> files) {
     checkNotStarted();
     for (VirtualFile file : files) {
-      myCommandLine.addParameter(GitUtil.relativePath(myWorkingDirectory, file));
+      myCommandLine.addParameter(VcsFileUtil.relativePath(myWorkingDirectory, file));
     }
   }
 
@@ -632,7 +632,7 @@ public abstract class GitHandler {
    * @return true if the command line is too big
    */
   public boolean isLargeCommandLine() {
-    return myCommandLine.getCommandLineString().length() > GitFileUtils.FILE_PATH_LIMIT;
+    return myCommandLine.getCommandLineString().length() > VcsFileUtil.FILE_PATH_LIMIT;
   }
 
   public void runInCurrentThread(Runnable postStartAction) {
index a37aec26a7b40d12ee2dea0d34f87b3fa42a46e3..5da1cb4f5279bbdf96a4c3ecbef04326dfe0f353 100644 (file)
@@ -22,11 +22,11 @@ import com.intellij.openapi.vcs.FilePath;
 import com.intellij.openapi.vcs.TreeDiffProvider;
 import com.intellij.openapi.vcs.VcsException;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.vcsUtil.VcsFileUtil;
 import com.intellij.vcsUtil.VcsUtil;
 import git4idea.GitBranchesSearcher;
 import git4idea.changes.GitChangeUtils;
 import git4idea.commands.GitCommand;
-import git4idea.commands.GitFileUtils;
 import git4idea.commands.GitSimpleHandler;
 import git4idea.commands.StringScanner;
 
@@ -52,7 +52,7 @@ public class GitTreeDiffProvider implements TreeDiffProvider {
       for (String path : paths) {
         files.add(VcsUtil.getFilePath(path));
       }
-      for (List<String> pathList : GitFileUtils.chunkPaths(vcsRoot, files)) {
+      for (List<String> pathList : VcsFileUtil.chunkPaths(vcsRoot, files)) {
         GitSimpleHandler handler = new GitSimpleHandler(myProject, vcsRoot, GitCommand.DIFF);
         handler.addParameters("--name-status", "--diff-filter=ADCRUX", "-M", "HEAD..." + searcher.getRemote().getFullName());
         handler.setNoSSH(true);
index e380823b936bf6a987e0a33716f0219e8a7ccf16..476c3db7155264298ca357bf7f90b53826af81a1 100644 (file)
@@ -24,6 +24,7 @@ import com.intellij.openapi.vcs.merge.MergeProvider2;
 import com.intellij.openapi.vcs.merge.MergeSession;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.util.ui.ColumnInfo;
+import com.intellij.vcsUtil.VcsFileUtil;
 import com.intellij.vcsUtil.VcsRunnable;
 import com.intellij.vcsUtil.VcsUtil;
 import git4idea.GitFileRevision;
@@ -271,7 +272,7 @@ public class GitMergeProvider implements MergeProvider2 {
             }
           }
           for (VirtualFile f : files) {
-            String path = GitUtil.relativePath(root, f);
+            String path = VcsFileUtil.relativePath(root, f);
             Conflict c = cs.get(path);
             assert c != null : "The conflict not found for the file: " + f.getPath() + "(" + path + ")";
             c.myFile = f;
index 8cb5f8a8f0cfec293323cb5ca6278fe888d146ca..92b4dd6bf24724988446aab6c7d45038e5309da6 100644 (file)
@@ -25,6 +25,7 @@ import com.intellij.openapi.vcs.rollback.RollbackEnvironment;
 import com.intellij.openapi.vcs.rollback.RollbackProgressListener;
 import com.intellij.openapi.vfs.LocalFileSystem;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.vcsUtil.VcsFileUtil;
 import git4idea.GitUtil;
 import git4idea.commands.GitCommand;
 import git4idea.commands.GitFileUtils;
@@ -180,7 +181,7 @@ public class GitRollbackEnvironment implements RollbackEnvironment {
    * @throws VcsException Id it breaks.
    */
   public void revert(final VirtualFile root, final List<FilePath> files) throws VcsException {
-    for (List<String> paths : GitFileUtils.chunkPaths(root, files)) {
+    for (List<String> paths : VcsFileUtil.chunkPaths(root, files)) {
       GitSimpleHandler handler = new GitSimpleHandler(myProject, root, GitCommand.CHECKOUT);
       handler.setNoSSH(true);
       handler.addParameters("HEAD");
index 271b0228f04958cfa069d72122bedd1a9c064c1b..cb963bf1cd307cd548b217576d2bc7aed1657704 100644 (file)
@@ -22,6 +22,7 @@ import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.ui.*;
 import com.intellij.util.ui.UIUtil;
 import com.intellij.util.ui.tree.TreeUtil;
+import com.intellij.vcsUtil.VcsFileUtil;
 import git4idea.DialogManager;
 import git4idea.GitUtil;
 import git4idea.config.GitVcsSettings;
@@ -172,7 +173,7 @@ public class GitConvertFilesDialog extends DialogWrapper {
         if (i != null) {
           r.setIcon(i);
         }
-        r.append(GitUtil.getRelativeFilePath(file, parent), SimpleTextAttributes.REGULAR_ATTRIBUTES, true);
+        r.append(VcsFileUtil.getRelativeFilePath(file, parent), SimpleTextAttributes.REGULAR_ATTRIBUTES, true);
       }
       else {
         // the vcs root node
index 30f000c258c5d0929ae00c4e2b9ba3c3259ec1c8..cb98be7a11c8c8f66282bba38c14392080e1f3bb 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vcs.ProjectLevelVcsManager;
 import com.intellij.openapi.vfs.*;
 import com.intellij.util.containers.HashSet;
+import com.intellij.vcsUtil.VcsFileUtil;
 import git4idea.GitUtil;
 import git4idea.GitVcs;
 import org.jetbrains.annotations.Nullable;
@@ -161,7 +162,7 @@ public class GitConfigTracker implements GitRootsListener {
         }
         return;
       }
-      VirtualFile base = GitUtil.getPossibleBase(file, ".git", "config");
+      VirtualFile base = VcsFileUtil.getPossibleBase(file, ".git", "config");
       if (base != null) {
         boolean reported;
         synchronized (myReportedRoots) {
index b9e55862a04aa525443e53d79c5cd29fb3c5f4f5..117de8274345203ffb34438c38d058d9d4678128 100644 (file)
@@ -25,7 +25,7 @@ import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager;
 import com.intellij.openapi.vfs.*;
 import com.intellij.util.containers.HashMap;
 import com.intellij.util.containers.HashSet;
-import git4idea.GitUtil;
+import com.intellij.vcsUtil.VcsFileUtil;
 import git4idea.GitVcs;
 import git4idea.config.GitConfigUtil;
 import org.jetbrains.annotations.NotNull;
@@ -333,7 +333,7 @@ public class GitIgnoreTracker {
         }
         return;
       }
-      final VirtualFile base = GitUtil.getPossibleBase(file, LOCAL_EXCLUDE_ARRAY);
+      final VirtualFile base = VcsFileUtil.getPossibleBase(file, LOCAL_EXCLUDE_ARRAY);
       if (base != null) {
         myDirtyScopeManager.dirDirtyRecursively(base);
         return;
index dbcc179d14bbb82bd6440d0b85489b1186d8ed9c..98fcba470a6070b7c14c3cd713fc7edc6fa19cd8 100644 (file)
@@ -27,6 +27,7 @@ import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.VirtualFileEvent;
 import com.intellij.ui.AppUIUtil;
 import com.intellij.util.ui.UIUtil;
+import com.intellij.vcsUtil.VcsFileUtil;
 import com.intellij.vcsUtil.VcsUtil;
 import git4idea.GitUtil;
 import git4idea.GitVcs;
@@ -125,7 +126,7 @@ public class GitVFSListener extends VcsVFSListener {
         for (Map.Entry<VirtualFile, List<VirtualFile>> e : sortedFiles.entrySet()) {
           VirtualFile root = e.getKey();
           pi.setText(root.getPresentableUrl());
-          for (List<String> paths : GitFileUtils.chunkFiles(root, e.getValue())) {
+          for (List<String> paths : VcsFileUtil.chunkFiles(root, e.getValue())) {
             pi.setText2(paths.get(0) + "...");
             try {
               GitSimpleHandler h = new GitSimpleHandler(myProject, root, GitCommand.LS_FILES);
@@ -192,7 +193,7 @@ public class GitVFSListener extends VcsVFSListener {
             final VirtualFile root = e.getKey();
             indicator.setText(root.getPresentableUrl());
             GitFileUtils.addFiles(myProject, root, e.getValue());
-            GitUtil.markFilesDirty(myProject, e.getValue());
+            VcsFileUtil.markFilesDirty(myProject, e.getValue());
           }
           catch (final VcsException ex) {
             UIUtil.invokeLaterIfNeeded(new Runnable() {
@@ -235,7 +236,7 @@ public class GitVFSListener extends VcsVFSListener {
             final VirtualFile root = e.getKey();
             indicator.setText(root.getPresentableUrl());
             GitFileUtils.addPaths(myProject, root, e.getValue());
-            GitUtil.markFilesDirty(myProject, e.getValue());
+            VcsFileUtil.markFilesDirty(myProject, e.getValue());
           }
           catch (final VcsException ex) {
             UIUtil.invokeLaterIfNeeded(new Runnable() {
@@ -292,7 +293,7 @@ public class GitVFSListener extends VcsVFSListener {
             indicator.setText(root.getPresentableUrl());
             GitFileUtils.delete(myProject, root, e.getValue(), "--ignore-unmatch");
             if (myProject != null && !myProject.isDisposed()) {
-              GitUtil.markFilesDirty(myProject, e.getValue());
+              VcsFileUtil.markFilesDirty(myProject, e.getValue());
             }
             for (FilePath p : e.getValue()) {
               for (File f = p.getIOFile(); f != null && !f.equals(rootFile); f = f.getParentFile()) {
index 3ef1b7c5e81ea4ba19742b7cf65100c3c5b43a7c..4b40baa95f033b620a117e483462373436e5e457 100644 (file)
@@ -23,7 +23,7 @@ import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
 import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
 import com.intellij.testFramework.fixtures.TestFixtureBuilder;
 import com.intellij.util.ui.UIUtil;
-import git4idea.GitUtil;
+import com.intellij.vcsUtil.VcsFileUtil;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -77,7 +77,7 @@ public class GitUpperDirectorySearchTest {
     Assert.assertNotNull(dir);
     Assert.assertNotNull(childFile);
 
-    final VirtualFile result = GitUtil.getPossibleBase(childFile, dirName);
+    final VirtualFile result = VcsFileUtil.getPossibleBase(childFile, dirName);
     Assert.assertEquals(result, dir);
   }
 
@@ -98,7 +98,7 @@ public class GitUpperDirectorySearchTest {
     Assert.assertNotNull(dir);
     Assert.assertNotNull(childFile);
 
-    final VirtualFile result = GitUtil.getPossibleBase(childFile, dirName.split("/"));
+    final VirtualFile result = VcsFileUtil.getPossibleBase(childFile, dirName.split("/"));
     Assert.assertEquals(result, dir);
   }
 
@@ -119,7 +119,7 @@ public class GitUpperDirectorySearchTest {
     Assert.assertNotNull(dir);
     Assert.assertNotNull(childFile);
 
-    final VirtualFile result = GitUtil.getPossibleBase(childFile, dirName.split("/"));
+    final VirtualFile result = VcsFileUtil.getPossibleBase(childFile, dirName.split("/"));
     Assert.assertEquals(result, dir);
   }
 }