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

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

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

Repository.getRefDatabase介绍

[英]Get the reference database which stores the reference namespace.
[中]获取存储引用命名空间的引用数据库。

代码示例

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

/**
 * Constructor for StashDropCommand.
 *
 * @param repo
 *            a {@link org.eclipse.jgit.lib.Repository} object.
 */
public StashDropCommand(Repository repo) {
  super(repo);
  if (!(repo.getRefDatabase() instanceof RefDirectory)) {
    throw new UnsupportedOperationException(
        JGitText.get().stashDropNotSupported);
  }
}

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

/**
 * Get mutable map of all known refs, including symrefs like HEAD that may
 * not point to any object yet.
 *
 * @return mutable map of all known refs (heads, tags, remotes).
 * @deprecated use {@code getRefDatabase().getRefs()} instead.
 */
@Deprecated
@NonNull
public Map<String, Ref> getAllRefs() {
  try {
    return getRefDatabase().getRefs(RefDatabase.ALL);
  } catch (IOException e) {
    return new HashMap<>();
  }
}

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

/**
 * Get mutable map of all tags
 *
 * @return mutable map of all tags; key is short tag name ("v1.0") and value
 *         of the entry contains the ref with the full tag name
 *         ("refs/tags/v1.0").
 * @deprecated use {@code getRefDatabase().getRefsByPrefix(R_TAGS)} instead
 */
@Deprecated
@NonNull
public Map<String, Ref> getTags() {
  try {
    return getRefDatabase().getRefs(Constants.R_TAGS);
  } catch (IOException e) {
    return new HashMap<>();
  }
}

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

private void addPrefix(String prefix, Map<ObjectId, String> nonCommits,
    FIFORevQueue pending) throws IOException {
  for (Ref ref : repo.getRefDatabase().getRefsByPrefix(prefix))
    addRef(ref, nonCommits, pending);
}

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

@Override
  public void checkWants(UploadPack up, List<ObjectId> wants)
      throws PackProtocolException, IOException {
    checkNotAdvertisedWants(up, wants,
        refIdSet(up.getRepository().getRefDatabase().getRefs()));
  }
}

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

private Map<String, Ref> getAdvertisedOrDefaultRefs() throws IOException {
  if (refs != null) {
    return refs;
  }
  if (!advertiseRefsHookCalled) {
    advertiseRefsHook.advertiseRefs(this);
    advertiseRefsHookCalled = true;
  }
  if (refs == null) {
    // Fall back to all refs.
    setAdvertisedRefs(
        db.getRefDatabase().getRefs().stream()
          .collect(toMap(Ref::getName, identity())));
  }
  return refs;
}

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

/**
 * Create a command to rename a ref in this repository
 *
 * @param fromRef
 *            name of ref to rename from
 * @param toRef
 *            name of ref to rename to
 * @return an update command that knows how to rename a branch to another.
 * @throws java.io.IOException
 *             the rename could not be performed.
 */
@NonNull
public RefRename renameRef(String fromRef, String toRef) throws IOException {
  return getRefDatabase().newRename(fromRef, toRef);
}

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

/**
 * Get a ref by name.
 *
 * @param name
 *            the name of the ref to lookup. Must not be a short-hand
 *            form; e.g., "master" is not automatically expanded to
 *            "refs/heads/master".
 * @return the Ref with the given name, or {@code null} if it does not exist
 * @throws java.io.IOException
 * @since 4.2
 */
@Nullable
public final Ref exactRef(String name) throws IOException {
  return getRefDatabase().exactRef(name);
}

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

/**
 * Search for a ref by (possibly abbreviated) name.
 *
 * @param name
 *            the name of the ref to lookup. May be a short-hand form, e.g.
 *            "master" which is is automatically expanded to
 *            "refs/heads/master" if "refs/heads/master" already exists.
 * @return the Ref with the given name, or {@code null} if it does not exist
 * @throws java.io.IOException
 * @since 4.2
 */
@Nullable
public final Ref findRef(String name) throws IOException {
  return getRefDatabase().getRef(name);
}

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

/**
 * Create a command to update, create or delete a ref in this repository.
 *
 * @param ref
 *            name of the ref the caller wants to modify.
 * @param detach
 *            true to create a detached head
 * @return an update command. The caller must finish populating this command
 *         and then invoke one of the update methods to actually make a
 *         change.
 * @throws java.io.IOException
 *             a symbolic ref was passed in and could not be resolved back
 *             to the base ref, as the symbolic ref could not be read.
 */
@NonNull
public RefUpdate updateRef(String ref, boolean detach) throws IOException {
  return getRefDatabase().newUpdate(ref, detach);
}

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

private static Collection<RefSpec> expandPushWildcardsFor(
    final Repository db, final Collection<RefSpec> specs)
    throws IOException {
  final List<Ref> localRefs = db.getRefDatabase().getRefs();
  final Collection<RefSpec> procRefs = new LinkedHashSet<>();
  for (RefSpec spec : specs) {
    if (spec.isWildcard()) {
      for (Ref localRef : localRefs) {
        if (spec.matchSource(localRef))
          procRefs.add(spec.expandFromSource(localRef));
      }
    } else {
      procRefs.add(spec);
    }
  }
  return procRefs;
}

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

