Search in sources :

Example 1 with MutableInteger

use of org.eclipse.jgit.util.MutableInteger in project gerrit by GerritCodeReview.

the class ExternalIdIT method insertNonParsableExternalIds.

private Set<ConsistencyProblemInfo> insertNonParsableExternalIds() throws IOException {
    MutableInteger i = new MutableInteger();
    String scheme = "corrupt";
    Set<ConsistencyProblemInfo> expectedProblems = new HashSet<>();
    try (Repository repo = repoManager.openRepository(allUsers);
        RevWalk rw = new RevWalk(repo)) {
        String externalId = nextId(scheme, i);
        String noteId = insertExternalIdWithoutAccountId(repo, rw, externalId);
        expectedProblems.add(consistencyError("Invalid external ID config for note '" + noteId + "': Value for 'externalId." + externalId + ".accountId' is missing, expected account ID"));
        externalId = nextId(scheme, i);
        noteId = insertExternalIdWithKeyThatDoesntMatchNoteId(repo, rw, externalId);
        expectedProblems.add(consistencyError("Invalid external ID config for note '" + noteId + "': SHA1 of external ID '" + externalId + "' does not match note ID '" + noteId + "'"));
        noteId = insertExternalIdWithInvalidConfig(repo, rw, nextId(scheme, i));
        expectedProblems.add(consistencyError("Invalid external ID config for note '" + noteId + "': Invalid line in config file"));
        noteId = insertExternalIdWithEmptyNote(repo, rw, nextId(scheme, i));
        expectedProblems.add(consistencyError("Invalid external ID config for note '" + noteId + "': Expected exactly 1 'externalId' section, found 0"));
    }
    return expectedProblems;
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) MutableInteger(org.eclipse.jgit.util.MutableInteger) ConsistencyProblemInfo(com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo) RevWalk(org.eclipse.jgit.revwalk.RevWalk) HashSet(java.util.HashSet)

Example 2 with MutableInteger

use of org.eclipse.jgit.util.MutableInteger in project gerrit by GerritCodeReview.

the class ChangeIndexRewriter method rewriteImpl.

private Predicate<ChangeData> rewriteImpl(Predicate<ChangeData> in, QueryOptions opts) throws QueryParseException {
    ChangeIndex index = indexes.getSearchIndex();
    MutableInteger leafTerms = new MutableInteger();
    Predicate<ChangeData> out = rewriteImpl(in, index, opts, leafTerms);
    if (in == out || out instanceof IndexPredicate) {
        return new IndexedChangeQuery(index, out, opts);
    } else if (out == null) /* cannot rewrite */
    {
        return in;
    } else {
        return out;
    }
}
Also used : IndexPredicate(com.google.gerrit.server.index.IndexPredicate) MutableInteger(org.eclipse.jgit.util.MutableInteger) ChangeData(com.google.gerrit.server.query.change.ChangeData)

Example 3 with MutableInteger

use of org.eclipse.jgit.util.MutableInteger in project gerrit by GerritCodeReview.

the class ChangeNoteUtil method parseParentNumber.

private static Integer parseParentNumber(byte[] note, MutableInteger curr, Change.Id changeId) throws ConfigInvalidException {
    checkHeaderLineFormat(note, curr, PARENT_NUMBER, changeId);
    int start = RawParseUtils.endOfFooterLineKey(note, curr.value) + 1;
    MutableInteger i = new MutableInteger();
    int parentNumber = RawParseUtils.parseBase10(note, start, i);
    int endOfLine = RawParseUtils.nextLF(note, curr.value);
    if (i.value != endOfLine - 1) {
        throw parseException(changeId, "could not parse %s", PARENT_NUMBER);
    }
    checkResult(parentNumber, "parent number", changeId);
    curr.value = endOfLine;
    return Integer.valueOf(parentNumber);
}
Also used : MutableInteger(org.eclipse.jgit.util.MutableInteger)

Example 4 with MutableInteger

use of org.eclipse.jgit.util.MutableInteger in project gerrit by GerritCodeReview.

the class ChangeNoteUtil method parseCommentLength.

private static int parseCommentLength(byte[] note, MutableInteger curr, Change.Id changeId) throws ConfigInvalidException {
    checkHeaderLineFormat(note, curr, LENGTH, changeId);
    int startOfLength = RawParseUtils.endOfFooterLineKey(note, curr.value) + 1;
    MutableInteger i = new MutableInteger();
    i.value = startOfLength;
    int commentLength = RawParseUtils.parseBase10(note, startOfLength, i);
    if (i.value == startOfLength) {
        throw parseException(changeId, "could not parse %s", LENGTH);
    }
    int endOfLine = RawParseUtils.nextLF(note, curr.value);
    if (i.value != endOfLine - 1) {
        throw parseException(changeId, "could not parse %s", LENGTH);
    }
    curr.value = endOfLine;
    return checkResult(commentLength, "comment length", changeId);
}
Also used : MutableInteger(org.eclipse.jgit.util.MutableInteger)

Example 5 with MutableInteger

use of org.eclipse.jgit.util.MutableInteger in project gerrit by GerritCodeReview.

the class ChangeNoteUtil method parsePsId.

private static PatchSet.Id parsePsId(byte[] note, MutableInteger curr, Change.Id changeId, String fieldName) throws ConfigInvalidException {
    checkHeaderLineFormat(note, curr, fieldName, changeId);
    int startOfPsId = RawParseUtils.endOfFooterLineKey(note, curr.value) + 1;
    MutableInteger i = new MutableInteger();
    int patchSetId = RawParseUtils.parseBase10(note, startOfPsId, i);
    int endOfLine = RawParseUtils.nextLF(note, curr.value);
    if (i.value != endOfLine - 1) {
        throw parseException(changeId, "could not parse %s", fieldName);
    }
    checkResult(patchSetId, "patchset id", changeId);
    curr.value = endOfLine;
    return new PatchSet.Id(changeId, patchSetId);
}
Also used : MutableInteger(org.eclipse.jgit.util.MutableInteger) GerritServerId(com.google.gerrit.server.config.GerritServerId) RevId(com.google.gerrit.reviewdb.client.RevId)

Aggregations

MutableInteger (org.eclipse.jgit.util.MutableInteger)10 HashSet (java.util.HashSet)3 ConsistencyProblemInfo (com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo)2 RevId (com.google.gerrit.reviewdb.client.RevId)2 ExternalIdsUpdate (com.google.gerrit.server.account.externalids.ExternalIdsUpdate)2 RefsMetaExternalIdsUpdate (com.google.gerrit.server.account.externalids.ExternalIdsUpdate.RefsMetaExternalIdsUpdate)2 Comment (com.google.gerrit.reviewdb.client.Comment)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)1 GerritServerId (com.google.gerrit.server.config.GerritServerId)1 IndexPredicate (com.google.gerrit.server.index.IndexPredicate)1 ChangeData (com.google.gerrit.server.query.change.ChangeData)1 ArrayList (java.util.ArrayList)1 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)1 TestRepository (org.eclipse.jgit.junit.TestRepository)1 Repository (org.eclipse.jgit.lib.Repository)1 FooterKey (org.eclipse.jgit.revwalk.FooterKey)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1 QuotedString (org.eclipse.jgit.util.QuotedString)1