Example usage for org.eclipse.jgit.lib AbbreviatedObjectId name

List of usage examples for org.eclipse.jgit.lib AbbreviatedObjectId name

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib AbbreviatedObjectId name.

Prototype

public final String name() 

Source Link

Document

Get string form of the abbreviation, in lower case hexadecimal.

Usage

From source file:MyDiffFormatter.java

License:Eclipse Distribution License

private String format(AbbreviatedObjectId id) {
    if (id.isComplete() && db != null) {
        try {//from  www . j  av  a  2 s  .  c  om
            int abbreviationLength = 7;
            id = reader.abbreviate(id.toObjectId(), abbreviationLength);
        } catch (IOException cannotAbbreviate) {
            // Ignore this. We'll report the full identity.
        }
    }
    return id.name();
}

From source file:com.creactiviti.piper.core.git.JGitTemplate.java

License:Apache License

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);
        }//from  w  ww.j  av a 2  s . co m
        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));
    }
}

From source file:com.github.koraktor.mavanagaiata.git.jgit.JGitRepositoryTest.java

License:Open Source License

@Test
public void testDescribeTagged() throws Exception {
    RevCommit head = this.createCommit();
    RevCommit head_1 = this.createCommit();
    RevCommit head_2 = this.createCommit();
    head.getParents()[0] = head_1;/*from   w  w  w . ja v  a 2 s.c  o  m*/
    head_1.getParents()[0] = head_2;
    AbbreviatedObjectId abbrevId = head.abbreviate(7);
    this.repository.headObject = mock(ObjectId.class);
    this.repository.commitCache.put(this.repository.headObject, head);

    JGitRepository repo = spy(this.repository);

    Map<String, RevTag> rawTags = new HashMap<String, RevTag>();
    RevTag rawTag = this.createTag("2.0.0", head_2.getName());
    rawTags.put(head_2.getName(), rawTag);
    doReturn(rawTags).when(repo).getRawTags();

    Map<String, GitTag> tags = new HashMap<String, GitTag>();
    tags.put(head_2.getName(), new JGitTag(rawTag));
    doReturn(tags).when(repo).getTags();

    repo.revWalk = mock(RevWalk.class);
    RevFlag seenFlag = RevFlag.UNINTERESTING;
    when(repo.revWalk.newFlag("SEEN")).thenReturn(seenFlag);

    when(this.repo.getObjectDatabase().newReader().abbreviate(head)).thenReturn(abbrevId);

    GitTagDescription description = repo.describe();
    assertThat(head.has(seenFlag), is(true));
    assertThat(head_1.has(seenFlag), is(true));
    assertThat(head_2.has(seenFlag), is(true));
    assertThat(description.getNextTagName(), is(equalTo("2.0.0")));
    assertThat(description.toString(), is(equalTo("2.0.0-2-g" + abbrevId.name())));
}

From source file:com.github.koraktor.mavanagaiata.git.jgit.JGitRepositoryTest.java

License:Open Source License

@Test
public void testDescribeUntagged() throws Exception {
    RevCommit head = this.createCommit();
    RevCommit head_1 = this.createCommit();
    RevCommit head_2 = this.createCommit();
    head.getParents()[0] = head_1;/*from  w  w w  .ja  v a 2  s  . c om*/
    head_1.getParents()[0] = head_2;
    AbbreviatedObjectId abbrevId = head.abbreviate(7);
    this.repository.headObject = mock(ObjectId.class);
    this.repository.commitCache.put(this.repository.headObject, head);

    this.repository.revWalk = mock(RevWalk.class);
    RevFlag seenFlag = RevFlag.UNINTERESTING;
    when(this.repository.revWalk.newFlag("SEEN")).thenReturn(seenFlag);

    when(this.repo.getObjectDatabase().newReader().abbreviate(head)).thenReturn(abbrevId);

    GitTagDescription description = this.repository.describe();
    assertThat(head.has(seenFlag), is(true));
    assertThat(head_1.has(seenFlag), is(true));
    assertThat(head_2.has(seenFlag), is(true));
    assertThat(description.getNextTagName(), is(equalTo("")));
    assertThat(description.toString(), is(equalTo(abbrevId.name())));
}

From source file:com.google.gerrit.server.change.GetPatch.java

License:Apache License

private static String fileName(RevWalk rw, RevCommit commit) throws IOException {
    AbbreviatedObjectId id = rw.getObjectReader().abbreviate(commit, 8);
    return id.name() + ".diff";
}

From source file:com.google.gerrit.server.query.ObjectIdPredicate.java

License:Apache License

public ObjectIdPredicate(final String name, final AbbreviatedObjectId id) {
    super(name, id.name());
    this.id = id;
}

From source file:com.googlesource.gerrit.plugins.validators.CommitMessageLengthValidation.java

License:Apache License

private void onLineTooLong(final AbbreviatedObjectId id, List<CommitValidationMessage> messagesList,
        final String errorMessage) throws CommitValidationException {
    final String message = id.name() + ": " + errorMessage;
    if (rejectTooLong) {
        messagesList.add(new CommitValidationMessage(message, true));
        throw new CommitValidationException("Commit length validation failed", messagesList);
    }/*from w ww .  ja v  a 2  s .  c  o m*/
    messagesList.add(new CommitValidationMessage("(W) " + message, false));
}

From source file:com.madgag.agit.diff.LineContextDiffer.java

License:Open Source License

private String format(AbbreviatedObjectId id) {
    if (id.isComplete()) {
        try {//from   w  w w . j  a va 2  s . c om
            id = objectReader.abbreviate(id.toObjectId(), abbreviationLength);
        } catch (IOException cannotAbbreviate) {
            // Ignore this. We'll report the full identity.
        } finally {
            // reader.release();
        }
    }
    return id.name();
}

From source file:org.eclipse.egit.ui.internal.synchronize.mapping.GitChangeSetLabelProvider.java

License:Open Source License

private String getAbbreviatedId(GitModelCommit commit) {
    RevCommit remoteCommit = commit.getBaseCommit();
    ObjectReader reader = commit.getRepository().newObjectReader();
    ObjectId commitId = remoteCommit.getId();
    AbbreviatedObjectId shortId;
    try {//w  ww.  j av a  2  s. co m
        shortId = reader.abbreviate(commitId, 6);
    } catch (IOException e) {
        shortId = AbbreviatedObjectId.fromObjectId(ObjectId.zeroId());
        Activator.logError(e.getMessage(), e);
    } finally {
        reader.release();
    }
    return shortId.name();
}

From source file:pl.project13.maven.git.GitCommitIdMojo.java

License:Open Source License

private void putAbbrevCommitId(ObjectReader objectReader, Properties properties, RevCommit headCommit,
        int abbrevLength) throws MojoExecutionException {
    if (abbrevLength < 2 || abbrevLength > 40) {
        throw new MojoExecutionException(
                "Abbreviated commit id lenght must be between 2 and 40, inclusive! Was [%s]. ".codePointBefore(
                        abbrevLength) + "Please fix your configuration (the <abbrevLength/> element).");
    }/*w w w  .  ja va  2s . c  om*/

    try {
        AbbreviatedObjectId abbreviatedObjectId = objectReader.abbreviate(headCommit, abbrevLength);
        put(properties, COMMIT_ID_ABBREV, abbreviatedObjectId.name());
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to abbreviate commit id! "
                + "You may want to investigate the <abbrevLength/> element in your configuration.", e);
    }
}