本文整理汇总了Java中org.eclipse.jgit.revwalk.RevWalk.parseCommit方法的典型用法代码示例。如果您正苦于以下问题:Java RevWalk.parseCommit方法的具体用法?Java RevWalk.parseCommit怎么用?Java RevWalk.parseCommit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.revwalk.RevWalk
的用法示例。
在下文中一共展示了RevWalk.parseCommit方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLoaderFrom
import org.eclipse.jgit.revwalk.RevWalk; //导入方法依赖的package包/类
/**
* Gets the loader for a file from a specified commit and its path
*
* @param commit
* - the commit from which to get the loader
* @param path
* - the path to the file
* @return the loader
* @throws MissingObjectException
* @throws IncorrectObjectTypeException
* @throws CorruptObjectException
* @throws IOException
*/
public ObjectLoader getLoaderFrom(ObjectId commit, String path)
throws IOException {
Repository repository = git.getRepository();
RevWalk revWalk = new RevWalk(repository);
RevCommit revCommit = revWalk.parseCommit(commit);
// and using commit's tree find the path
RevTree tree = revCommit.getTree();
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(path));
ObjectLoader loader = null;
if (treeWalk.next()) {
ObjectId objectId = treeWalk.getObjectId(0);
loader = repository.open(objectId);
}
treeWalk.close();
revWalk.close();
return loader;
}
示例2: markBranchFlags
import org.eclipse.jgit.revwalk.RevWalk; //导入方法依赖的package包/类
private void markBranchFlags (Map<String, GitBranch> allBranches, RevWalk walk, Map<RevFlag, List<GitBranch>> branchFlags) {
int i = 1;
Set<String> usedFlags = new HashSet<>();
Repository repository = getRepository();
for (Map.Entry<String, GitBranch> e : allBranches.entrySet()) {
if (e.getKey() != GitBranch.NO_BRANCH) {
String flagId = e.getValue().getId();
if (usedFlags.contains(flagId)) {
for (Map.Entry<RevFlag, List<GitBranch>> e2 : branchFlags.entrySet()) {
if (e2.getKey().toString().equals(flagId)) {
e2.getValue().add(e.getValue());
}
}
} else {
usedFlags.add(flagId);
if (i < 25) {
i = i + 1;
RevFlag flag = walk.newFlag(flagId);
List<GitBranch> branches = new ArrayList<>(allBranches.size());
branches.add(e.getValue());
branchFlags.put(flag, branches);
try {
RevCommit branchHeadCommit = walk.parseCommit(repository.resolve(e.getValue().getId()));
branchHeadCommit.add(flag);
branchHeadCommit.carry(flag);
walk.markStart(branchHeadCommit);
} catch (IOException ex) {
LOG.log(Level.INFO, null, ex);
}
} else {
LOG.log(Level.WARNING, "Out of available flags for branches: {0}", allBranches.size()); //NOI18N
break;
}
}
}
}
walk.carry(branchFlags.keySet());
}
示例3: pullRemoteRepo
import org.eclipse.jgit.revwalk.RevWalk; //导入方法依赖的package包/类
/**
* pulls the remote git repository to receive changes.
*/
public void pullRemoteRepo() {
String method = "pullRemoteRepo";
LOGGER.info("Trying to pull remote repository...");
localGit = LocalRepoCreater.getLocalGit();
if (localGit != null) {
Repository repository = localGit.getRepository();
try (Git git = new Git(repository)) {
/*
* Getting The Commit Information of the Remote Repository
*/
RevWalk walker = new RevWalk(repository);
RevCommit commit = walker.parseCommit(repository.getRef("HEAD").getObjectId());
Date commitTime = commit.getAuthorIdent().getWhen();
String commiterName = commit.getAuthorIdent().getName();
String commitEmail = commit.getAuthorIdent().getEmailAddress();
String commitID = repository.getRef("HEAD").getObjectId().getName();
PullResult pullResult = git.pull().setStrategy(MergeStrategy.THEIRS).call();
LOGGER.info("Fetch result: " + pullResult.getFetchResult().getMessages());
LOGGER.info("Merge result: " + pullResult.getMergeResult().toString());
LOGGER.info("Merge status: " + pullResult.getMergeResult().getMergeStatus());
repoDiffer.checkForUpdates(git, commiterName, commitEmail, commitTime, commitID);
} catch (Exception e) {
LOGGER.error("In method " + method + ": Error while pulling remote git repository.", e);
}
localGit.close();
} else {
LOGGER.warn("Repository not cloned yet");
}
}
示例4: getSrcCommit
import org.eclipse.jgit.revwalk.RevWalk; //导入方法依赖的package包/类
public RevCommit getSrcCommit() {
try {
RevWalk revWalk = new RevWalk(git.getRepository());
AnyObjectId headId = git.getRepository().resolve(Constants.HEAD);
RevCommit root = revWalk.parseCommit(headId);
revWalk.sort(RevSort.REVERSE);
revWalk.markStart(root);
return revWalk.next();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: getChangedFiles
import org.eclipse.jgit.revwalk.RevWalk; //导入方法依赖的package包/类
public List<Path> getChangedFiles() throws IOException {
List<Path> changedFiles = new ArrayList<>();
RevWalk revWalk = new RevWalk(git.getRepository());
AnyObjectId headId = git.getRepository().resolve(Constants.HEAD);
RevCommit head = revWalk.parseCommit(headId);
DiffFormatter formatter = new DiffFormatter(null);
formatter.setRepository(git.getRepository());
formatter.setDiffComparator(RawTextComparator.DEFAULT);
formatter.setDetectRenames(true);
List<DiffEntry> entries = formatter.scan(getSrcCommit().getTree(), head);
entries.forEach((diffEntry -> changedFiles.add(Paths.get(diffEntry.getPath(DiffEntry.Side.NEW)))));
return changedFiles;
}
示例6: updateWithRemoteFile
import org.eclipse.jgit.revwalk.RevWalk; //导入方法依赖的package包/类
public void updateWithRemoteFile(String filePath) {
try {
RevWalk walk = new RevWalk(git.getRepository());
walk.reset();
RevCommit commit = walk.parseCommit(git.getRepository().resolve("MERGE_HEAD"));
git.checkout().setStartPoint(commit).addPath(filePath).call();
walk.close();
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug(e, e);
}
}
}
示例7: countCommits
import org.eclipse.jgit.revwalk.RevWalk; //导入方法依赖的package包/类
public int countCommits(Repository repository, String branch) throws Exception {
RevWalk walk = new RevWalk(repository);
try {
Ref ref = repository.findRef(REMOTE_REFS_PREFIX + branch);
ObjectId objectId = ref.getObjectId();
RevCommit start = walk.parseCommit(objectId);
walk.setRevFilter(RevFilter.NO_MERGES);
return RevWalkUtils.count(walk, start, null);
} finally {
walk.dispose();
}
}
示例8: countCommits
import org.eclipse.jgit.revwalk.RevWalk; //导入方法依赖的package包/类
@Override
public int countCommits(Repository repository, String branch) throws Exception {
RevWalk walk = new RevWalk(repository);
try {
Ref ref = repository.findRef(REMOTE_REFS_PREFIX + branch);
ObjectId objectId = ref.getObjectId();
RevCommit start = walk.parseCommit(objectId);
walk.setRevFilter(RevFilter.NO_MERGES);
return RevWalkUtils.count(walk, start, null);
} finally {
walk.dispose();
}
}
示例9: getRepoMetadata
import org.eclipse.jgit.revwalk.RevWalk; //导入方法依赖的package包/类
/**
* Fetch all commit metadata from the repo
* @param repoDir repository directory
* @return list of commit metadata
* @throws IOException
* @throws GitAPIException
*/
public static List<CommitMetadata> getRepoMetadata(String repoDir) throws IOException, GitAPIException {
List<CommitMetadata> metadataList = new ArrayList<>();
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(repoDir, ".git")).readEnvironment().findGitDir().build();
// Current branch may not be master. Instead of hard coding determine the current branch
String currentBranch = repository.getBranch();
Ref head = repository.getRef("refs/heads/" + currentBranch); // current branch may not be "master"
if (head == null) {
return metadataList;
}
Git git = new Git(repository);
RevWalk walk = new RevWalk(repository);
RevCommit commit = walk.parseCommit(head.getObjectId());
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(commit.getTree());
treeWalk.setRecursive(true);
while (treeWalk.next()) {
String filePath = treeWalk.getPathString();
Iterable<RevCommit> commitLog = git.log().add(repository.resolve(Constants.HEAD)).addPath(filePath).call();
for (RevCommit r : commitLog) {
CommitMetadata metadata = new CommitMetadata(r.getName());
metadata.setFilePath(filePath);
metadata.setFileName(FilenameUtils.getName(filePath));
metadata.setMessage(r.getShortMessage().trim());
// Difference between committer and author
// refer to: http://git-scm.com/book/ch2-3.html
PersonIdent committer = r.getCommitterIdent();
PersonIdent author = r.getAuthorIdent();
metadata.setAuthor(author.getName());
metadata.setAuthorEmail(author.getEmailAddress());
metadata.setCommitter(committer.getName());
metadata.setCommitterEmail(committer.getEmailAddress());
metadata.setCommitTime(committer.getWhen());
metadataList.add(metadata);
}
}
git.close();
return metadataList;
}
示例10: testAmendCommit
import org.eclipse.jgit.revwalk.RevWalk; //导入方法依赖的package包/类
public void testAmendCommit () throws Exception {
repository.getConfig().setString("user", null, "name", "John");
repository.getConfig().setString("user", null, "email", "[email protected]");
repository.getConfig().save();
File dir = new File(workDir, "testdir");
File newOne = new File(dir, "test.txt");
File another = new File(dir, "test2.txt");
dir.mkdirs();
write(newOne, "content1");
write(another, "content2");
GitClient client = getClient(workDir);
client.add(new File[] { newOne, another }, NULL_PROGRESS_MONITOR);
GitRevisionInfo info = client.commit(new File[] { newOne, another }, "initial commit", null, null, NULL_PROGRESS_MONITOR);
Map<File, GitStatus> statuses = client.getStatus(new File[] { newOne, another }, NULL_PROGRESS_MONITOR);
assertStatus(statuses, workDir, newOne, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false);
assertStatus(statuses, workDir, another, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false);
write(newOne, "modification1");
write(another, "modification2");
client.add(new File[] { newOne, another }, NULL_PROGRESS_MONITOR);
GitRevisionInfo lastCommit = client.commit(new File[] { newOne }, "second commit", null, null, false, NULL_PROGRESS_MONITOR);
statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR);
assertStatus(statuses, workDir, newOne, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false);
assertStatus(statuses, workDir, another, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false);
Map<File, GitFileInfo> modifiedFiles = lastCommit.getModifiedFiles();
assertTrue(modifiedFiles.get(newOne).getStatus().equals(Status.MODIFIED));
assertNull(modifiedFiles.get(another));
assertEquals(1, lastCommit.getParents().length);
assertEquals(info.getRevision(), lastCommit.getParents()[0]);
assertEquals(lastCommit.getRevision(), client.getBranches(false, NULL_PROGRESS_MONITOR).get("master").getId());
Thread.sleep(1100);
long time = lastCommit.getCommitTime();
RevWalk walk = new RevWalk(repository);
RevCommit originalCommit = walk.parseCommit(repository.resolve(lastCommit.getRevision()));
lastCommit = client.commit(new File[] { newOne, another }, "second commit, modified message",
new GitUser("user2", "user2.email"), new GitUser("committer2", "committer2.email"), true, NULL_PROGRESS_MONITOR);
RevCommit amendedCommit = walk.parseCommit(repository.resolve(lastCommit.getRevision()));
assertEquals("Commit time should not change after amend", time, lastCommit.getCommitTime());
assertEquals(originalCommit.getAuthorIdent().getWhen(), amendedCommit.getAuthorIdent().getWhen());
// commit time should not equal.
assertFalse(originalCommit.getCommitterIdent().getWhen().equals(amendedCommit.getCommitterIdent().getWhen()));
statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR);
assertStatus(statuses, workDir, newOne, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false);
assertStatus(statuses, workDir, another, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false);
modifiedFiles = lastCommit.getModifiedFiles();
assertTrue(modifiedFiles.get(newOne).getStatus().equals(Status.MODIFIED));
assertTrue(modifiedFiles.get(another).getStatus().equals(Status.MODIFIED));
assertEquals(1, lastCommit.getParents().length);
assertEquals(info.getRevision(), lastCommit.getParents()[0]);
assertEquals(lastCommit.getRevision(), client.getBranches(false, NULL_PROGRESS_MONITOR).get("master").getId());
}
示例11: getHead
import org.eclipse.jgit.revwalk.RevWalk; //导入方法依赖的package包/类
public RevCommit getHead() throws IOException {
RevWalk revWalk = new RevWalk(git.getRepository());
AnyObjectId headId = git.getRepository().resolve(Constants.HEAD);
RevCommit head = revWalk.parseCommit(headId);
return head;
}
示例12: getCommit
import org.eclipse.jgit.revwalk.RevWalk; //导入方法依赖的package包/类
/**
* Returns the SHA-1 commit id for a file by specifying what commit to get for
* that file and it's path
*
* @param commit
* - specifies the commit to return(MINE, THEIRS, BASE, LOCAL)
* @param path
* - the file path for the specified commit
* @return the SHA-1 commit id
*/
public ObjectId getCommit(Commit commit, String path) {
List<DiffEntry> entries;
boolean baseIsNull = false;
int index = 0;
try {
entries = git.diff().setPathFilter(PathFilter.create(path)).call();
if (entries.size() == 2) {
baseIsNull = true;
}
if (commit == Commit.MINE) {
if (baseIsNull) {
index = 0;
} else {
index = 1;
}
return entries.get(index).getOldId().toObjectId();
} else if (commit == Commit.THEIRS) {
if (baseIsNull) {
index = 1;
} else {
index = 2;
}
return entries.get(index).getOldId().toObjectId();
} else if (commit == Commit.BASE) {
return entries.get(index).getOldId().toObjectId();
} else if (commit == Commit.LOCAL) {
ObjectId lastLocalCommit = getLastLocalCommit();
RevWalk revWalk = new RevWalk(git.getRepository());
RevCommit revCommit = revWalk.parseCommit(lastLocalCommit);
RevTree tree = revCommit.getTree();
TreeWalk treeWalk = new TreeWalk(git.getRepository());
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(path));
ObjectId objectId = null;
if (treeWalk.next()) {
objectId = treeWalk.getObjectId(0);
}
treeWalk.close();
revWalk.close();
return objectId;
}
} catch (GitAPIException |IOException e) {
if (logger.isDebugEnabled()) {
logger.debug(e, e);
}
}
return null;
}