本文整理汇总了Java中org.eclipse.jgit.dircache.DirCache.builder方法的典型用法代码示例。如果您正苦于以下问题:Java DirCache.builder方法的具体用法?Java DirCache.builder怎么用?Java DirCache.builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.dircache.DirCache
的用法示例。
在下文中一共展示了DirCache.builder方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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")));
}
示例3: testResetConflict
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的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());
}
示例4: resetIndex
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的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();
}
示例5: checkoutCacheWithMultiStagesFile_shouldThrowIllegalStateException
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的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);
}
示例6: checkoutCacheWithIgnoringMultiStagesFile_theIgnoredFileShouldNotBeCheckedOut
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的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")));
}
示例7: setupCache
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的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;
}
示例8: addFilesWithDirCacheBuilderTest
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的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);
}
示例9: readBaseTree
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的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;
}
}
示例10: readTree
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的package包/类
private static DirCache readTree(RevWalk rw, ObjectId base) throws IOException {
final DirCache dc = DirCache.newInCore();
final DirCacheBuilder b = dc.builder();
b.addTree(
new byte[0], // no prefix path
DirCacheEntry.STAGE_0, // standard stage
rw.getObjectReader(),
rw.parseTree(base));
b.finish();
return dc;
}
示例11: readTree
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的package包/类
protected DirCache readTree(RevTree tree)
throws IOException, MissingObjectException, IncorrectObjectTypeException {
DirCache dc = DirCache.newInCore();
if (tree != null) {
DirCacheBuilder b = dc.builder();
b.addTree(new byte[0], DirCacheEntry.STAGE_0, reader, tree);
b.finish();
}
return dc;
}
示例12: mergeConflicts
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的package包/类
private void mergeConflicts (List<String> conflicts, DirCache cache) throws GitException {
DirCacheBuilder builder = cache.builder();
DirCacheBuildIterator dci = new DirCacheBuildIterator(builder);
TreeWalk walk = new TreeWalk(getRepository());
ObjectDatabase od = null;
DiffAlgorithm.SupportedAlgorithm diffAlg = getRepository().getConfig().getEnum(
ConfigConstants.CONFIG_DIFF_SECTION, null,
ConfigConstants.CONFIG_KEY_ALGORITHM,
DiffAlgorithm.SupportedAlgorithm.HISTOGRAM);
MergeAlgorithm merger = new MergeAlgorithm(DiffAlgorithm.getAlgorithm(diffAlg));
try {
od = getRepository().getObjectDatabase();
walk.addTree(dci);
walk.setFilter(PathFilterGroup.create(Utils.getPathFilters(conflicts)));
String lastPath = null;
DirCacheEntry[] entries = new DirCacheEntry[3];
walk.setRecursive(true);
while (walk.next()) {
DirCacheEntry e = walk.getTree(0, DirCacheIterator.class).getDirCacheEntry();
String path = e.getPathString();
if (lastPath != null && !lastPath.equals(path)) {
resolveEntries(merger, lastPath, entries, od, builder);
}
if (e.getStage() == 0) {
DirCacheIterator c = walk.getTree(0, DirCacheIterator.class);
builder.add(c.getDirCacheEntry());
} else {
entries[e.getStage() - 1] = e;
lastPath = path;
}
}
resolveEntries(merger, lastPath, entries, od, builder);
builder.commit();
} catch (IOException ex) {
throw new GitException(ex);
} finally {
walk.release();
if (od != null) {
od.close();
}
}
}
示例13: deleteTicketImpl
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的package包/类
/**
* Deletes a ticket from the repository.
*
* @param ticket
* @return true if successful
*/
@Override
protected synchronized boolean deleteTicketImpl(RepositoryModel repository, TicketModel ticket, String deletedBy) {
if (ticket == null) {
throw new RuntimeException("must specify a ticket!");
}
boolean success = false;
Repository db = repositoryManager.getRepository(ticket.repository);
try {
RefModel ticketsBranch = getTicketsBranch(db);
if (ticketsBranch == null) {
throw new RuntimeException(BRANCH + " does not exist!");
}
String ticketPath = toTicketPath(ticket.number);
try {
ObjectId treeId = db.resolve(BRANCH + "^{tree}");
// Create the in-memory index of the new/updated ticket
DirCache index = DirCache.newInCore();
DirCacheBuilder builder = index.builder();
// Traverse HEAD to add all other paths
try (TreeWalk treeWalk = new TreeWalk(db)) {
int hIdx = -1;
if (treeId != null) {
hIdx = treeWalk.addTree(treeId);
}
treeWalk.setRecursive(true);
while (treeWalk.next()) {
String path = treeWalk.getPathString();
CanonicalTreeParser hTree = null;
if (hIdx != -1) {
hTree = treeWalk.getTree(hIdx, CanonicalTreeParser.class);
}
if (!path.startsWith(ticketPath)) {
// add entries from HEAD for all other paths
if (hTree != null) {
final DirCacheEntry entry = new DirCacheEntry(path);
entry.setObjectId(hTree.getEntryObjectId());
entry.setFileMode(hTree.getEntryFileMode());
// add to temporary in-core index
builder.add(entry);
}
}
}
}
// finish temporary in-core index used for this commit
builder.finish();
success = commitIndex(db, index, deletedBy, "- " + ticket.number);
} catch (Throwable t) {
log.error(MessageFormat.format("Failed to delete ticket {0,number,0} from {1}", ticket.number, db.getDirectory()), t);
}
} finally {
db.close();
}
return success;
}