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

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

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

Ref.getObjectId介绍

[英]Cached value of this ref.
[中]此引用的缓存值。

代码示例

代码示例来源:origin: gocd/gocd

public Long commitCountOnMaster() throws GitAPIException, IncorrectObjectTypeException, MissingObjectException {
    // not inside a doLocked/synchronized block because we don't want to block the server status service.
    // we do a `git branch` because we switch branches as part of normal git operations,
    // and we don't care about number of commits on those branches.
    List<Ref> branches = git.branchList().call();
    for (Ref branch : branches) {
      if (branch.getName().equals("refs/heads/master")) {
        Iterable<RevCommit> commits = git.log().add(branch.getObjectId()).call();
        long count = 0;
        for (RevCommit commit : commits) {
          count++;
        }
        return count;
      }
    }
    return Long.valueOf(-1);
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-config

private Ref resetHard(Git git, String label, String ref) {
  ResetCommand reset = git.reset();
  reset.setRef(ref);
  reset.setMode(ResetType.HARD);
  try {
    Ref resetRef = reset.call();
    if (resetRef != null) {
      this.logger.info(
          "Reset label " + label + " to version " + resetRef.getObjectId());
    }
    return resetRef;
  }
  catch (Exception ex) {
    String message = "Could not reset to remote for " + label + " (current ref="
        + ref + "), remote: " + git.getRepository().getConfig()
            .getString("remote", "origin", "url");
    warn(message, ex);
    return null;
  }
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldCreateBranchForARevCommit() throws Exception {
  configRepo.checkin(goConfigRevision("something", "md5-1"));
  RevCommit revCommit = configRepo.getCurrentRevCommit();
  configRepo.createBranch("branch1", revCommit);
  Ref branch = getBranch("branch1");
  assertThat(branch, is(notNullValue()));
  assertThat(branch.getObjectId(), is(revCommit.getId()));
}

代码示例来源:origin: jphp-group/jphp

public static ArrayMemory valueOf(Ref ref) {
  ArrayMemory memory = new ArrayMemory();
  memory.refOfIndex("name").assign(ref.getName());
  memory.refOfIndex("peeled").assign(ref.isPeeled());
  memory.refOfIndex("symbolic").assign(ref.isSymbolic());
  memory.refOfIndex("objectId").assign(valueOf(ref.getObjectId()));
  memory.refOfIndex("storage").assign(valueOf(ref.getStorage()));
  return memory;
}

代码示例来源:origin: spring-cloud/spring-cloud-config

return git.getRepository().findRef("HEAD").getObjectId().getName();

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

private static ObjectId idOf(@Nullable Ref src) {
  return src != null && src.getObjectId() != null
      ? src.getObjectId()
      : ObjectId.zeroId();
}

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

private static ObjectId toId(Ref ref) {
  if (ref != null) {
    ObjectId id = ref.getObjectId();
    if (id != null) {
      return id;
    }
  }
  return ObjectId.zeroId();
}

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

private RevCommit parseCommit(Repository clonedRepo, Ref ref)
    throws MissingObjectException, IncorrectObjectTypeException,
    IOException {
  final RevCommit commit;
  try (RevWalk rw = new RevWalk(clonedRepo)) {
    commit = rw.parseCommit(ref.getObjectId());
  }
  return commit;
}

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

@Override
  public void apply(DirCacheEntry ent) {
    checkRef(ent, cmd);
    ent.setFileMode(GITLINK);
    ent.setObjectId(newRef.getObjectId());
  }
}.setReplace(false));

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

private Ref getHead() throws IOException, RefNotFoundException {
  Ref head = repo.exactRef(Constants.HEAD);
  if (head == null || head.getObjectId() == null)
    throw new RefNotFoundException(MessageFormat.format(
        JGitText.get().refNotResolved, Constants.HEAD));
  return head;
}

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

private static boolean equals(Ref r1, Ref r2) {
  if (r1 == null || r2 == null) {
    return false;
  }
  if (r1.isSymbolic()) {
    return r2.isSymbolic() && r1.getTarget().getName()
        .equals(r2.getTarget().getName());
  }
  return !r2.isSymbolic()
      && Objects.equals(r1.getObjectId(), r2.getObjectId());
}

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

public static void main(String[] args) throws IOException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
      // the Ref holds an ObjectId for any type of object (tree, commit, blob, tree)
      Ref head = repository.exactRef("refs/heads/master");
      System.out.println("Ref of refs/heads/master: " + head + ": " + head.getName() + " - " + head.getObjectId().getName());
    }
  }
}

代码示例来源: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

@NonNull
  static ObjectId getId(@Nullable Ref ref) {
    if (ref != null) {
      ObjectId id = ref.getObjectId();
      if (id != null) {
        return id;
      }
    }
    return ObjectId.zeroId();
  }
}

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

@Override
int valueType() {
  if (ref.isSymbolic()) {
    return VALUE_SYMREF;
  } else if (ref.getStorage() == NEW && ref.getObjectId() == null) {
    return VALUE_NONE;
  } else if (ref.getPeeledObjectId() != null) {
    return VALUE_2ID;
  } else {
    return VALUE_1ID;
  }
}

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

private String getShortBranchName(Ref headRef) {
  if (headRef.isSymbolic()) {
    return Repository.shortenRefName(headRef.getTarget().getName());
  }
  // Detached HEAD. Every non-symbolic ref in the ref database has an
  // object id, so this cannot be null.
  ObjectId id = headRef.getObjectId();
  if (id == null) {
    throw new NullPointerException();
  }
  return id.getName();
}

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

private static String getHeadName(Ref head) {
  String headName;
  if (head.isSymbolic()) {
    headName = head.getTarget().getName();
  } else {
    ObjectId headId = head.getObjectId();
    // the callers are checking this already
    assert headId != null;
    headName = headId.getName();
  }
  return headName;
}

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

@Override
public ObjectId sha1(String uri, String ref) throws GitAPIException {
  Map<String, Ref> map = Git
      .lsRemoteRepository()
      .setRemote(uri)
      .callAsMap();
  Ref r = RefDatabase.findRef(map, ref);
  return r != null ? r.getObjectId() : null;
}

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

private RefUpdate createRefUpdate(Ref stashRef) throws IOException {
  RefUpdate update = repo.updateRef(R_STASH);
  update.disableRefLog();
  update.setExpectedOldObjectId(stashRef.getObjectId());
  update.setForceUpdate(true);
  return update;
}

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

private void markRefsAdvertised() {
  for (Ref r : getRefs()) {
    markAdvertised(r.getObjectId());
    if (r.getPeeledObjectId() != null)
      markAdvertised(r.getPeeledObjectId());
  }
}

相关文章