Search in sources :

Example 56 with PersonIdent

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

the class AccountsOnInit method insert.

public void insert(ReviewDb db, Account account) throws OrmException, IOException {
    db.accounts().insert(ImmutableSet.of(account));
    File path = getPath();
    if (path != null) {
        try (Repository repo = new FileRepository(path);
            ObjectInserter oi = repo.newObjectInserter()) {
            PersonIdent serverIdent = new GerritPersonIdentProvider(flags.cfg).get();
            AccountsUpdate.createUserBranch(repo, oi, serverIdent, serverIdent, account);
        }
    }
}
Also used : FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) FileRepository(org.eclipse.jgit.internal.storage.file.FileRepository) Repository(org.eclipse.jgit.lib.Repository) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) PersonIdent(org.eclipse.jgit.lib.PersonIdent) GerritPersonIdentProvider(com.google.gerrit.server.GerritPersonIdentProvider) File(java.io.File)

Example 57 with PersonIdent

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

the class ChangeNotesParser method parseAddApproval.

private PatchSetApproval parseAddApproval(PatchSet.Id psId, Account.Id committerId, Account.Id realAccountId, Timestamp ts, String line) throws ConfigInvalidException {
    // There are potentially 3 accounts involved here:
    //  1. The account from the commit, which is the effective IdentifiedUser
    //     that produced the update.
    //  2. The account in the label footer itself, which is used during submit
    //     to copy other users' labels to a new patch set.
    //  3. The account in the Real-user footer, indicating that the whole
    //     update operation was executed by this user on behalf of the effective
    //     user.
    Account.Id effectiveAccountId;
    String labelVoteStr;
    int s = line.indexOf(' ');
    if (s > 0) {
        // Account in the label line (2) becomes the effective ID of the
        // approval. If there is a real user (3) different from the commit user
        // (2), we actually don't store that anywhere in this case; it's more
        // important to record that the real user (3) actually initiated submit.
        labelVoteStr = line.substring(0, s);
        PersonIdent ident = RawParseUtils.parsePersonIdent(line.substring(s + 1));
        checkFooter(ident != null, FOOTER_LABEL, line);
        effectiveAccountId = noteUtil.parseIdent(ident, id);
    } else {
        labelVoteStr = line;
        effectiveAccountId = committerId;
    }
    LabelVote l;
    try {
        l = LabelVote.parseWithEquals(labelVoteStr);
    } catch (IllegalArgumentException e) {
        ConfigInvalidException pe = parseException("invalid %s: %s", FOOTER_LABEL, line);
        pe.initCause(e);
        throw pe;
    }
    PatchSetApproval psa = new PatchSetApproval(new PatchSetApproval.Key(psId, effectiveAccountId, new LabelId(l.label())), l.value(), ts);
    psa.setTag(tag);
    if (!Objects.equals(realAccountId, committerId)) {
        psa.setRealAccountId(realAccountId);
    }
    ApprovalKey k = ApprovalKey.create(psId, effectiveAccountId, l.label());
    if (!approvals.containsKey(k)) {
        approvals.put(k, psa);
    }
    return psa;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) PersonIdent(org.eclipse.jgit.lib.PersonIdent) LabelVote(com.google.gerrit.server.util.LabelVote) LabelId(com.google.gerrit.reviewdb.client.LabelId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval)

Example 58 with PersonIdent

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

the class ChangeNotesParser method parseReviewer.

private void parseReviewer(Timestamp ts, ReviewerStateInternal state, String line) throws ConfigInvalidException {
    PersonIdent ident = RawParseUtils.parsePersonIdent(line);
    if (ident == null) {
        throw invalidFooter(state.getFooterKey(), line);
    }
    Account.Id accountId = noteUtil.parseIdent(ident, id);
    reviewerUpdates.add(ReviewerStatusUpdate.create(ts, ownerId, accountId, state));
    if (!reviewers.containsRow(accountId)) {
        reviewers.put(accountId, state, ts);
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) PersonIdent(org.eclipse.jgit.lib.PersonIdent)

Example 59 with PersonIdent

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

the class ChangeNotesParser method parseSubmitRecords.

private void parseSubmitRecords(List<String> lines) throws ConfigInvalidException {
    SubmitRecord rec = null;
    for (String line : lines) {
        int c = line.indexOf(": ");
        if (c < 0) {
            rec = new SubmitRecord();
            submitRecords.add(rec);
            int s = line.indexOf(' ');
            String statusStr = s >= 0 ? line.substring(0, s) : line;
            rec.status = Enums.getIfPresent(SubmitRecord.Status.class, statusStr).orNull();
            checkFooter(rec.status != null, FOOTER_SUBMITTED_WITH, line);
            if (s >= 0) {
                rec.errorMessage = line.substring(s);
            }
        } else {
            checkFooter(rec != null, FOOTER_SUBMITTED_WITH, line);
            SubmitRecord.Label label = new SubmitRecord.Label();
            if (rec.labels == null) {
                rec.labels = new ArrayList<>();
            }
            rec.labels.add(label);
            label.status = Enums.getIfPresent(SubmitRecord.Label.Status.class, line.substring(0, c)).orNull();
            checkFooter(label.status != null, FOOTER_SUBMITTED_WITH, line);
            int c2 = line.indexOf(": ", c + 2);
            if (c2 >= 0) {
                label.label = line.substring(c + 2, c2);
                PersonIdent ident = RawParseUtils.parsePersonIdent(line.substring(c2 + 2));
                checkFooter(ident != null, FOOTER_SUBMITTED_WITH, line);
                label.appliedBy = noteUtil.parseIdent(ident, id);
            } else {
                label.label = line.substring(c + 2);
            }
        }
    }
}
Also used : SubmitRecord(com.google.gerrit.common.data.SubmitRecord) PersonIdent(org.eclipse.jgit.lib.PersonIdent)

Example 60 with PersonIdent

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

the class ChangeNotesParser method parseIdent.

private Account.Id parseIdent(ChangeNotesCommit commit) throws ConfigInvalidException {
    // Check if the author name/email is the same as the committer name/email,
    // i.e. was the server ident at the time this commit was made.
    PersonIdent a = commit.getAuthorIdent();
    PersonIdent c = commit.getCommitterIdent();
    if (a.getName().equals(c.getName()) && a.getEmailAddress().equals(c.getEmailAddress())) {
        return null;
    }
    return noteUtil.parseIdent(commit.getAuthorIdent(), id);
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent)

Aggregations

PersonIdent (org.eclipse.jgit.lib.PersonIdent)86 RevCommit (org.eclipse.jgit.revwalk.RevCommit)23 Test (org.junit.Test)21 CommitBuilder (org.eclipse.jgit.lib.CommitBuilder)19 ObjectId (org.eclipse.jgit.lib.ObjectId)18 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)15 RevWalk (org.eclipse.jgit.revwalk.RevWalk)13 Change (com.google.gerrit.reviewdb.client.Change)12 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)12 Repository (org.eclipse.jgit.lib.Repository)11 Account (com.google.gerrit.reviewdb.client.Account)10 IOException (java.io.IOException)9 RefUpdate (org.eclipse.jgit.lib.RefUpdate)9 Ref (org.eclipse.jgit.lib.Ref)8 TestRepository (org.eclipse.jgit.junit.TestRepository)7 Date (java.util.Date)6 Result (org.eclipse.jgit.lib.RefUpdate.Result)6 ArrayList (java.util.ArrayList)5 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)4 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4