private Map<String, Ref> localRefs() throws TransportException {
  if (localRefs == null) {
    try {
      localRefs = transport.local.getRefDatabase()
          .getRefs(RefDatabase.ALL);
    } catch (IOException err) {
      throw new TransportException(JGitText.get().cannotListRefs, err);
    }
  }
  return localRefs;
}

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

private ObjectId getObjectIdFromRef(Ref r) throws JGitInternalException {
  try {
    ObjectId key = repo.getRefDatabase().peel(r).getPeeledObjectId();
    if (key == null) {
      key = r.getObjectId();
    }
    return key;
  } catch (IOException e) {
    throw new JGitInternalException(e.getMessage(), e);
  }
}

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

/**
 * Invoked when the use count drops to zero during {@link #close()}.
 * <p>
 * The default implementation closes the object and ref databases.
 */
protected void doClose() {
  getObjectDatabase().close();
  getRefDatabase().close();
}

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

@Override
  public void checkWants(UploadPack up, List<ObjectId> wants)
      throws PackProtocolException, IOException {
    if (!up.isBiDirectionalPipe())
      new ReachableCommitTipRequestValidator().checkWants(up, wants);
    else if (!wants.isEmpty()) {
      Set<ObjectId> refIds =
          refIdSet(up.getRepository().getRefDatabase().getRefs());
      for (ObjectId obj : wants) {
        if (!refIds.contains(obj))
          throw new WantNotValidException(obj);
      }
    }
  }
}

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

void load() throws IOException {
  close();
  reader = db.newObjectReader();
  Ref ref = db.getRefDatabase().exactRef(REF_NAME);
  if (ref == null) {
    // No ref, same as empty.
    return;
  }
  try (RevWalk rw = new RevWalk(reader)) {
    commit = rw.parseCommit(ref.getObjectId());
  }
}

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

@Nullable
private ObjectId resolveSimple(String revstr) throws IOException {
  if (ObjectId.isId(revstr))
    return ObjectId.fromString(revstr);
  if (Repository.isValidRefName("x/" + revstr)) { //$NON-NLS-1$
    Ref r = getRefDatabase().getRef(revstr);
    if (r != null)
      return r.getObjectId();
  }
  if (AbbreviatedObjectId.isId(revstr))
    return resolveAbbreviation(revstr);
  int dashg = revstr.indexOf("-g"); //$NON-NLS-1$
  if ((dashg + 5) < revstr.length() && 0 <= dashg
      && isHex(revstr.charAt(dashg + 2))
      && isHex(revstr.charAt(dashg + 3))
      && isAllHex(revstr, dashg + 4)) {
    // Possibly output from git describe?
    String s = revstr.substring(dashg + 2);
    if (AbbreviatedObjectId.isId(s))
      return resolveAbbreviation(s);
  }
  return null;
}

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

private void markLocalRefsComplete(Set<ObjectId> have) throws TransportException {
  List<Ref> refs;
  try {
    refs = local.getRefDatabase().getRefs();
  } catch (IOException e) {
    throw new TransportException(e.getMessage(), e);
  }
  for (Ref r : refs) {
    try {
      markLocalObjComplete(revWalk.parseAny(r.getObjectId()));
    } catch (IOException readError) {
      throw new TransportException(MessageFormat.format(JGitText.get().localRefIsMissingObjects, r.getName()), readError);
    }
  }
  for (ObjectId id : have) {
    try {
      markLocalObjComplete(revWalk.parseAny(id));
    } catch (IOException readError) {
      throw new TransportException(MessageFormat.format(JGitText.get().transportExceptionMissingAssumed, id.name()), readError);
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      try (Git git = new Git(repository)) {
        List<Ref> call = git.tagList().call();
        for (Ref ref : call) {
          System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());

          // fetch all commits for this tag
          LogCommand log = git.log();

          Ref peeledRef = repository.getRefDatabase().peel(ref);
          if(peeledRef.getPeeledObjectId() != null) {
            log.add(peeledRef.getPeeledObjectId());
          } else {
            log.add(ref.getObjectId());
          }

          Iterable<RevCommit> logs = log.call();
          for (RevCommit rev : logs) {
            System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
          }
        }
      }
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      try (Git git = new Git(repository)) {
        List<Ref> call = git.tagList().call();
        for (Ref ref : call) {
          System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());

          // fetch all commits for this tag
          LogCommand log = git.log();

          Ref peeledRef = repository.getRefDatabase().peel(ref);
          if(peeledRef.getPeeledObjectId() != null) {
            log.add(peeledRef.getPeeledObjectId());
          } else {
            log.add(ref.getObjectId());
          }

          Iterable<RevCommit> logs = log.call();
          for (RevCommit rev : logs) {
            System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
          }
        }
      }
    }
  }
}

相关文章

Repository类方法