org.eclipse.jgit.lib.Repository.getFS()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(66)

本文整理了Java中org.eclipse.jgit.lib.Repository.getFS方法的一些代码示例,展示了Repository.getFS的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Repository.getFS方法的具体详情如下:
包路径:org.eclipse.jgit.lib.Repository
类名称:Repository
方法名:getFS

Repository.getFS介绍

[英]Get the used file system abstraction.
[中]获取使用过的文件系统抽象。

代码示例

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Spawn process
 *
 * @param cmd
 *            command
 * @return a {@link java.lang.Process} object.
 * @throws org.eclipse.jgit.errors.TransportException
 *             if any.
 */
protected Process spawn(String cmd)
    throws TransportException {
  try {
    String[] args = { "." }; //$NON-NLS-1$
    ProcessBuilder proc = local.getFS().runInShell(cmd, args);
    proc.directory(remoteGitDir);
    // Remove the same variables CGit does.
    Map<String, String> env = proc.environment();
    env.remove("GIT_ALTERNATE_OBJECT_DIRECTORIES"); //$NON-NLS-1$
    env.remove("GIT_CONFIG"); //$NON-NLS-1$
    env.remove("GIT_CONFIG_PARAMETERS"); //$NON-NLS-1$
    env.remove("GIT_DIR"); //$NON-NLS-1$
    env.remove("GIT_WORK_TREE"); //$NON-NLS-1$
    env.remove("GIT_GRAFT_FILE"); //$NON-NLS-1$
    env.remove("GIT_INDEX_FILE"); //$NON-NLS-1$
    env.remove("GIT_NO_REPLACE_OBJECTS"); //$NON-NLS-1$
    return proc.start();
  } catch (IOException err) {
    throw new TransportException(uri, err.getMessage(), err);
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

static boolean isCached(@NonNull Repository repo) {
  File gitDir = repo.getDirectory();
  if (gitDir == null) {
    return false;
  }
  FileKey key = new FileKey(gitDir, repo.getFS());
  return cache.cacheMap.get(key) == repo;
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Get submodule repository
 *
 * @param parent
 *            the {@link org.eclipse.jgit.lib.Repository}.
 * @param path
 *            submodule path
 * @return repository or null if repository doesn't exist
 * @throws java.io.IOException
 */
public static Repository getSubmoduleRepository(final Repository parent,
    final String path) throws IOException {
  return getSubmoduleRepository(parent.getWorkTree(), path,
      parent.getFS());
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Create a new in-core index representation and read an index from disk.
 * <p>
 * The new index will be read before it is returned to the caller. Read
 * failures are reported as exceptions and therefore prevent the method from
 * returning a partially populated index.
 *
 * @param repository
 *            repository containing the index to read
 * @return a cache representing the contents of the specified index file (if
 *         it exists) or an empty cache if the file does not exist.
 * @throws java.io.IOException
 *             the index file is present but could not be read.
 * @throws org.eclipse.jgit.errors.CorruptObjectException
 *             the index file is using a format or extension that this
 *             library does not support.
 */
public static DirCache read(Repository repository)
    throws CorruptObjectException, IOException {
  final DirCache c = read(repository.getIndexFile(), repository.getFS());
  c.repository = repository;
  return c;
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

private void checkoutGitlink(String path, DirCacheEntry entry)
    throws IOException {
  File gitlinkDir = new File(repo.getWorkTree(), path);
  FileUtils.mkdirs(gitlinkDir, true);
  FS fs = repo.getFS();
  entry.setLastModified(fs.lastModified(gitlinkDir));
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Create a new in-core index representation, lock it, and read from disk.
 * <p>
 * The new index will be locked and then read before it is returned to the
 * caller. Read failures are reported as exceptions and therefore prevent
 * the method from returning a partially populated index. On read failure,
 * the lock is released.
 *
 * @param repository
 *            repository containing the index to lock and read
 * @param indexChangedListener
 *            listener to be informed when DirCache is committed
 * @return a cache representing the contents of the specified index file (if
 *         it exists) or an empty cache if the file does not exist.
 * @throws java.io.IOException
 *             the index file is present but could not be read, or the lock
 *             could not be obtained.
 * @throws org.eclipse.jgit.errors.CorruptObjectException
 *             the index file is using a format or extension that this
 *             library does not support.
 * @since 2.0
 */
public static DirCache lock(final Repository repository,
    final IndexChangedListener indexChangedListener)
    throws CorruptObjectException, IOException {
  DirCache c = lock(repository.getIndexFile(), repository.getFS(),
      indexChangedListener);
  c.repository = repository;
  return c;
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

private Properties loadProperties() throws NotSupportedException {
  if (local.getDirectory() != null) {
    File propsFile = new File(local.getDirectory(), uri.getUser());
    if (propsFile.isFile())
      return loadPropertiesFile(propsFile);
  }
  File propsFile = new File(local.getFS().userHome(), uri.getUser());
  if (propsFile.isFile())
    return loadPropertiesFile(propsFile);
  Properties props = new Properties();
  String user = uri.getUser();
  String pass = uri.getPass();
  if (user != null && pass != null) {
      props.setProperty("accesskey", user); //$NON-NLS-1$
      props.setProperty("secretkey", pass); //$NON-NLS-1$
  } else
    throw new NotSupportedException(MessageFormat.format(
        JGitText.get().cannotReadFile, propsFile));
  return props;
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Load the attributes node
 *
 * @return the attributes node
 * @throws java.io.IOException
 */
public AttributesNode load() throws IOException {
  AttributesNode r = new AttributesNode();
  FS fs = repository.getFS();
  File attributes = fs.resolve(repository.getDirectory(),
      Constants.INFO_ATTRIBUTES);
  FileRepository.AttributesNodeProviderImpl.loadRulesFromFile(r, attributes);
  return r.getRules().isEmpty() ? null : r;
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

throws FileNotFoundException, IOException {
File workTree = nonNullRepo().getWorkTree();
FS fs = nonNullRepo().getFS();
File of = new File(workTree, tw.getPathString());
File parentFolder = of.getParentFile();

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

@Override
public Transport open(URIish uri, Repository local, String remoteName)
    throws NoRemoteRepositoryException {
  File localPath = local.isBare() ? local.getDirectory() : local.getWorkTree();
  File path = local.getFS().resolve(localPath, uri.getPath());
  // If the reference is to a local file, C Git behavior says
  // assume this is a bundle, since repositories are directories.
  if (path.isFile())
    return new TransportBundleFile(local, uri, path);
  File gitDir = RepositoryCache.FileKey.resolve(path, local.getFS());
  if (gitDir == null)
    throw new NoRemoteRepositoryException(uri, JGitText.get().notFound);
  return new TransportLocal(local, uri, gitDir);
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Create a new iterator to traverse the work tree and its children.
 *
 * @param repo
 *            the repository whose working tree will be scanned.
 * @param fileModeStrategy
 *            the strategy to use to determine the FileMode for a FileEntry;
 *            controls gitlinks etc.
 * @since 4.3
 */
public FileTreeIterator(Repository repo, FileModeStrategy fileModeStrategy) {
  this(repo.getWorkTree(), repo.getFS(),
      repo.getConfig().get(WorkingTreeOptions.KEY),
      fileModeStrategy);
  initRootIterator(repo);
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Remove a repository from the cache.
 * <p>
 * Removes a repository from the cache, if it is still registered here. This
 * method will not close the repository, only remove it from the cache. See
 * {@link org.eclipse.jgit.lib.RepositoryCache#close(Repository)} to remove
 * and close the repository.
 *
 * @param db
 *            repository to unregister.
 * @since 4.3
 */
public static void unregister(Repository db) {
  if (db.getDirectory() != null) {
    unregister(FileKey.exact(db.getDirectory(), db.getFS()));
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Register one repository into the cache.
 * <p>
 * During registration the cache automatically increments the usage counter,
 * permitting it to retain the reference. A
 * {@link org.eclipse.jgit.lib.RepositoryCache.FileKey} for the repository's
 * {@link org.eclipse.jgit.lib.Repository#getDirectory()} is used to index
 * the repository in the cache.
 * <p>
 * If another repository already is registered in the cache at this
 * location, the other instance is closed.
 *
 * @param db
 *            repository to register.
 */
public static void register(Repository db) {
  if (db.getDirectory() != null) {
    FileKey key = FileKey.exact(db.getDirectory(), db.getFS());
    cache.registerRepository(key, db);
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Close and remove a repository from the cache.
 * <p>
 * Removes a repository from the cache, if it is still registered here, and
 * close it.
 *
 * @param db
 *            repository to unregister.
 */
public static void close(@NonNull Repository db) {
  if (db.getDirectory() != null) {
    FileKey key = FileKey.exact(db.getDirectory(), db.getFS());
    cache.unregisterAndCloseRepository(key);
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Get the default SSH session
 *
 * @return a remote session
 * @throws org.eclipse.jgit.errors.TransportException
 *             in case of error with opening SSH session
 */
protected RemoteSession getSession() throws TransportException {
  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;
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
   * Load the attributes node
   *
   * @return the attributes node
   * @throws java.io.IOException
   */
  public AttributesNode load() throws IOException {
    AttributesNode r = new AttributesNode();

    FS fs = repository.getFS();
    String path = repository.getConfig().get(CoreConfig.KEY)
        .getAttributesFile();
    if (path != null) {
      File attributesFile;
      if (path.startsWith("~/")) { //$NON-NLS-1$
        attributesFile = fs.resolve(fs.userHome(),
            path.substring(2));
      } else {
        attributesFile = fs.resolve(null, path);
      }
      FileRepository.AttributesNodeProviderImpl.loadRulesFromFile(r, attributesFile);
    }
    return r.getRules().isEmpty() ? null : r;
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

private Repository openRepo() throws TransportException {
  try {
    return new RepositoryBuilder()
        .setFS(local != null ? local.getFS() : FS.DETECTED)
        .setGitDir(remoteGitDir).build();
  } catch (IOException err) {
    throw new TransportException(uri, JGitText.get().notAGitDirectory);
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Get submodule id using the repository at the location of the entry
 * relative to the directory.
 *
 * @param directory
 *            a {@link java.io.File} object.
 * @param e
 *            a {@link org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry}
 *            object.
 * @return non-null submodule id
 */
protected byte[] idSubmodule(File directory, Entry e) {
  try (Repository submoduleRepo = SubmoduleWalk.getSubmoduleRepository(
      directory, e.getName(),
      repository != null ? repository.getFS() : FS.DETECTED)) {
    if (submoduleRepo == null) {
      return zeroid;
    }
    ObjectId head = submoduleRepo.resolve(Constants.HEAD);
    if (head == null) {
      return zeroid;
    }
    byte[] id = new byte[Constants.OBJECT_ID_LENGTH];
    head.copyRawTo(id, 0);
    return id;
  } catch (IOException exception) {
    return zeroid;
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

@Override
IgnoreNode load() throws IOException {
  IgnoreNode r;
  if (entry != null) {
    r = super.load();
    if (r == null)
      r = new IgnoreNode();
  } else {
    r = new IgnoreNode();
  }
  FS fs = repository.getFS();
  String path = repository.getConfig().get(CoreConfig.KEY)
      .getExcludesFile();
  if (path != null) {
    File excludesfile;
    if (path.startsWith("~/")) //$NON-NLS-1$
      excludesfile = fs.resolve(fs.userHome(), path.substring(2));
    else
      excludesfile = fs.resolve(null, path);
    loadRulesFromFile(r, excludesfile);
  }
  File exclude = fs.resolve(repository.getDirectory(),
      Constants.INFO_EXCLUDE);
  loadRulesFromFile(r, exclude);
  return r.getRules().isEmpty() ? null : r;
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

private RevCommit checkoutCurrentHead() throws IOException, NoHeadException {
  ObjectId headTree = repo.resolve(Constants.HEAD + "^{tree}"); //$NON-NLS-1$
  if (headTree == null)
    throw new NoHeadException(
        JGitText.get().cannotRebaseWithoutCurrentHead);
  DirCache dc = repo.lockDirCache();
  try {
    DirCacheCheckout dco = new DirCacheCheckout(repo, dc, headTree);
    dco.setFailOnConflict(false);
    dco.setProgressMonitor(monitor);
    boolean needsDeleteFiles = dco.checkout();
    if (needsDeleteFiles) {
      List<String> fileList = dco.getToBeDeleted();
      for (String filePath : fileList) {
        File fileToDelete = new File(repo.getWorkTree(), filePath);
        if (repo.getFS().exists(fileToDelete))
          FileUtils.delete(fileToDelete, FileUtils.RECURSIVE
              | FileUtils.RETRY);
      }
    }
  } finally {
    dc.unlock();
  }
  try (RevWalk rw = new RevWalk(repo)) {
    RevCommit commit = rw.parseCommit(repo.resolve(Constants.HEAD));
    return commit;
  }
}

相关文章

微信公众号

最新文章

更多

Repository类方法