本文整理汇总了Java中org.eclipse.jgit.api.LogCommand类的典型用法代码示例。如果您正苦于以下问题:Java LogCommand类的具体用法?Java LogCommand怎么用?Java LogCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LogCommand类属于org.eclipse.jgit.api包,在下文中一共展示了LogCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fillLastModifiedCommits
import org.eclipse.jgit.api.LogCommand; //导入依赖的package包/类
private void fillLastModifiedCommits(ObjectId start, String basePath) throws IOException, GitAPIException {
Map<String, ObjectId> objects = lastModifiedCommits.get(start);
if (objects == null) {
objects = new TreeMap<>();
}
DiffFormatter diffFmt = new DiffFormatter(NullOutputStream.INSTANCE);
diffFmt.setRepository(getGitRepository());
LogCommand log = new Git(getGitRepository()).log();
if (!basePath.isEmpty()) {
log.addPath(basePath);
}
for(RevCommit c: log.call()) {
final RevTree a = c.getParentCount() > 0 ? c.getParent(0).getTree() : null;
final RevTree b = c.getTree();
for(DiffEntry diff: diffFmt.scan(a, b)) {
objects.put(diff.getNewPath(), c.getId());
}
}
lastModifiedCommits.put(start, objects);
}
示例2: getHistory
import org.eclipse.jgit.api.LogCommand; //导入依赖的package包/类
@Override
public List<Revision> getHistory(final String test,
final String revision,
final int start,
final int limit) throws StoreException {
try {
final ObjectId commitId = ObjectId.fromString(revision);
final LogCommand logCommand = git.log()
// TODO: create path to definition.json file, sanitize test name for invalid / relative characters
.addPath(getTestDefinitionsDirectory() + File.separator + test + File.separator + FileBasedProctorStore.TEST_DEFINITION_FILENAME)
.add(commitId)
.setSkip(start)
.setMaxCount(limit);
return getHistoryFromLogCommand(logCommand);
} catch (IOException e) {
throw new StoreException("Could not get history for " + test + " starting at " + getGitCore().getRefName(), e);
}
}
示例3: testCommitNoRoots
import org.eclipse.jgit.api.LogCommand; //导入依赖的package包/类
public void testCommitNoRoots () throws Exception {
File toCommit = new File(workDir, "testnotadd.txt");
write(toCommit, "blablabla");
GitClient client = getClient(workDir);
Map<File, GitStatus> statuses = client.getStatus(new File[] { toCommit }, NULL_PROGRESS_MONITOR);
assertStatus(statuses, workDir, toCommit, false, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_ADDED, false);
client.add(new File[] { toCommit }, NULL_PROGRESS_MONITOR);
statuses = client.getStatus(new File[] { toCommit }, NULL_PROGRESS_MONITOR);
assertStatus(statuses, workDir, toCommit, true, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, false);
GitRevisionInfo info = client.commit(new File[0], "initial commit", null, null, NULL_PROGRESS_MONITOR);
statuses = client.getStatus(new File[] { toCommit }, NULL_PROGRESS_MONITOR);
assertStatus(statuses, workDir, toCommit, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false);
Git git = new Git(repository);
LogCommand log = git.log();
RevCommit com = log.call().iterator().next();
assertEquals("initial commit", info.getFullMessage());
assertEquals("initial commit", com.getFullMessage());
assertEquals(ObjectId.toString(com.getId()), info.getRevision());
Map<File, GitFileInfo> modifiedFiles = info.getModifiedFiles();
assertTrue(modifiedFiles.get(toCommit).getStatus().equals(Status.ADDED));
}
示例4: getCommiters
import org.eclipse.jgit.api.LogCommand; //导入依赖的package包/类
@Override
public List<GitUser> getCommiters() throws GitException {
List<GitUser> gitUsers = new ArrayList<>();
try {
LogCommand logCommand = getGit().log();
for (RevCommit commit : logCommand.call()) {
PersonIdent committerIdentity = commit.getCommitterIdent();
GitUser gitUser =
newDto(GitUser.class)
.withName(committerIdentity.getName())
.withEmail(committerIdentity.getEmailAddress());
if (!gitUsers.contains(gitUser)) {
gitUsers.add(gitUser);
}
}
} catch (GitAPIException exception) {
throw new GitException(exception.getMessage(), exception);
}
return gitUsers;
}
示例5: toWikiPage
import org.eclipse.jgit.api.LogCommand; //导入依赖的package包/类
@Override
public WikiPage toWikiPage(WikiPage root) {
FileBasedWikiPage fsPage = (FileBasedWikiPage) root;
String content;
try {
content = convertToWikiText(history(fsPage.getFileSystemPath(), new LogCommandSpec() {
@Override
public LogCommand specify(LogCommand log, Repository repository) {
return log.setMaxCount(RECENT_CHANGES_DEPTH);
}
}));
} catch (GitAPIException e) {
content = "Unable to read history: " + e.getMessage();
}
return new GitRecentChangesPage(RecentChanges.RECENT_CHANGES, root,
new PageData(content, new WikiPageProperties()));
}
示例6: getFirstCommits
import org.eclipse.jgit.api.LogCommand; //导入依赖的package包/类
private List<RevCommit> getFirstCommits(Git git, ObjectId objectId, String path, int length)
throws MissingObjectException, IncorrectObjectTypeException, NoHeadException, GitAPIException {
LogCommand command = git.log();
if (objectId != null) {
command.add(objectId);
}
if (StringUtils.isNotBlank(path)) {
command.addPath(path);
}
Iterator<RevCommit> iterator = command.setMaxCount(length).call().iterator();
List<RevCommit> list = new ArrayList<RevCommit>();
for (int i = 0; i < length; i++) {
if (iterator.hasNext()) {
list.add(iterator.next());
} else {
break;
}
}
return list;
}
示例7: getCommitsFromTag
import org.eclipse.jgit.api.LogCommand; //导入依赖的package包/类
private Iterable<RevCommit> getCommitsFromTag(String refName) {
try {
List<Ref> call = git.tagList().call();
for (Ref ref : call) {
if (ref.getName().endsWith(refName)) {
LogCommand log = git.log();
Ref peeledRef = git.getRepository().peel(ref);
if (peeledRef.getPeeledObjectId() != null) {
return log.add(peeledRef.getPeeledObjectId()).call();
} else {
return log.add(ref.getObjectId()).call();
}
}
}
return null;
} catch (GitAPIException | IncorrectObjectTypeException | MissingObjectException e) {
close();
throw new RepositoryMinerException(e);
}
}
示例8: testRange
import org.eclipse.jgit.api.LogCommand; //导入依赖的package包/类
@Test
public void testRange () throws IOException {
Git git = mock(Git.class);
Repository repository = mock(Repository.class);
LogCommand logCommand = mock(LogCommand.class);
ObjectId a1 = mock(ObjectId.class);
ObjectId a2 = mock(ObjectId.class);
when(git.getRepository()).thenReturn(repository);
when(git.log()).thenReturn(logCommand);
when(repository.resolve("HEAD^^")).thenReturn(a1);
when(repository.resolve("4a877e")).thenReturn(a2);
JGitScanner.getLogWithOrWithOutRange(git, "HEAD^^..4a877e");
verify(logCommand).addRange(a1, a2);
}
示例9: testRangeNoUntil
import org.eclipse.jgit.api.LogCommand; //导入依赖的package包/类
@Test
public void testRangeNoUntil () throws IOException {
Git git = mock(Git.class);
Repository repository = mock(Repository.class);
LogCommand logCommand = mock(LogCommand.class);
ObjectId a1 = mock(ObjectId.class);
ObjectId a2 = mock(ObjectId.class);
when(git.getRepository()).thenReturn(repository);
when(git.log()).thenReturn(logCommand);
when(repository.resolve("HEAD^^")).thenReturn(a1);
when(repository.resolve("HEAD")).thenReturn(a2);
JGitScanner.getLogWithOrWithOutRange(git, "HEAD^^..");
verify(logCommand).addRange(a1, a2);
}
示例10: getHistoryFromLogCommand
import org.eclipse.jgit.api.LogCommand; //导入依赖的package包/类
private List<Revision> getHistoryFromLogCommand(final LogCommand command) throws StoreException {
final List<Revision> versions = Lists.newArrayList();
final Iterable<RevCommit> commits;
try {
commits = command.call();
} catch (GitAPIException e) {
throw new StoreException("Could not get history", e);
}
for( RevCommit commit : commits) {
versions.add(new Revision(
commit.getName(),
commit.getAuthorIdent().toExternalString(),
new Date(Long.valueOf(commit.getCommitTime()) * 1000 /* convert seconds to milliseconds */),
commit.getFullMessage()
));
}
return versions;
}
示例11: main
import org.eclipse.jgit.api.LogCommand; //导入依赖的package包/类
public static void main(String[] args) throws IOException, GitAPIException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
try (Git git = new Git(repository)) {
List<Ref> call = git.tagList().call();
for (Ref ref : call) {
System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());
// fetch all commits for this tag
LogCommand log = git.log();
Ref peeledRef = repository.peel(ref);
if(peeledRef.getPeeledObjectId() != null) {
log.add(peeledRef.getPeeledObjectId());
} else {
log.add(ref.getObjectId());
}
Iterable<RevCommit> logs = log.call();
for (RevCommit rev : logs) {
System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
}
}
}
}
}
示例12: fixCommitCount
import org.eclipse.jgit.api.LogCommand; //导入依赖的package包/类
private static TagVersionAndCount fixCommitCount(TagVersionAndCount resolved, Repository repo) throws RefNotFoundException, GitAPIException {
Git git = new Git(repo);
ObjectId target, head;
LogCommand logCommand;
try {
target = repo.getRef(resolved.getVersion()).getPeeledObjectId();
logCommand = git.log();
logCommand.add(target);
} catch (IOException e) {
throw new SemverGitflowPlugin.VersionApplicationException(e);
}
int count = 0;
for (RevCommit commit : logCommand.call()) {
count ++;
}
return new TagVersionAndCount(resolved.getVersion(), count);
}
示例13: testSingleFileCommit
import org.eclipse.jgit.api.LogCommand; //导入依赖的package包/类
public void testSingleFileCommit () throws Exception {
repository.getConfig().setString("user", null, "name", "John");
repository.getConfig().setString("user", null, "email", "[email protected]");
repository.getConfig().save();
File toCommit = new File(workDir, "testnotadd.txt");
write(toCommit, "blablabla");
GitClient client = getClient(workDir);
Map<File, GitStatus> statuses = client.getStatus(new File[] { toCommit }, NULL_PROGRESS_MONITOR);
assertStatus(statuses, workDir, toCommit, false, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_ADDED, false);
client.add(new File[] { toCommit }, NULL_PROGRESS_MONITOR);
statuses = client.getStatus(new File[] { toCommit }, NULL_PROGRESS_MONITOR);
assertStatus(statuses, workDir, toCommit, true, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, false);
long t1 = System.currentTimeMillis();
Thread.sleep(1000);
GitRevisionInfo info = client.commit(new File[] { toCommit }, "initial commit", null, null, NULL_PROGRESS_MONITOR);
Thread.sleep(1000);
long t2 = System.currentTimeMillis();
statuses = client.getStatus(new File[] { toCommit }, NULL_PROGRESS_MONITOR);
assertStatus(statuses, workDir, toCommit, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false);
assertTrue(t1 <= info.getCommitTime() && t2 >= info.getCommitTime());
Git git = new Git(repository);
LogCommand log = git.log();
RevCommit com = log.call().iterator().next();
assertEquals("initial commit", info.getFullMessage());
assertEquals("initial commit", com.getFullMessage());
assertEquals( "[email protected]", info.getAuthor().getEmailAddress());
assertEquals( "[email protected]", com.getAuthorIdent().getEmailAddress());
assertEquals(ObjectId.toString(com.getId()), info.getRevision());
Map<File, GitFileInfo> modifiedFiles = info.getModifiedFiles();
assertTrue(modifiedFiles.get(toCommit).getStatus().equals(Status.ADDED));
}
示例14: testSingleTreeCommit
import org.eclipse.jgit.api.LogCommand; //导入依赖的package包/类
public void testSingleTreeCommit () throws Exception {
File folder = new File(workDir, "folder");
File subfolder1 = new File(folder, "subfolder");
File subfolder11 = new File(subfolder1, "subfolder1");
File subfolder12 = new File(subfolder1, "subfolder2");
subfolder11.mkdirs();
subfolder12.mkdirs();
File file1 = new File(subfolder11, "file1");
File file2 = new File(subfolder12, "file2");
write(file1, "file1 content");
write(file2, "file2 content");
File[] files = new File[] { folder };
GitClient client = getClient(workDir);
client.add(files, NULL_PROGRESS_MONITOR);
GitRevisionInfo info = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR);
Map<File, GitFileInfo> modifiedFiles = info.getModifiedFiles();
assertEquals(2, modifiedFiles.size());
assertTrue(modifiedFiles.get(file1).getStatus().equals(Status.ADDED));
assertTrue(modifiedFiles.get(file2).getStatus().equals(Status.ADDED));
Map<File, GitStatus> statuses = client.getStatus(files, NULL_PROGRESS_MONITOR);
assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false);
assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false);
Git git = new Git(repository);
LogCommand log = git.log();
RevCommit com = log.call().iterator().next();
assertEquals("initial commit", com.getFullMessage());
}
示例15: log
import org.eclipse.jgit.api.LogCommand; //导入依赖的package包/类
/** @see org.eclipse.che.api.git.GitConnection#log(LogParams) */
@Override
public LogPage log(LogParams params) throws GitException {
LogCommand logCommand = getGit().log();
try {
setRevisionRange(logCommand, params);
logCommand.setSkip(params.getSkip());
logCommand.setMaxCount(params.getMaxCount());
List<String> fileFilter = params.getFileFilter();
if (fileFilter != null) {
fileFilter.forEach(logCommand::addPath);
}
String filePath = params.getFilePath();
if (!isNullOrEmpty(filePath)) {
logCommand.addPath(filePath);
}
Iterator<RevCommit> revIterator = logCommand.call().iterator();
List<Revision> commits = new ArrayList<>();
while (revIterator.hasNext()) {
RevCommit commit = revIterator.next();
Revision revision = getRevision(commit, filePath);
commits.add(revision);
}
return new LogPage(commits);
} catch (GitAPIException | IOException exception) {
String errorMessage = exception.getMessage();
if (ERROR_LOG_NO_HEAD_EXISTS.equals(errorMessage)) {
throw new GitException(errorMessage, ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED);
} else {
LOG.error("Failed to retrieve log. ", exception);
throw new GitException(exception);
}
}
}