Java 类org.eclipse.jgit.lib.AbbreviatedObjectId 实例源码

项目:neembuu-uploader    文件:UpdaterGenerator.java   
private void checkDiffEmpty(List<DiffEntry> diffs){
    if (diffs.isEmpty()) {
        System.out.println("No diff");
    } else {
        System.out.println("Check if there are plugins to update");
        for (DiffEntry entry : diffs) {
            String editFilePath = entry.getPath(DiffEntry.Side.NEW);
            if (editFilePath.contains("neembuu-uploader-uploaders/src/neembuu/uploader/uploaders")) {
                AbbreviatedObjectId newId = entry.getNewId();
                String sha = newId.name();
                pluginsToUpdate.add(new PluginToUpdate(new File(gitDirectory, editFilePath), sha));
                System.out.println(sha + " -> " + editFilePath);
            }
        }
    }
}
项目:github-merge    文件:GitUtil.java   
public static void updateTodoLog(NotificationService notification, PullRequestKey request, Map<AbbreviatedObjectId, Commit> mappedCommits, List<RebaseTodoLine> steps) {
    for(int i = 0; i < steps.size(); i++) {
        RebaseTodoLine step = steps.get(i);
        if(!mappedCommits.containsKey(step.getCommit())) {
            notification.sendMessage(request, "Perform " + step.getCommit().toString() + " Action[remove]");
            steps.remove(i);
            i--;
            continue;
        }
        Commit commit = mappedCommits.get(step.getCommit());
        if(commit.getState() == State.DELETE) {
            notification.sendMessage(request, "Perform " + step.getCommit().toString() + " " + " Action[remove]");
            steps.remove(i);
            i--;
            continue;
        }
        try {
            step.setAction(Action.parse(commit.getState().name().toLowerCase()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        notification.sendMessage(request, "Perform " + step.getCommit().toString() + " " + step.getAction());
    }
}
项目:ninja_chic-    文件:LineContextDiffer.java   
private byte[] open(ObjectReader reader, FileMode mode,
                    AbbreviatedObjectId id) throws IOException {
    if (mode == FileMode.MISSING)
        return new byte[] { };

    if (mode.getObjectType() != Constants.OBJ_BLOB)
        return new byte[] { };

    if (!id.isComplete()) {
        Collection<ObjectId> ids = reader.resolve(id);
        if (ids.size() == 1)
            id = AbbreviatedObjectId.fromObjectId(ids.iterator().next());
        else if (ids.size() == 0)
            throw new MissingObjectException(id, Constants.OBJ_BLOB);
        else
            throw new AmbiguousObjectException(id, ids);
    }

    ObjectLoader ldr = reader.open(id.toObjectId());
    return ldr.getCachedBytes(bigFileThreshold);
}
项目:gitiles    文件:LogServlet.java   
private static Optional<ObjectId> getStart(ListMultimap<String, String> params,
    ObjectReader reader) throws IOException {
  List<String> values = params.get(START_PARAM);
  switch (values.size()) {
    case 0:
      return Optional.absent();
    case 1:
      Collection<ObjectId> ids = reader.resolve(AbbreviatedObjectId.fromString(values.get(0)));
      if (ids.size() != 1) {
        return null;
      }
      return Optional.of(Iterables.getOnlyElement(ids));
    default:
      return null;
  }
}
项目:WebIDE-Backend    文件:RebaseTodoUtils.java   
public static List<RebaseTodoLine> parseLines(List<RebaseResponse.RebaseTodoLine> lines) {
    List<RebaseTodoLine> rebaseTodoLines = new ArrayList<>();

    for (RebaseResponse.RebaseTodoLine line : lines) {
        RebaseTodoLine rebaseTodoLine = new RebaseTodoLine(
                RebaseTodoLine.Action.valueOf(line.getAction().name()),
                AbbreviatedObjectId.fromString(line.getCommit()),
                line.getShortMessage());

        rebaseTodoLines.add(rebaseTodoLine);
    }

    return rebaseTodoLines;
}
项目:piper    文件:JGitTemplate.java   
private IdentifiableResource readBlob (Repository aRepo, String aPath, String aBlobId) throws Exception {
  try (ObjectReader reader = aRepo.newObjectReader()) {
    if(aBlobId.equals(LATEST)) {
      List<IdentifiableResource> headFiles = getHeadFiles(aRepo, aPath);
      Assert.notEmpty(headFiles,"could not find: " + aPath + ":" + aBlobId);
      return headFiles.get(0);
    }
    ObjectId objectId = aRepo.resolve(aBlobId);
    Assert.notNull(objectId,"could not find: " + aPath + ":" + aBlobId);
    byte[] data = reader.open(objectId).getBytes();
    AbbreviatedObjectId abbreviated = reader.abbreviate(objectId);
    return new IdentifiableResource(aPath+":"+abbreviated.name(), new ByteArrayResource(data));
  }
}
项目:GitDirStat    文件:RevstrCommitSelection.java   
@Override
public boolean accept(RevCommit cmit) {
    ObjectId id = cmit.getId();
    AbbreviatedObjectId abbreviatedId = id.abbreviate(7);
    return revStrings.contains(abbreviatedId.name())
            || revStrings.contains(id.name());
}
项目:gerrit    文件:InMemoryInserter.java   
@Override
public Collection<ObjectId> resolve(AbbreviatedObjectId id) throws IOException {
  Set<ObjectId> result = new HashSet<>();
  for (ObjectId insId : inserted.keySet()) {
    if (id.prefixCompare(insId) == 0) {
      result.add(insId);
    }
  }
  result.addAll(reader.resolve(id));
  return result;
}
项目:GitDirStat    文件:RevstrCommitSelection.java   
@Override
public boolean accept(RevCommit cmit) {
    ObjectId id = cmit.getId();
    AbbreviatedObjectId abbreviatedId = id.abbreviate(7);
    return revStrings.contains(abbreviatedId.name())
            || revStrings.contains(id.name());
}
项目:github-merge    文件:GitUtil.java   
public static Map<AbbreviatedObjectId, Commit> map(List<Commit> commits) {
    Map<AbbreviatedObjectId, Commit> mapped = new HashMap<>();
    for(Commit commit : commits) {
        mapped.put(AbbreviatedObjectId.fromString(commit.getId().substring(0, 7)), commit);
    }
    return mapped;
}
项目:ninja_chic-    文件:LineContextDiffer.java   
private String format(AbbreviatedObjectId id) {
    if (id.isComplete()) {
        try {
            id = objectReader.abbreviate(id.toObjectId(), abbreviationLength);
        } catch (IOException cannotAbbreviate) {
            // Ignore this. We'll report the full identity.
        } finally {
            // reader.release();
        }
    }
    return id.name();
}
项目:ninja_chic-    文件:BlobViewerActivity.java   
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            String revision = getIntent().getStringExtra(REVISION);

            Intent intent = AbbreviatedObjectId.isId(revision)?commitViewIntentFor(getIntent().getExtras()).toIntent():branchViewerIntentFor(gitdir(), revision);
            return homewardsWith(this, intent);
    }
    return super.onOptionsItemSelected(item);
}
项目:cdversion-maven-extension    文件:GitRevisionGeneratorTest.java   
@Test
public void testInit_gitLogApiException()
        throws RevisionGeneratorException,
        GitAPIException, 
        IOException {

    String branch = "master";
    String hash = UUID.randomUUID().toString().replaceAll("-", "");
    String abbreviatedHash = hash.substring(0, 5);
    AbbreviatedObjectId abbreviatedObjectId = AbbreviatedObjectId.fromString(abbreviatedHash);

    Repository repo = mock(Repository.class);
    Ref headRef = mock(Ref.class);
    ObjectId headObjectId = mock(ObjectId.class);
    LogCommand logCmd = mock(LogCommand.class);

    GitAPIException exception = new NoHeadException("Dummy Git API Exception");

    when(git.getRepository()).thenReturn(repo);
    when(repo.isBare()).thenReturn(Boolean.FALSE);
    when(repo.getBranch()).thenReturn(branch);
    when(repo.getRef(eq("HEAD"))).thenReturn(headRef);
    when(headRef.getObjectId()).thenReturn(headObjectId);
    when(headObjectId.abbreviate(eq(5))).thenReturn(abbreviatedObjectId);
    when(git.log()).thenReturn(logCmd);
    when(logCmd.setMaxCount(1)).thenReturn(logCmd);
    when(logCmd.call()).thenThrow(exception);

    exceptions.expect(RevisionGeneratorException.class);
    exceptions.expectMessage("Issue getting Git CommitTime");
    exceptions.expectCause(IsInstanceOf.any(GitAPIException.class));

    try {
        item.init(git, logger);
    } finally {
        verify(git).getRepository();
        verify(git).log();
        verify(repo).isBare();
        verify(repo).getRef(eq("HEAD"));
        verify(repo).getBranch();
        verify(headRef, times(2)).getObjectId();
        verify(headObjectId).abbreviate(eq(5));
        verify(logCmd).setMaxCount(eq(1));
        verify(logCmd).call();
        verifyNoMoreInteractions(git);
        verifyNoMoreInteractions(repo);
        verifyNoMoreInteractions(headRef);
        verifyNoMoreInteractions(headObjectId);
        verifyNoMoreInteractions(logCmd);
        verifyZeroInteractions(logger);
    }
}
项目:cdversion-maven-extension    文件:GitRevisionGeneratorTest.java   
@Test
public void testInit_gitStatusApiException()
        throws RevisionGeneratorException,
        GitAPIException, 
        IOException {

    String branch = "master";
    String hash = UUID.randomUUID().toString().replaceAll("-", "")+UUID.randomUUID().toString().replaceAll("-", "").substring(0,8);
    String abbreviatedHash = hash.substring(0, 5);
    AbbreviatedObjectId abbreviatedObjectId = AbbreviatedObjectId.fromString(abbreviatedHash);
    int commitTime = (int) (System.currentTimeMillis()/1000);

    RevCommit headCommit = createRevCommit(hash, commitTime);


    Repository repo = mock(Repository.class);
    Ref headRef = mock(Ref.class);
    ObjectId headObjectId = mock(ObjectId.class);
    LogCommand logCmd = mock(LogCommand.class);
    StatusCommand statusCmd = mock(StatusCommand.class);

    GitAPIException exception = new NoHeadException("Dummy Git API Exception");

    when(git.getRepository()).thenReturn(repo);
    when(repo.isBare()).thenReturn(Boolean.FALSE);
    when(repo.getBranch()).thenReturn(branch);
    when(repo.getRef(eq("HEAD"))).thenReturn(headRef);
    when(headRef.getObjectId()).thenReturn(headObjectId);
    when(headObjectId.abbreviate(eq(5))).thenReturn(abbreviatedObjectId);
    when(git.log()).thenReturn(logCmd);
    when(logCmd.setMaxCount(1)).thenReturn(logCmd);
    when(logCmd.call()).thenReturn(Arrays.asList(headCommit));
    when(git.status()).thenReturn(statusCmd);
    when(statusCmd.call()).thenThrow(exception);

    exceptions.expect(RevisionGeneratorException.class);
    exceptions.expectMessage("Issue getting Git Status");
    exceptions.expectCause(IsInstanceOf.any(GitAPIException.class));

    try {
        item.init(git, logger);
    } finally {
        verify(git).getRepository();
        verify(git).log();
        verify(repo).isBare();
        verify(repo).getRef(eq("HEAD"));
        verify(repo).getBranch();
        verify(headRef, times(2)).getObjectId();
        verify(headObjectId).abbreviate(eq(5));
        verify(logCmd).setMaxCount(eq(1));
        verify(logCmd).call();
        verify(git).status();
        verify(statusCmd).call();
        verifyNoMoreInteractions(git);
        verifyNoMoreInteractions(repo);
        verifyNoMoreInteractions(headRef);
        verifyNoMoreInteractions(headObjectId);
        verifyNoMoreInteractions(logCmd);
        verifyNoMoreInteractions(statusCmd);
        verifyZeroInteractions(logger);
    }
}
项目:GitDirStat    文件:IndexUpdate.java   
@Override
public Collection<ObjectId> resolve(AbbreviatedObjectId id)
        throws IOException {
    return delegate.resolve(id);
}
项目:gerrit    文件:GetPatch.java   
private static String fileName(RevWalk rw, RevCommit commit) throws IOException {
  AbbreviatedObjectId id = rw.getObjectReader().abbreviate(commit, 7);
  return id.name() + ".diff";
}
项目:git-webapp    文件:GitOperation.java   
private Optional<FileContent> getFileContent(Git git, String path, AbbreviatedObjectId abbreviatedObjectId) {
  if (abbreviatedObjectId == null || path.equals("/dev/null")) {
    return Optional.empty();
  }
  return Optional.of(getFileContent(git, path, abbreviatedObjectId.toObjectId()));
}
项目:GitDirStat    文件:IndexUpdate.java   
@Override
public Collection<ObjectId> resolve(AbbreviatedObjectId id)
        throws IOException {
    return delegate.resolve(id);
}
项目:ninja_chic-    文件:Repos.java   
public static String shortenRevName(String revision) {
    return AbbreviatedObjectId.isId(revision)?revision.substring(0,4):shortenRefName(revision);
}
项目:gitiles    文件:Revision.java   
public boolean nameIsId() {
  return AbbreviatedObjectId.isId(name)
      && (AbbreviatedObjectId.fromString(name).prefixCompare(id) == 0);
}