本文整理汇总了Java中org.eclipse.jgit.dircache.DirCache类的典型用法代码示例。如果您正苦于以下问题:Java DirCache类的具体用法?Java DirCache怎么用?Java DirCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DirCache类属于org.eclipse.jgit.dircache包,在下文中一共展示了DirCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.eclipse.jgit.dircache.DirCache; //导入依赖的package包/类
@Override
protected void run() throws GitException {
Repository repository = getRepository();
DirCache cache = null;
try {
// cache must be locked because checkout index may modify its entries
cache = repository.lockDirCache();
DirCacheBuilder builder = cache.builder();
if (cache.getEntryCount() > 0) {
builder.keep(0, cache.getEntryCount());
}
builder.finish();
new CheckoutIndex(repository, cache, roots, recursively, listener, monitor, true).checkout();
// cache must be saved to disk because checkout index may modify its entries
builder.commit();
} catch (IOException ex) {
throw new GitException(ex);
} finally {
if (cache != null) {
cache.unlock();
}
}
}
示例2: deleteIfUnversioned
import org.eclipse.jgit.dircache.DirCache; //导入依赖的package包/类
private void deleteIfUnversioned(DirCache cache, String path, WorkingTreeIterator f, Repository repository, TreeWalk treeWalk) throws IOException, NoWorkTreeException {
if (cache.getEntry(path) == null && // not in index
!f.isEntryIgnored() && // not ignored
!Utils.isFromNested(f.getEntryFileMode().getBits()))
{
File file = new File(repository.getWorkTree().getAbsolutePath() + File.separator + path);
if(file.isDirectory()) {
String[] s = file.list();
if(s != null && s.length > 0) { // XXX is there no better way to find out if empty?
// not empty
return;
}
}
file.delete();
listener.notifyFile(file, treeWalk.getPathString());
}
}
示例3: testJGitCheckout
import org.eclipse.jgit.dircache.DirCache; //导入依赖的package包/类
public void testJGitCheckout () throws Exception {
File file1 = new File(workDir, "file1");
write(file1, "blablablabla");
Git git = new Git(repository);
org.eclipse.jgit.api.AddCommand cmd = git.add();
cmd.addFilepattern("file1");
cmd.call();
org.eclipse.jgit.api.CommitCommand commitCmd = git.commit();
commitCmd.setAuthor("author", "[email protected]");
commitCmd.setMessage("commit message");
commitCmd.call();
String commitId = git.log().call().iterator().next().getId().getName();
DirCache cache = repository.lockDirCache();
try {
DirCacheCheckout checkout = new DirCacheCheckout(repository, null, cache, new RevWalk(repository).parseCommit(repository.resolve(commitId)).getTree());
checkout.checkout();
} finally {
cache.unlock();
}
}
示例4: checkJGitFix
import org.eclipse.jgit.dircache.DirCache; //导入依赖的package包/类
private void checkJGitFix (String branch, File file) throws Exception {
ObjectId headTree = null;
try {
headTree = Utils.findCommit(repository, Constants.HEAD).getTree();
} catch (GitException.MissingObjectException ex) { }
DirCache cache = repository.lockDirCache();
RevCommit commit;
commit = Utils.findCommit(repository, branch);
DirCacheCheckout dco = new DirCacheCheckout(repository, headTree, cache, commit.getTree());
dco.setFailOnConflict(false);
dco.checkout();
if (file.exists()) {
// and do not forget to remove WA in checkout command when JGit is fixed.
fail("Hey, JGit is fixed, why don't you fix me as well?");
}
cache.unlock();
}
示例5: assertDirCacheEntryModified
import org.eclipse.jgit.dircache.DirCache; //导入依赖的package包/类
private void assertDirCacheEntryModified (Collection<File> files) throws IOException {
DirCache cache = repository.lockDirCache();
for (File f : files) {
String relativePath = Utils.getRelativePath(workDir, f);
DirCacheEntry e = cache.getEntry(relativePath);
assertNotNull(e);
assertEquals(relativePath, e.getPathString());
InputStream in = new FileInputStream(f);
try {
assertNotSame(e.getObjectId(), repository.newObjectInserter().idFor(Constants.OBJ_BLOB, f.length(), in));
} finally {
in.close();
}
}
cache.unlock();
}
示例6: assertDirCacheEntry
import org.eclipse.jgit.dircache.DirCache; //导入依赖的package包/类
protected static void assertDirCacheEntry (Repository repository, File workDir, Collection<File> files) throws IOException {
DirCache cache = repository.lockDirCache();
for (File f : files) {
String relativePath = Utils.getRelativePath(workDir, f);
DirCacheEntry e = cache.getEntry(relativePath);
assertNotNull(e);
assertEquals(relativePath, e.getPathString());
if (f.lastModified() != e.getLastModified()) {
assertEquals((f.lastModified() / 1000) * 1000, (e.getLastModified() / 1000) * 1000);
}
try (InputStream in = new FileInputStream(f)) {
assertEquals(e.getObjectId(), repository.newObjectInserter().idFor(Constants.OBJ_BLOB, f.length(), in));
}
if (e.getLength() == 0 && f.length() != 0) {
assertTrue(e.isSmudged());
} else {
assertEquals(f.length(), e.getLength());
}
}
cache.unlock();
}
示例7: blockingPreviewDiff
import org.eclipse.jgit.dircache.DirCache; //导入依赖的package包/类
private Map<String, Change<?>> blockingPreviewDiff(Revision baseRevision, Iterable<Change<?>> changes) {
requireNonNull(baseRevision, "baseRevision");
requireNonNull(changes, "changes");
baseRevision = blockingNormalize(baseRevision);
try (ObjectReader reader = jGitRepository.newObjectReader();
RevWalk revWalk = new RevWalk(reader);
DiffFormatter diffFormatter = new DiffFormatter(NullOutputStream.INSTANCE)) {
final ObjectId baseTreeId = toTreeId(revWalk, baseRevision);
final DirCache dirCache = DirCache.newInCore();
final int numEdits = applyChanges(baseRevision, baseTreeId, dirCache, changes);
if (numEdits == 0) {
return Collections.emptyMap();
}
CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(reader, baseTreeId);
diffFormatter.setRepository(jGitRepository);
List<DiffEntry> result = diffFormatter.scan(p, new DirCacheIterator(dirCache));
return toChangeMap(result);
} catch (IOException e) {
throw new StorageException("failed to perform a dry-run diff", e);
}
}
示例8: findEntrys
import org.eclipse.jgit.dircache.DirCache; //导入依赖的package包/类
private DirCacheEntry[] findEntrys(Repository repository, String path) throws IOException {
DirCache dirCache = repository.readDirCache();
int eIdx = dirCache.findEntry(path);
if (eIdx < 0) {
throw new GitInvalidPathException(format("%s is not found in git index", path));
}
int lastIdx = dirCache.nextEntry(eIdx);
final DirCacheEntry[] entries = new DirCacheEntry[lastIdx - eIdx];
for (int i=0; i<entries.length; i++) {
entries[i] = dirCache.getEntry(eIdx + i);
}
return entries;
}
示例9: prepareTreeParser
import org.eclipse.jgit.dircache.DirCache; //导入依赖的package包/类
private AbstractTreeIterator prepareTreeParser(Repository repository, String ref) throws IOException {
if ("~~staged~~".equals(ref)) {
return new DirCacheIterator(DirCache.read(repository));
} else if ("~~unstaged~~".equals(ref)) {
return new FileTreeIterator(repository);
}
try (RevWalk walk = new RevWalk(repository)) {
ObjectId commitObjectId = repository.resolve(ref);
if (commitObjectId == null) {
throw new GitInvalidRefException(format("invalid git ref %s", ref));
}
log.debug("ref: {}, commit id: {}", ref, commitObjectId.toString());
RevCommit commit = walk.parseCommit(commitObjectId);
RevTree tree = walk.parseTree(commit.getTree().getId());
CanonicalTreeParser treeParser = new CanonicalTreeParser();
try (ObjectReader objectReader = repository.newObjectReader()) {
treeParser.reset(objectReader, tree.getId());
}
return treeParser;
}
}
示例10: getProjectList
import org.eclipse.jgit.dircache.DirCache; //导入依赖的package包/类
public List<String> getProjectList(String projectName){
FileRepositoryBuilder builder = new FileRepositoryBuilder();
List list= new ArrayList();
try {
log.debug("errororororoor123 "+ "\n");
Repository repository = builder
.readEnvironment() // scan environment GIT_* variables
.setGitDir(new File("C:/test0101/" + projectName +"/.git")) // scan up the file system tree
.build();
DirCache index = DirCache.read(repository);
ObjectLoader loader = null;
log.debug("DirCache has " + index.getEntryCount() + " items");
for (int i = 0; i < index.getEntryCount(); i++) {
log.debug(index.getEntry(i).getPathString()+ "\n");
list.add(index.getEntry(i).getPathString());
}
} catch (IOException e) {
log.debug("errororororoor "+ "\n");
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
示例11: addAndCommitSelectedFiles
import org.eclipse.jgit.dircache.DirCache; //导入依赖的package包/类
/**
* Adds the files that were selected and commits them. Note: the {@link AddCommand}
* and {@link CommitCommand} are used in this method. {@link AddCommand#setWorkingTreeIterator(WorkingTreeIterator)}
* can be configured fia {@link #setWorkingTreeIterator(WorkingTreeIterator)} before calling this method,
* and the {@code CommitCommand} can be configured via {@link #configureCommitCommand(CommitCommand)}.
* @return the result of {@link #createResult(DirCache, RevCommit, List)} or null if
* a {@link GitAPIException} is thrown.
*/
protected final R addAndCommitSelectedFiles() {
List<String> selectedFiles = getDialogPane().getSelectedFiles();
try {
AddCommand add = getGitOrThrow().add();
selectedFiles.forEach(add::addFilepattern);
workingTreeIterator.ifPresent(add::setWorkingTreeIterator);
DirCache cache = add.call();
CommitCommand commit = getGitOrThrow().commit();
configureCommitCommand(commit);
RevCommit revCommit = commit.call();
return createResult(cache, revCommit, selectedFiles);
} catch (GitAPIException e) {
handleGitAPIException(e);
return null;
}
}
示例12: checkpoint
import org.eclipse.jgit.dircache.DirCache; //导入依赖的package包/类
@Override
public Revision checkpoint(String pattern, String commitMessage, AuthenticationInfo subject) {
Revision revision = Revision.EMPTY;
try {
List<DiffEntry> gitDiff = git.diff().call();
if (!gitDiff.isEmpty()) {
LOG.debug("Changes found for pattern '{}': {}", pattern, gitDiff);
DirCache added = git.add().addFilepattern(pattern).call();
LOG.debug("{} changes are about to be commited", added.getEntryCount());
RevCommit commit = git.commit().setMessage(commitMessage).call();
revision = new Revision(commit.getName(), commit.getShortMessage(), commit.getCommitTime());
} else {
LOG.debug("No changes found {}", pattern);
}
} catch (GitAPIException e) {
LOG.error("Failed to add+commit {} to Git", pattern, e);
}
return revision;
}
示例13: checkoutCacheWithIgnoringSomeFile_theIgnoredFileShouldNotBeCheckedOut
import org.eclipse.jgit.dircache.DirCache; //导入依赖的package包/类
@Test
public void checkoutCacheWithIgnoringSomeFile_theIgnoredFileShouldNotBeCheckedOut() throws IOException {
initGitFileSystem("/some_existing_file.txt");
DirCache cache = DirCache.newInCore();
DirCacheBuilder builder = cache.builder();
builder.add(someEntry("/test_file1.txt"));
builder.add(someEntry("/test_file2.txt"));
builder.add(someEntry("/test_file3.txt"));
builder.finish();
new GfsDefaultCheckout(gfs).ignoredFiles(singleton("/test_file2.txt")).checkout(cache);
assertTrue(Files.exists(gfs.getPath("/test_file1.txt")));
assertFalse(Files.exists(gfs.getPath("/test_file2.txt")));
assertTrue(Files.exists(gfs.getPath("/test_file3.txt")));
}
示例14: deleteFilesWithDirCacheEditorTest
import org.eclipse.jgit.dircache.DirCache; //导入依赖的package包/类
@Test
public void deleteFilesWithDirCacheEditorTest() {
DirCache cache = setupCache("a/b/c1.txt",
"a/b/c2.txt",
"a/c3.txt",
"a/c4.txt",
"a/c5.txt",
"a/c6.txt");
DirCacheEditor editor = cache.editor();
CacheUtils.deleteFile("a/b/c1.txt", editor);
CacheUtils.deleteFile("a/c3.txt", editor);
CacheUtils.deleteFile("a/c4.txt", editor);
CacheUtils.deleteFile("a/c6.txt", editor);
editor.finish();
assertEquals(2, cache.getEntryCount());
assertNull(cache.getEntry("a/b/c1.txt"));
assertNotNull(cache.getEntry("a/b/c2.txt"));
assertNotNull(cache.getEntry("a/c5.txt"));
}
示例15: deleteTreeTest
import org.eclipse.jgit.dircache.DirCache; //导入依赖的package包/类
@Test
public void deleteTreeTest() {
DirCache cache = setupCache("a/b/c1.txt",
"a/b/c2.txt",
"a/c3.txt",
"a/c4.txt",
"a/c5.txt",
"a/c6.txt");
CacheUtils.deleteDirectory("a/b", cache);
assertEquals(4, cache.getEntryCount());
assertNull(cache.getEntry("a/b/c1.txt"));
assertNull(cache.getEntry("a/b/c2.txt"));
assertNotNull(cache.getEntry("a/c3.txt"));
assertNotNull(cache.getEntry("a/c4.txt"));
assertNotNull(cache.getEntry("a/c5.txt"));
assertNotNull(cache.getEntry("a/c6.txt"));
}