Search in sources :

Example 26 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project gitiles by GerritCodeReview.

the class TimeCache method getTime.

Long getTime(final RevWalk walk, final ObjectId id) throws IOException {
    try {
        return cache.get(id, () -> {
            RevObject o = walk.parseAny(id);
            while (o instanceof RevTag) {
                RevTag tag = (RevTag) o;
                PersonIdent ident = tag.getTaggerIdent();
                if (ident != null) {
                    return ident.getWhen().getTime() / 1000;
                }
                o = tag.getObject();
                walk.parseHeaders(o);
            }
            if (o.getType() == Constants.OBJ_COMMIT) {
                return Long.valueOf(((RevCommit) o).getCommitTime());
            }
            return Long.MIN_VALUE;
        });
    } catch (ExecutionException e) {
        Throwables.throwIfInstanceOf(e.getCause(), IOException.class);
        throw new IOException(e);
    }
}
Also used : RevTag(org.eclipse.jgit.revwalk.RevTag) RevObject(org.eclipse.jgit.revwalk.RevObject) PersonIdent(org.eclipse.jgit.lib.PersonIdent) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 27 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project gitiles by GerritCodeReview.

the class IdentRevFilterTest method caseSensitiveName.

@Test
public void caseSensitiveName() throws Exception {
    IdentRevFilter filter = IdentRevFilter.author("eSt");
    assertThat(filter.matchesPerson(new PersonIdent("est", "null@google.com"))).isFalse();
    assertThat(filter.matchesPerson(new PersonIdent("Establish", "null@google.com"))).isFalse();
    assertThat(filter.matchesPerson(new PersonIdent("tESt", "null@google.com"))).isFalse();
    assertThat(filter.matchesPerson(new PersonIdent("tesTing", "null@google.com"))).isFalse();
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) Test(org.junit.Test)

Example 28 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project gitiles by GerritCodeReview.

the class IdentRevFilterTest method matchesEmailLocalPart.

@Test
public void matchesEmailLocalPart() throws Exception {
    IdentRevFilter filter = IdentRevFilter.author("eSt");
    assertThat(filter.matchesPerson(new PersonIdent("null", "eSt@google.com"))).isTrue();
    assertThat(filter.matchesPerson(new PersonIdent("null", "eStablish@google.com"))).isTrue();
    assertThat(filter.matchesPerson(new PersonIdent("null", "teSt@google.com"))).isTrue();
    assertThat(filter.matchesPerson(new PersonIdent("null", "teSting@google.com"))).isTrue();
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) Test(org.junit.Test)

Example 29 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project gitiles by GerritCodeReview.

the class DateFormatterTest method newIdent.

private PersonIdent newIdent(String whenStr, String tzStr) throws ParseException {
    whenStr += " " + tzStr;
    Date when = GitDateParser.parse(whenStr, null);
    TimeZone tz = getTimeZone("GMT" + tzStr);
    PersonIdent ident = new PersonIdent("A User", "user@example.com", when, tz);
    // PersonIdent.toString() uses its own format with "d" instead of "dd",
    // hence the mismatches in 2 vs. 02 above. Nonetheless I think this sanity
    // check is useful enough to keep around.
    assertThat(ident.toString()).isEqualTo("PersonIdent[A User, user@example.com, " + whenStr + "]");
    return ident;
}
Also used : TimeZone(java.util.TimeZone) TimeZone.getTimeZone(java.util.TimeZone.getTimeZone) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Date(java.util.Date)

Example 30 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project gitiles by GerritCodeReview.

the class DateFormatterTest method isoIncludingTimeZone.

@Test
public void isoIncludingTimeZone() throws Exception {
    PersonIdent ident = newIdent("Mon Jan 2 15:04:05 2006", "-0700");
    DateFormatter df = new DateFormatter(Optional.empty(), ISO);
    assertThat(df.format(ident)).isEqualTo("2006-01-02 15:04:05 -0700");
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) Test(org.junit.Test)

Aggregations

PersonIdent (org.eclipse.jgit.lib.PersonIdent)221 RevCommit (org.eclipse.jgit.revwalk.RevCommit)78 ObjectId (org.eclipse.jgit.lib.ObjectId)55 Test (org.junit.Test)55 Repository (org.eclipse.jgit.lib.Repository)48 IOException (java.io.IOException)41 CommitBuilder (org.eclipse.jgit.lib.CommitBuilder)41 RevWalk (org.eclipse.jgit.revwalk.RevWalk)38 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)31 Change (com.google.gerrit.entities.Change)28 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)26 Ref (org.eclipse.jgit.lib.Ref)26 Git (org.eclipse.jgit.api.Git)25 Account (com.google.gerrit.entities.Account)22 Instant (java.time.Instant)21 TestRepository (org.eclipse.jgit.junit.TestRepository)20 ArrayList (java.util.ArrayList)18 File (java.io.File)17 Date (java.util.Date)17 RefUpdate (org.eclipse.jgit.lib.RefUpdate)17