本文整理匯總了Java中org.eclipse.jgit.lib.PersonIdent類的典型用法代碼示例。如果您正苦於以下問題:Java PersonIdent類的具體用法?Java PersonIdent怎麽用?Java PersonIdent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PersonIdent類屬於org.eclipse.jgit.lib包,在下文中一共展示了PersonIdent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toCommit
import org.eclipse.jgit.lib.PersonIdent; //導入依賴的package包/類
private static Commit toCommit(RevCommit revCommit) {
final Author author;
final PersonIdent committerIdent = revCommit.getCommitterIdent();
if (committerIdent == null) {
author = Author.UNKNOWN;
} else {
author = new Author(committerIdent.getName(), committerIdent.getEmailAddress());
}
long when = committerIdent.getWhen().getTime();
try {
return CommitUtil.newCommit(author, when, revCommit.getFullMessage());
} catch (Exception e) {
throw new StorageException("failed to create a Commit", e);
}
}
示例2: parsePersonIdent
import org.eclipse.jgit.lib.PersonIdent; //導入依賴的package包/類
/**
* Parse the raw user information into PersonIdent object, the raw information
* should be in format <code>[name] [<email>] [epoch timezone]</code>, for
* example:
*
* Jacob Thornton <[email protected]> 1328060294 -0800
*
* @param raw
* @return
*/
public static @Nullable PersonIdent parsePersonIdent(String raw) {
if (Strings.isNullOrEmpty(raw))
return null;
int pos1 = raw.indexOf('<');
if (pos1 <= 0)
throw new IllegalArgumentException("Raw " + raw);
String name = raw.substring(0, pos1 - 1);
int pos2 = raw.indexOf('>');
if (pos2 <= 0)
throw new IllegalArgumentException("Raw " + raw);
String time = raw.substring(pos2 + 1).trim();
Date when = parseRawDate(time);
String email = raw.substring(pos1 + 1, pos2 - 1);
return newPersonIdent(name, email, when);
}
示例3: build
import org.eclipse.jgit.lib.PersonIdent; //導入依賴的package包/類
public LogCommit build() {
PersonIdent committer;
if (StringUtils.isNotBlank(committerName) && StringUtils.isNotBlank(committerEmail)
&& committerDate != null) {
committer = GitUtils.newPersonIdent(committerName, committerEmail, committerDate);
} else {
committer = null;
}
PersonIdent author;
if (StringUtils.isNotBlank(authorName) && StringUtils.isNotBlank(authorEmail)
&& authorDate != null) {
author = GitUtils.newPersonIdent(authorName, authorEmail, authorDate);
} else {
author = null;
}
return new LogCommit(hash, committer, author, parentHashes, changedFiles);
}
示例4: commit
import org.eclipse.jgit.lib.PersonIdent; //導入依賴的package包/類
/**
*
* @param commitBuilder
* @param treeId
* @param repo
* @return
* @throws UnsupportedEncodingException
* @throws IOException
*/
public static ObjectId commit(CommitBuilder commitBuilder, ObjectId treeId, Repository repo) throws UnsupportedEncodingException, IOException {
commitBuilder.setTreeId(treeId);
commitBuilder.setMessage(System.currentTimeMillis() + ": My commit!\n");
PersonIdent person = new PersonIdent("Alex", "[email protected]");
commitBuilder.setAuthor(person);
commitBuilder.setCommitter(person);
commitBuilder.build();
ObjectInserter commitInserter = repo.newObjectInserter();
ObjectId commitId = commitInserter.insert(commitBuilder);
commitInserter.flush();
updateMasterRecord(repo, commitId);
System.out.println("Commit Object ID: " + commitId.getName());
return commitId;
}
示例5: getAuthorName
import org.eclipse.jgit.lib.PersonIdent; //導入依賴的package包/類
@Override
public String getAuthorName( String commitId ) {
if ( commitId.equals( IVCS.WORKINGTREE ) ) {
Config config = git.getRepository().getConfig();
return config.get( UserConfig.KEY ).getAuthorName()
+ " <" + config.get( UserConfig.KEY ).getAuthorEmail() + ">";
} else {
RevCommit commit = resolve( commitId );
PersonIdent author = commit.getAuthorIdent();
final StringBuilder r = new StringBuilder();
r.append( author.getName() );
r.append( " <" ); //$NON-NLS-1$
r.append( author.getEmailAddress() );
r.append( ">" ); //$NON-NLS-1$
return r.toString();
}
}
示例6: testCommit
import org.eclipse.jgit.lib.PersonIdent; //導入依賴的package包/類
@Test
public void testCommit() throws Exception {
assertFalse( uiGit.hasStagedFiles() );
writeTrashFile( "Test.txt", "Hello world" );
uiGit.add( "Test.txt" );
PersonIdent author = new PersonIdent( "author", "[email protected]" );
String message = "Initial commit";
assertTrue( uiGit.hasStagedFiles() );
uiGit.commit( author.toExternalString(), message );
String commitId = uiGit.getCommitId( Constants.HEAD );
assertTrue( uiGit.isClean() );
assertTrue( author.toExternalString().contains( uiGit.getAuthorName( commitId ) ) );
assertEquals( message, uiGit.getCommitMessage( commitId ) );
}
示例7: createCommitInfo
import org.eclipse.jgit.lib.PersonIdent; //導入依賴的package包/類
public CommitInfo createCommitInfo(RevCommit entry) {
final Date date = GitUtils.getCommitDate(entry);
PersonIdent authorIdent = entry.getAuthorIdent();
String author = null;
String name = null;
String email = null;
String avatarUrl = null;
if (authorIdent != null) {
author = authorIdent.getName();
name = authorIdent.getName();
email = authorIdent.getEmailAddress();
// lets try default the avatar
if (Strings.isNotBlank(email)) {
avatarUrl = getAvatarUrl(email);
}
}
boolean merge = entry.getParentCount() > 1;
String shortMessage = entry.getShortMessage();
String sha = entry.getName();
return new CommitInfo(sha, author, name, email, avatarUrl, date, merge, shortMessage);
}
示例8: getAuthors
import org.eclipse.jgit.lib.PersonIdent; //導入依賴的package包/類
/**
* Gets a set of authors for a path in a given repository
* @param repo The git repository
* @param path The path to get commits for
* @return An iterable of commits
* @throws GitAPIException Any API errors which may occur
* @throws URISyntaxException Error constructing mailto link
*/
public Set<HashableAgent> getAuthors(Git repo, String path) throws GitAPIException, URISyntaxException {
Iterable<RevCommit> logs = repo.log().addPath(path).call();
Set<HashableAgent> fileAuthors = new HashSet<>();
for (RevCommit rev : logs) {
// Use author first with backup of committer
PersonIdent author = rev.getAuthorIdent();
if (author == null) {
author = rev.getCommitterIdent();
}
// Create a new agent and add as much detail as possible
if (author != null) {
HashableAgent newAgent = new HashableAgent();
String name = author.getName();
if (name != null && name.length() > 0) {
newAgent.setName(author.getName());
}
String email = author.getEmailAddress();
if (email != null && email.length() > 0) {
newAgent.setUri(new URI("mailto:" + author.getEmailAddress()));
}
fileAuthors.add(newAgent);
}
}
return fileAuthors;
}
示例9: create
import org.eclipse.jgit.lib.PersonIdent; //導入依賴的package包/類
public static AppRepo create(String name, File originDir) {
try {
InitCommand initCommand = Git.init();
initCommand.setDirectory(originDir);
Git origin = initCommand.call();
origin.add().addFilepattern(".").call();
origin.commit().setMessage("Initial commit")
.setAuthor(new PersonIdent("Author Test", "[email protected]"))
.call();
return new AppRepo(name, originDir, origin);
} catch (Exception e) {
throw new RuntimeException("Error while creating git repo", e);
}
}
示例10: pushingAnEmptyRepoIsRejected
import org.eclipse.jgit.lib.PersonIdent; //導入依賴的package包/類
@Test
public void pushingAnEmptyRepoIsRejected() throws Exception {
File dir = Photocopier.folderForSampleProject("empty-project");
InitCommand initCommand = Git.init();
initCommand.setDirectory(dir);
Git origin = initCommand.call();
ContentResponse resp = restClient.createApp(dir.toURI().toString(), "empty-project");
assertThat(resp, equalTo(501, containsString("No suitable runner found for this app")));
Photocopier.copySampleAppToDir("maven", dir);
origin.add().addFilepattern(".").call();
origin.commit().setMessage("Initial commit")
.setAuthor(new PersonIdent("Author Test", "[email protected]"))
.call();
resp = restClient.createApp(dir.toURI().toString(), "empty-project");
assertThat(resp, equalTo(201, containsString("empty-project")));
assertThat(new JSONObject(resp.getContentAsString()).get("name"), Matchers.equalTo("empty-project"));
assertThat(restClient.deleteApp("empty-project"), equalTo(200, containsString("{")));
}
示例11: returnsCurrentCommitForNonEmptyRepos
import org.eclipse.jgit.lib.PersonIdent; //導入依賴的package包/類
@Test
public void returnsCurrentCommitForNonEmptyRepos() throws Exception {
Git git = emptyRepo();
FileRepository repository = (FileRepository) git.getRepository();
File dir = repository.getDirectory();
FileUtils.writeStringToFile(new File(dir, "file1"), "Hello", "UTF-8");
git.add().addFilepattern(".").call();
git.commit().setMessage("Initial commit")
.setAuthor(new PersonIdent("Author Test", "[email protected]"))
.call();
FileUtils.writeStringToFile(new File(dir, "file2"), "Hello too", "UTF-8");
git.add().addFilepattern(".").call();
git.commit().setMessage("Second commit")
.setAuthor(new PersonIdent("Second contributor", "[email protected]"))
.call();
JSONObject actual = GitCommit.fromHEAD(git).toJSON();
JSONAssert.assertEquals("{" +
"author: 'Second contributor', message: 'Second commit'" +
"}", actual, JSONCompareMode.LENIENT);
assertThat(actual.getLong("date"), Matchers.greaterThanOrEqualTo(System.currentTimeMillis() - 1000));
assertThat(actual.getString("id"), actual.getString("id").length(), is("3688d7063d2d647e3989d62d9770d0dfd0ce3c25".length()));
}
示例12: create
import org.eclipse.jgit.lib.PersonIdent; //導入依賴的package包/類
public static AppRepo create(String name) {
try {
File originDir = copySampleAppToTempDir(name);
InitCommand initCommand = Git.init();
initCommand.setDirectory(originDir);
Git origin = initCommand.call();
origin.add().addFilepattern(".").call();
origin.commit().setMessage("Initial commit")
.setAuthor(new PersonIdent("Author Test", "[email protected]"))
.call();
return new AppRepo(name, originDir, origin);
} catch (Exception e) {
throw new RuntimeException("Error while creating git repo", e);
}
}
示例13: getCommitInfo
import org.eclipse.jgit.lib.PersonIdent; //導入依賴的package包/類
/**
* Does not fetch.
*/
public CommitInfo getCommitInfo(String path) throws Exception {
Iterator<RevCommit> revCommits = git.log().addPath(path).setMaxCount(1).call().iterator();
if (revCommits.hasNext()) {
RevCommit revCommit = revCommits.next();
CommitInfo commitInfo = new CommitInfo(revCommit.getId().name());
PersonIdent committerIdent = revCommit.getCommitterIdent();
commitInfo.setCommitter(committerIdent.getName());
commitInfo.setEmail(committerIdent.getEmailAddress());
if ((commitInfo.getCommitter() == null || commitInfo.getCommitter().isEmpty()) && commitInfo.getEmail() != null)
commitInfo.setCommitter(commitInfo.getEmail());
commitInfo.setDate(committerIdent.getWhen());
commitInfo.setMessage(revCommit.getShortMessage());
return commitInfo;
}
return null;
}
示例14: AbstractChangeUpdate
import org.eclipse.jgit.lib.PersonIdent; //導入依賴的package包/類
protected AbstractChangeUpdate(
Config cfg,
NotesMigration migration,
ChangeNotes notes,
CurrentUser user,
PersonIdent serverIdent,
String anonymousCowardName,
ChangeNoteUtil noteUtil,
Date when) {
this.migration = migration;
this.noteUtil = noteUtil;
this.serverIdent = new PersonIdent(serverIdent, when);
this.anonymousCowardName = anonymousCowardName;
this.notes = notes;
this.change = notes.getChange();
this.accountId = accountId(user);
Account.Id realAccountId = accountId(user.getRealUser());
this.realAccountId = realAccountId != null ? realAccountId : accountId;
this.authorIdent = ident(noteUtil, serverIdent, anonymousCowardName, user, when);
this.when = when;
this.readOnlySkewMs = NoteDbChangeState.getReadOnlySkew(cfg);
}
示例15: addNoteDbCommit
import org.eclipse.jgit.lib.PersonIdent; //導入依賴的package包/類
private void addNoteDbCommit(Change.Id id, String commitMessage) throws Exception {
if (!notesMigration.commitChangeWrites()) {
return;
}
PersonIdent committer = serverIdent.get();
PersonIdent author =
noteUtil.newIdent(
accountCache.get(admin.getId()).getAccount(),
committer.getWhen(),
committer,
anonymousCowardName);
testRepo
.branch(RefNames.changeMetaRef(id))
.commit()
.author(author)
.committer(committer)
.message(commitMessage)
.create();
}