本文整理汇总了Java中org.eclipse.jgit.dircache.DirCacheBuilder类的典型用法代码示例。如果您正苦于以下问题:Java DirCacheBuilder类的具体用法?Java DirCacheBuilder怎么用?Java DirCacheBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DirCacheBuilder类属于org.eclipse.jgit.dircache包,在下文中一共展示了DirCacheBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.eclipse.jgit.dircache.DirCacheBuilder; //导入依赖的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: buildDirCache
import org.eclipse.jgit.dircache.DirCacheBuilder; //导入依赖的package包/类
private void buildDirCache(TreeWalk walk, DirCacheBuilder builder)
throws MissingObjectException, IncorrectObjectTypeException,
CorruptObjectException, IOException {
while (walk.next()) {
AbstractTreeIterator cIter = walk.getTree(0,
AbstractTreeIterator.class);
if (cIter == null) {
// Not in commit, don't add to new index
continue;
}
final DirCacheEntry entry = new DirCacheEntry(walk.getRawPath());
entry.setFileMode(cIter.getEntryFileMode());
entry.setObjectIdFromRaw(cIter.idBuffer(), cIter.idOffset());
DirCacheIterator dcIter = walk.getTree(1, DirCacheIterator.class);
if (dcIter != null && dcIter.idEqual(cIter)) {
DirCacheEntry indexEntry = dcIter.getDirCacheEntry();
entry.setLastModified(indexEntry.getLastModified());
entry.setLength(indexEntry.getLength());
}
builder.add(entry);
}
}
示例3: checkoutCacheWithIgnoringSomeFile_theIgnoredFileShouldNotBeCheckedOut
import org.eclipse.jgit.dircache.DirCacheBuilder; //导入依赖的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")));
}
示例4: writeLargeFile_shouldWork
import org.eclipse.jgit.dircache.DirCacheBuilder; //导入依赖的package包/类
@Test
public void writeLargeFile_shouldWork() throws IOException {
repoDir = FileUtils.createTempDir(getClass().getSimpleName(), null, null);
repo = RepositoryUtils.createRepository(repoDir, true);
DirCacheBuilder builder = CacheUtils.keepEverything(cache);
byte[] largeData = new byte[50*1024*1024+1];
Random random = new Random();
random.nextBytes(largeData);
AnyObjectId blobId = BlobUtils.insertBlob(largeData, repo);
addFile("large.txt", REGULAR_FILE, blobId, builder);
builder.finish();
commitToMaster();
initGitFileSystemForBranch(MASTER);
byte[] data = someBytes();
Path file = gfs.getPath("/large.txt");
Files.write(file, data, APPEND);
}
示例5: dirCacheAltersId
import org.eclipse.jgit.dircache.DirCacheBuilder; //导入依赖的package包/类
@Test
public void dirCacheAltersId() throws Exception {
assertEquals(
"a\n"
+ //
"\n"
+ //
"Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n", //
call("a\n"));
final DirCacheBuilder builder = repository.lockDirCache().builder();
builder.add(file("A"));
assertTrue(builder.commit());
assertEquals(
"a\n"
+ //
"\n"
+ //
"Change-Id: If56597ea9759f23b070677ea6f064c60c38da631\n", //
call("a\n"));
}
示例6: createTreeDirCache
import org.eclipse.jgit.dircache.DirCacheBuilder; //导入依赖的package包/类
private DirCache createTreeDirCache(Map<SubtreeConfig, RevCommit> parentCommits,
String commitMessage) throws IOException {
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.setRecursive(true);
addTrees(parentCommits, treeWalk);
DirCacheBuilder builder = DirCache.newInCore().builder();
while (treeWalk.next()) {
AbstractTreeIterator iterator = getSingleTreeIterator(treeWalk, commitMessage);
if (iterator == null) {
throw new IllegalStateException(
"Tree walker did not return a single tree (should not happen): "
+ treeWalk.getPathString());
}
byte[] path = Arrays.copyOf(iterator.getEntryPathBuffer(),
iterator.getEntryPathLength());
DirCacheEntry entry = new DirCacheEntry(path);
entry.setFileMode(iterator.getEntryFileMode());
entry.setObjectId(iterator.getEntryObjectId());
builder.add(entry);
}
builder.finish();
return builder.getDirCache();
}
}
示例7: testResetConflict
import org.eclipse.jgit.dircache.DirCacheBuilder; //导入依赖的package包/类
public void testResetConflict () throws Exception {
File file = new File(workDir, "file");
write(file, "init");
File[] files = new File[] { file };
add(files);
commit(files);
DirCache index = repository.lockDirCache();
DirCacheBuilder builder = index.builder();
DirCacheEntry e = index.getEntry(file.getName());
DirCacheEntry e1 = new DirCacheEntry(file.getName(), 1);
e1.setCreationTime(e.getCreationTime());
e1.setFileMode(e.getFileMode());
e1.setLastModified(e.getLastModified());
e1.setLength(e.getLength());
e1.setObjectId(e.getObjectId());
builder.add(e1);
builder.finish();
builder.commit();
GitClient client = getClient(workDir);
Map<File, GitStatus> status = client.getStatus(files, NULL_PROGRESS_MONITOR);
assertTrue(status.get(file).isConflict());
assertEquals(GitConflictDescriptor.Type.BOTH_DELETED, status.get(file).getConflictDescriptor().getType());
client.reset(files, "HEAD", true, NULL_PROGRESS_MONITOR);
status = client.getStatus(files, NULL_PROGRESS_MONITOR);
assertFalse(status.get(file).isConflict());
}
示例8: resetIndex
import org.eclipse.jgit.dircache.DirCacheBuilder; //导入依赖的package包/类
private void resetIndex(RevCommit revCommit, DirCache dirCache)
throws IOException {
TreeWalk walk = new TreeWalk(cachingObjectReader);
walk.setRecursive(true);
RevTree revTree = revCommit.getTree();
walk.addTree(revTree);
DirCacheBuilder builder = dirCache.builder();
walk.addTree(new DirCacheIterator(dirCache));
buildDirCache(walk, builder);
builder.finish();
}
示例9: checkoutCacheWithMultiStagesFile_shouldThrowIllegalStateException
import org.eclipse.jgit.dircache.DirCacheBuilder; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
public void checkoutCacheWithMultiStagesFile_shouldThrowIllegalStateException() throws IOException {
initGitFileSystem("/some_existing_file.txt");
DirCache cache = DirCache.newInCore();
DirCacheBuilder builder = cache.builder();
builder.add(someEntry("/test_file.txt", STAGE_1));
builder.add(someEntry("/test_file.txt", STAGE_2));
builder.add(someEntry("/test_file.txt", STAGE_3));
builder.finish();
new GfsDefaultCheckout(gfs).checkout(cache);
}
示例10: checkoutCacheWithIgnoringMultiStagesFile_theIgnoredFileShouldNotBeCheckedOut
import org.eclipse.jgit.dircache.DirCacheBuilder; //导入依赖的package包/类
@Test
public void checkoutCacheWithIgnoringMultiStagesFile_theIgnoredFileShouldNotBeCheckedOut() throws IOException {
initGitFileSystem("/some_existing_file.txt");
DirCache cache = DirCache.newInCore();
DirCacheBuilder builder = cache.builder();
builder.add(someEntry("/test_file.txt", STAGE_1));
builder.add(someEntry("/test_file.txt", STAGE_2));
builder.add(someEntry("/test_file.txt", STAGE_3));
builder.finish();
new GfsDefaultCheckout(gfs).ignoredFiles(singleton("/test_file.txt")).checkout(cache);
assertFalse(Files.exists(gfs.getPath("/test_file.txt")));
}
示例11: writeMultipleToCache
import org.eclipse.jgit.dircache.DirCacheBuilder; //导入依赖的package包/类
protected void writeMultipleToCache(String... paths) throws IOException {
DirCacheBuilder builder = CacheUtils.keepEverything(cache);
for(String path : paths) {
AnyObjectId blobId = repo != null ? BlobUtils.insertBlob(someBytes(), repo) : someObjectId();
addFile(path, REGULAR_FILE, blobId, builder);
}
builder.finish();
}
示例12: setupCache
import org.eclipse.jgit.dircache.DirCacheBuilder; //导入依赖的package包/类
@Nonnull
private static DirCache setupCache(String... files) {
DirCache cache = DirCache.newInCore();
DirCacheBuilder builder = cache.builder();
for(String file : files)
CacheUtils.addFile(file, REGULAR_FILE, zeroId(), builder);
builder.finish();
return cache;
}
示例13: keepEverything_ExistingEntriesShouldBeKept
import org.eclipse.jgit.dircache.DirCacheBuilder; //导入依赖的package包/类
@Test
public void keepEverything_ExistingEntriesShouldBeKept() throws IOException {
writeMultipleToCache("/file1.txt", "/file2.txt");
DirCacheBuilder builder = CacheUtils.keepEverything(cache);
builder.finish();
assertNotNull(CacheUtils.getEntry("/file1.txt", cache));
assertNotNull(CacheUtils.getEntry("/file2.txt", cache));
}
示例14: addFilesWithDirCacheBuilderTest
import org.eclipse.jgit.dircache.DirCacheBuilder; //导入依赖的package包/类
@Test
public void addFilesWithDirCacheBuilderTest() {
DirCache cache = DirCache.newInCore();
DirCacheBuilder builder = cache.builder();
String[] files = new String[] {"a/b/c1.txt",
"a/c2.txt",
"a/c3.txt",
"a/b/c4.txt"};
for(String file : files)
CacheUtils.addFile(file, REGULAR_FILE, zeroId(), builder);builder.finish();
int entryCount = cache.getEntryCount();
assertEquals(4, entryCount);
}
示例15: readBaseTree
import org.eclipse.jgit.dircache.DirCacheBuilder; //导入依赖的package包/类
private DirCache readBaseTree(Repository repository) throws IOException {
try (ObjectReader objectReader = repository.newObjectReader()) {
DirCache dirCache = DirCache.newInCore();
DirCacheBuilder dirCacheBuilder = dirCache.builder();
dirCacheBuilder.addTree(
new byte[0], DirCacheEntry.STAGE_0, objectReader, baseCommit.getTree());
dirCacheBuilder.finish();
return dirCache;
}
}