Package org.eclipse.jgit.treewalk

Examples of org.eclipse.jgit.treewalk.WorkingTreeOptions


  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();
    File tmpFile = File.createTempFile("._" + f.getName(), null, parentDir);
    WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY);
    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();
    }
    FS fs = repo.getFS();
    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);
      }
    }
    if (!tmpFile.renameTo(f)) {
      // tried to rename which failed. Let' delete the target file and try
      // again
      FileUtils.delete(f);
      if (!tmpFile.renameTo(f)) {
        throw new IOException(MessageFormat.format(
            JGitText.get().couldNotWriteFile, tmpFile.getPath(),
            f.getPath()));
      }
    }
    entry.setLastModified(f.lastModified());
    if (opt.getAutoCRLF() != AutoCRLF.FALSE)
      entry.setLength(f.length()); // AutoCRLF wants on-disk-size
    else
      entry.setLength((int) ol.getSize());
  }
View Full Code Here


      ol.copyTo(channel);
    } finally {
      channel.close();
    }
    FS fs = repo.getFS();
    WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY);
    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))
View Full Code Here

      ol.copyTo(channel);
    } finally {
      channel.close();
    }
    FS fs = repo.getFS();
    WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY);
    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))
View Full Code Here

      ol.copyTo(channel);
    } finally {
      channel.close();
    }
    FS fs = repo.getFS();
    WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY);
    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))
View Full Code Here

      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) {
        throw new IOException(MessageFormat.format(
            JGitText.get().renameFileFailed, tmpFile.getPath(),
            f.getPath()));
      }
    }
    entry.setLastModified(f.lastModified());
    if (opt.getAutoCRLF() != AutoCRLF.FALSE)
      entry.setLength(f.length()); // AutoCRLF wants on-disk-size
    else
      entry.setLength((int) ol.getSize());
  }
View Full Code Here

  private RawText getRawText(File inTree) throws IOException,
      FileNotFoundException {
    RawText rawText;

    WorkingTreeOptions workingTreeOptions = getRepository().getConfig()
        .get(WorkingTreeOptions.KEY);
    AutoCRLF autoCRLF = workingTreeOptions.getAutoCRLF();
    switch (autoCRLF) {
    case FALSE:
    case INPUT:
      // Git used the repo format on checkout, but other tools
      // may change the format to CRLF. We ignore that here.
View Full Code Here

      ol.copyTo(channel);
    } finally {
      channel.close();
    }
    FS fs = repo.getFS();
    WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY);
    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))
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();
    File tmpFile = File.createTempFile("._" + f.getName(), null, parentDir);
    WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY);
    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();
    }
    FS fs = repo.getFS();
    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);
      }
    }
    if (!tmpFile.renameTo(f)) {
      // tried to rename which failed. Let' delete the target file and try
      // again
      FileUtils.delete(f);
      if (!tmpFile.renameTo(f)) {
        throw new IOException(MessageFormat.format(
            JGitText.get().couldNotWriteFile, tmpFile.getPath(),
            f.getPath()));
      }
    }
    entry.setLastModified(f.lastModified());
    if (opt.getAutoCRLF() != AutoCRLF.FALSE)
      entry.setLength(f.length()); // AutoCRLF wants on-disk-size
    else
      entry.setLength((int) ol.getSize());
  }
View Full Code Here

      if (newContent.length == 0) {
        editor.add(new DirCacheEditor.DeletePath(gitPath));
      } else {
        int length;
        byte[] content;
        WorkingTreeOptions workingTreeOptions = repository.getConfig()
            .get(WorkingTreeOptions.KEY);
        AutoCRLF autoCRLF = workingTreeOptions.getAutoCRLF();
        switch (autoCRLF) {
        case FALSE:
          content = newContent;
          length = newContent.length;
          break;
View Full Code Here

      IncorrectObjectTypeException {
    if (blobId == null)
      return new ByteArrayInputStream(new byte[0]);

    try {
      WorkingTreeOptions workingTreeOptions = db.getConfig().get(WorkingTreeOptions.KEY);
      switch (workingTreeOptions.getAutoCRLF()) {
      case INPUT:
        // When autocrlf == input the working tree could be either CRLF or LF, i.e. the comparison
        // itself should ignore line endings.
      case FALSE:
        return db.open(blobId, Constants.OBJ_BLOB).openStream();
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.treewalk.WorkingTreeOptions

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.