Package org.eclipse.jgit.util

Examples of org.eclipse.jgit.util.FS


   * @throws IOException
   */
  public void pack(List<String> refs) throws IOException {
    if (refs.size() == 0)
      return;
    FS fs = parent.getFS();

    // Lock the packed refs file and read the content
    LockFile lck = new LockFile(packedRefsFile, fs);
    if (!lck.lock())
      throw new IOException(MessageFormat.format(
          JGitText.get().cannotLock, packedRefsFile));

    try {
      final PackedRefList packed = getPackedRefs();
      RefList<Ref> cur = readPackedRefs();

      // Iterate over all refs to be packed
      for (String refName : refs) {
        Ref ref = readRef(refName, cur);
        if (ref.isSymbolic())
          continue; // can't pack symbolic refs
        // Add/Update it to packed-refs
        int idx = cur.find(refName);
        if (idx >= 0)
          cur = cur.set(idx, peeledPackedRef(ref));
        else
          cur = cur.add(idx, peeledPackedRef(ref));
      }

      // The new content for packed-refs is collected. Persist it.
      commitPackedRefs(lck, cur, packed);

      // Now delete the loose refs which are now packed
      for (String refName : refs) {
        // Lock the loose ref
        File refFile = fileFor(refName);
        if (!fs.exists(refFile))
          continue;
        LockFile rLck = new LockFile(refFile,
            parent.getFS());
        if (!rLck.lock())
          continue;
View Full Code Here


      Set<String> untrackedAndIgnoredFiles = new TreeSet<String>(
          status.getUntracked());
      Set<String> untrackedAndIgnoredDirs = new TreeSet<String>(
          status.getUntrackedFolders());

      FS fs = getRepository().getFS();
      for (String p : status.getIgnoredNotInIndex()) {
        File f = new File(repo.getWorkTree(), p);
        if (fs.isFile(f) || fs.isSymLink(f))
          untrackedAndIgnoredFiles.add(p);
        else if (fs.isDirectory(f))
          untrackedAndIgnoredDirs.add(p);
      }

      Set<String> filtered = filterFolders(untrackedAndIgnoredFiles,
          untrackedAndIgnoredDirs);
View Full Code Here

    StoredConfig config = db.getConfig();
    config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_FILEMODE, true);
    config.save();

    FS executableFs = new FS() {

      public boolean supportsExecute() {
        return true;
      }

      public boolean setExecute(File f, boolean canExec) {
        return true;
      }

      public ProcessBuilder runInShell(String cmd, String[] args) {
        return null;
      }

      public boolean retryFailedLockFileCommit() {
        return false;
      }

      public FS newInstance() {
        return this;
      }

      protected File discoverGitPrefix() {
        return null;
      }

      public boolean canExecute(File f) {
        return true;
      }

      @Override
      public boolean isCaseSensitive() {
        return false;
      }
    };

    Git git = Git.open(db.getDirectory(), executableFs);
    String path = "a.txt";
    writeTrashFile(path, "content");
    git.add().addFilepattern(path).call();
    RevCommit commit1 = git.commit().setMessage("commit").call();
    TreeWalk walk = TreeWalk.forPath(db, path, commit1.getTree());
    assertNotNull(walk);
    assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));

    FS nonExecutableFs = new FS() {

      public boolean supportsExecute() {
        return false;
      }
View Full Code Here

  public static void checkoutEntry(final Repository repo, File f,
      DirCacheEntry entry, ObjectReader or) throws IOException {
    ObjectLoader ol = or.open(entry.getObjectId());
    File parentDir = f.getParentFile();
    parentDir.mkdirs();
    FS fs = repo.getFS();
    WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY);
    if (entry.getFileMode() == FileMode.SYMLINK
        && opt.getSymLinks() == SymLinks.TRUE) {
      byte[] bytes = ol.getBytes();
      String target = RawParseUtils.decode(bytes);
      fs.createSymLink(f, target);
      entry.setLength(bytes.length);
      entry.setLastModified(fs.lastModified(f));
    } else {
      File tmpFile = File.createTempFile(
          "._" + f.getName(), null, parentDir); //$NON-NLS-1$
      FileOutputStream rawChannel = new FileOutputStream(tmpFile);
      OutputStream channel;
      if (opt.getAutoCRLF() == AutoCRLF.TRUE)
        channel = new AutoCRLFOutputStream(rawChannel);
      else
        channel = rawChannel;
      try {
        ol.copyTo(channel);
      } finally {
        channel.close();
      }
      if (opt.isFileMode() && fs.supportsExecute()) {
        if (FileMode.EXECUTABLE_FILE.equals(entry.getRawMode())) {
          if (!fs.canExecute(tmpFile))
            fs.setExecute(tmpFile, true);
        } else {
          if (fs.canExecute(tmpFile))
            fs.setExecute(tmpFile, false);
        }
      }
      try {
        FileUtils.rename(tmpFile, f);
      } catch (IOException e) {
View Full Code Here

   * @throws IOException
   */
  public static long fsTick(File lastFile) throws InterruptedException,
      IOException {
    long sleepTime = 64;
    FS fs = FS.DETECTED;
    if (lastFile != null && !fs.exists(lastFile))
      throw new FileNotFoundException(lastFile.getPath());
    File tmp = File.createTempFile("FileTreeIteratorWithTimeControl", null);
    try {
      long startTime = (lastFile == null) ? fs.lastModified(tmp) : fs
          .lastModified(lastFile);
      long actTime = fs.lastModified(tmp);
      while (actTime <= startTime) {
        Thread.sleep(sleepTime);
        sleepTime *= 2;
        FileOutputStream fos = new FileOutputStream(tmp);
        fos.close();
        actTime = fs.lastModified(tmp);
      }
      return actTime;
    } finally {
      FileUtils.delete(tmp);
    }
View Full Code Here

    if (sock != null)
      return sock;

    final int tms = getTimeout() > 0 ? getTimeout() * 1000 : 0;

    final FS fs = local == null ? FS.detect() : local.getFS();

    sock = sch
        .getSession(uri, getCredentialsProvider(), fs, tms);
    return sock;
  }
View Full Code Here

    if (workTree == null)
      // TODO: This should be handled by WorkingTreeIterators which
      // support write operations
      throw new UnsupportedOperationException();

    FS fs = db.getFS();
    File of = new File(workTree, tw.getPathString());
    File parentFolder = of.getParentFile();
    if (!fs.exists(parentFolder))
      parentFolder.mkdirs();
    FileOutputStream fos = new FileOutputStream(of);
    try {
      new MergeFormatter().formatMerge(fos, result,
          Arrays.asList(commitNames), CHARACTER_ENCODING);
View Full Code Here

    StoredConfig config = db.getConfig();
    config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_FILEMODE, true);
    config.save();

    FS executableFs = new FS() {

      public boolean supportsExecute() {
        return true;
      }

      public boolean setExecute(File f, boolean canExec) {
        return true;
      }

      public ProcessBuilder runInShell(String cmd, String[] args) {
        return null;
      }

      public boolean retryFailedLockFileCommit() {
        return false;
      }

      public FS newInstance() {
        return this;
      }

      protected File discoverGitPrefix() {
        return null;
      }

      public boolean canExecute(File f) {
        return true;
      }

      @Override
      public boolean isCaseSensitive() {
        return true;
      }
    };

    Git git = Git.open(db.getDirectory(), executableFs);
    String path = "a.txt";
    writeTrashFile(path, "content");
    git.add().addFilepattern(path).call();
    RevCommit commit1 = git.commit().setMessage("commit").call();
    TreeWalk walk = TreeWalk.forPath(db, path, commit1.getTree());
    assertNotNull(walk);
    assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));

    FS nonExecutableFs = new FS() {

      public boolean supportsExecute() {
        return false;
      }
View Full Code Here

    // First commit - a.txt file
    git.add().addFilepattern("a.txt").call();
    git.commit().setMessage("commit1").setCommitter(committer).call();

    // pure mode change should be committable
    FS fs = db.getFS();
    fs.setExecute(file, true);
    git.add().addFilepattern("a.txt").call();
    git.commit().setMessage("mode change").setCommitter(committer).call();

    // pure mode change should be committable with -o option
    fs.setExecute(file, false);
    git.add().addFilepattern("a.txt").call();
    git.commit().setMessage("mode change").setCommitter(committer)
        .setOnly("a.txt").call();
  }
View Full Code Here

import org.junit.Test;

public class FileTreeIteratorJava7Test extends RepositoryTestCase {
  @Test
  public void testFileModeSymLinkIsNotATree() throws IOException {
    FS fs = db.getFS();
    // mål = target in swedish, just to get som unicode in here
    writeTrashFile("mål/data", "targetdata");
    fs.createSymLink(new File(trash, "länk"), "mål");
    FileTreeIterator fti = new FileTreeIterator(db);
    assertFalse(fti.eof());
    assertEquals("länk", fti.getEntryPathString());
    assertEquals(FileMode.SYMLINK, fti.getEntryFileMode());
    fti.next(1);
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.util.FS

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.