Factor out a method for converting PersonIdent to GitPerson
Created a new, common class for this kind of thing; hopefully it grows some more methods. Change-Id: I0a7d99e78a54694f898fd56822ae9cbd42f2df05
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.server;
|
||||
|
||||
import com.google.gerrit.extensions.common.GitPerson;
|
||||
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* Converters to classes in {@link com.google.gerrit.extensions.common}.
|
||||
* <p>
|
||||
* The server frequently needs to convert internal types to types exposed in the
|
||||
* extension API, but the converters themselves are not part of this API. This
|
||||
* class contains such converters as static utility methods.
|
||||
*/
|
||||
public class CommonConverters {
|
||||
public static GitPerson toGitPerson(PersonIdent ident) {
|
||||
GitPerson result = new GitPerson();
|
||||
result.name = ident.getName();
|
||||
result.email = ident.getEmailAddress();
|
||||
result.date = new Timestamp(ident.getWhen().getTime());
|
||||
result.tz = ident.getTimeZoneOffset();
|
||||
return result;
|
||||
}
|
||||
|
||||
private CommonConverters() {
|
||||
}
|
||||
}
|
@@ -21,12 +21,12 @@ import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.extensions.common.CommitInfo;
|
||||
import com.google.gerrit.extensions.common.GitPerson;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetAncestor;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.CommonConverters;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.ProjectControl;
|
||||
@@ -39,7 +39,6 @@ import com.google.inject.Singleton;
|
||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
@@ -50,7 +49,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
@@ -272,15 +270,6 @@ public class GetRelated implements RestReadView<RevisionResource> {
|
||||
return r;
|
||||
}
|
||||
|
||||
private static GitPerson toGitPerson(PersonIdent id) {
|
||||
GitPerson p = new GitPerson();
|
||||
p.name = id.getName();
|
||||
p.email = id.getEmailAddress();
|
||||
p.date = new Timestamp(id.getWhen().getTime());
|
||||
p.tz = id.getTimeZoneOffset();
|
||||
return p;
|
||||
}
|
||||
|
||||
public static class RelatedInfo {
|
||||
public List<ChangeAndCommit> changes;
|
||||
}
|
||||
@@ -309,7 +298,7 @@ public class GetRelated implements RestReadView<RevisionResource> {
|
||||
p.commit = c.getParent(i).name();
|
||||
commit.parents.add(p);
|
||||
}
|
||||
commit.author = toGitPerson(c.getAuthorIdent());
|
||||
commit.author = CommonConverters.toGitPerson(c.getAuthorIdent());
|
||||
commit.subject = c.getShortMessage();
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.server.project;
|
||||
import com.google.gerrit.extensions.common.CommitInfo;
|
||||
import com.google.gerrit.extensions.common.GitPerson;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.CommonConverters;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
@@ -36,8 +37,8 @@ public class GetCommit implements RestReadView<CommitResource> {
|
||||
private static CommitInfo toCommitInfo(RevCommit commit) {
|
||||
CommitInfo info = new CommitInfo();
|
||||
info.commit = commit.getName();
|
||||
info.author = toGitPerson(commit.getAuthorIdent());
|
||||
info.committer = toGitPerson(commit.getCommitterIdent());
|
||||
info.author = CommonConverters.toGitPerson(commit.getAuthorIdent());
|
||||
info.committer = CommonConverters.toGitPerson(commit.getCommitterIdent());
|
||||
info.subject = commit.getShortMessage();
|
||||
info.message = commit.getFullMessage();
|
||||
info.parents = new ArrayList<>(commit.getParentCount());
|
||||
|
@@ -20,12 +20,12 @@ import com.google.gerrit.extensions.common.GitPerson;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.server.CommonConverters;
|
||||
import com.google.gerrit.server.args4j.TimestampHandler;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.ReflogEntry;
|
||||
import org.eclipse.jgit.lib.ReflogReader;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
@@ -122,14 +122,7 @@ public class GetReflog implements RestReadView<BranchResource> {
|
||||
public ReflogEntryInfo(ReflogEntry e) {
|
||||
oldId = e.getOldId().getName();
|
||||
newId = e.getNewId().getName();
|
||||
|
||||
PersonIdent ident = e.getWho();
|
||||
who = new GitPerson();
|
||||
who.name = ident.getName();
|
||||
who.email = ident.getEmailAddress();
|
||||
who.date = new Timestamp(ident.getWhen().getTime());
|
||||
who.tz = ident.getTimeZoneOffset();
|
||||
|
||||
who = CommonConverters.toGitPerson(e.getWho());
|
||||
comment = e.getComment();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user