本文整理汇总了Java中org.eclipse.jgit.dircache.DirCacheEditor类的典型用法代码示例。如果您正苦于以下问题:Java DirCacheEditor类的具体用法?Java DirCacheEditor怎么用?Java DirCacheEditor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DirCacheEditor类属于org.eclipse.jgit.dircache包,在下文中一共展示了DirCacheEditor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
/**
* Apply the changes that this {@link TreeUpdate} represents to the given
* {@link DirCache}. The {@link DirCache} will be unlocked if was modified.
*
* @param dirCache
* @return true if updates are applied to the {@link DirCache}, false if the
* {@link DirCache} has not been modified.
*/
public ObjectId apply(ObjectInserter objectInserter) {
ObjectId newTreeId = null;
if (hasUpdates()) {
DirCacheEditor editor = index.editor();
for (PathEdit pathEdit : pathEdits) {
editor.add(pathEdit);
}
editor.finish();
try {
// Write the index as tree to the object database. This may
// fail for example when the index contains unmerged paths
// (unresolved conflicts)
newTreeId = index.writeTree(objectInserter);
} catch (IOException e) {
throw new GitRepositoryException(e);
}
}
return newTreeId;
}
示例2: deleteFilesWithDirCacheEditorTest
import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的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"));
}
示例3: deleteMultipleTreesTest
import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
@Test
public void deleteMultipleTreesTest() {
DirCache cache = setupCache("a/b/c1.txt",
"a/b/c2.txt",
"a/d/c3.txt",
"a/d/c4.txt",
"a/c5.txt",
"a/c6.txt");
DirCacheEditor editor = cache.editor();
CacheUtils.deleteDirectory("a/b", editor);
CacheUtils.deleteDirectory("a/d", editor);
editor.finish();
assertEquals(2, cache.getEntryCount());
assertNotNull(cache.getEntry("a/c5.txt"));
assertNotNull(cache.getEntry("a/c6.txt"));
}
示例4: getPathEdits
import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
@Override
public List<DirCacheEditor.PathEdit> getPathEdits(Repository repository, RevCommit baseCommit)
throws IOException {
try (RevWalk revWalk = new RevWalk(repository)) {
revWalk.parseHeaders(baseCommit);
try (TreeWalk treeWalk =
TreeWalk.forPath(revWalk.getObjectReader(), currentFilePath, baseCommit.getTree())) {
if (treeWalk == null) {
return Collections.emptyList();
}
DirCacheEditor.DeletePath deletePathEdit = new DirCacheEditor.DeletePath(currentFilePath);
AddPath addPathEdit =
new AddPath(newFilePath, treeWalk.getFileMode(0), treeWalk.getObjectId(0));
return Arrays.asList(deletePathEdit, addPathEdit);
}
}
}
示例5: saveFile
import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
protected void saveFile(String fileName, byte[] raw) throws IOException {
DirCacheEditor editor = newTree.editor();
if (raw != null && 0 < raw.length) {
final ObjectId blobId = inserter.insert(Constants.OBJ_BLOB, raw);
editor.add(
new PathEdit(fileName) {
@Override
public void apply(DirCacheEntry ent) {
ent.setFileMode(FileMode.REGULAR_FILE);
ent.setObjectId(blobId);
}
});
} else {
editor.add(new DeletePath(fileName));
}
editor.finish();
}
示例6: execute
import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
public Optional<ObjectId> execute() {
final Map<String, String> content = commitContent.getContent();
final DirCacheEditor editor = DirCache.newInCore().editor();
final List<String> pathsAdded = new ArrayList<>();
try {
iterateOverTreeWalk(git,
headId,
(walkPath, hTree) -> {
final String toPath = content.get(walkPath);
final DirCacheEntry dcEntry = new DirCacheEntry((toPath == null) ? walkPath : toPath);
if (!pathsAdded.contains(dcEntry.getPathString())) {
addToTemporaryInCoreIndex(editor,
dcEntry,
hTree.getEntryObjectId(),
hTree.getEntryFileMode());
pathsAdded.add(dcEntry.getPathString());
}
});
editor.finish();
} catch (final Exception e) {
throw new RuntimeException(e);
}
return buildTree(editor);
}
示例7: execute
import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
public Optional<ObjectId> execute() {
final DirCacheEditor editor = DirCache.newInCore().editor();
try {
iterateOverTreeWalk(git,
headId,
(walkPath, hTree) -> {
addToTemporaryInCoreIndex(editor,
new DirCacheEntry(walkPath),
hTree.getEntryObjectId(),
hTree.getEntryFileMode());
});
editor.finish();
} catch (final Exception e) {
throw new RuntimeException(e);
}
return buildTree(editor);
}
示例8: getPathEdits
import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
private List<DirCacheEditor.PathEdit> getPathEdits(Repository repository) throws IOException {
List<DirCacheEditor.PathEdit> pathEdits = new ArrayList<>();
for (TreeModification treeModification : treeModifications) {
pathEdits.addAll(treeModification.getPathEdits(repository, baseCommit));
}
return pathEdits;
}
示例9: buildTree
import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
Optional<ObjectId> buildTree(final DirCacheEditor editor) {
try {
return Optional.ofNullable(editor.getDirCache().writeTree(odi));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例10: addToTemporaryInCoreIndex
import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
void addToTemporaryInCoreIndex(final DirCacheEditor editor,
final DirCacheEntry dcEntry,
final ObjectId objectId,
final FileMode fileMode) {
editor.add(new DirCacheEditor.PathEdit(dcEntry) {
@Override
public void apply(final DirCacheEntry ent) {
ent.setObjectId(objectId);
ent.setFileMode(fileMode);
}
});
}
示例11: execute
import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
public Optional<ObjectId> execute() {
final Map<String, String> content = commitContent.getContent();
final DirCacheEditor editor = DirCache.newInCore().editor();
try {
iterateOverTreeWalk(git,
headId,
(walkPath, hTree) -> {
final String toPath = content.get(walkPath);
addToTemporaryInCoreIndex(editor,
new DirCacheEntry(walkPath),
hTree.getEntryObjectId(),
hTree.getEntryFileMode());
if (toPath != null) {
addToTemporaryInCoreIndex(editor,
new DirCacheEntry(toPath),
hTree.getEntryObjectId(),
hTree.getEntryFileMode());
}
});
editor.finish();
} catch (final Exception e) {
throw new RuntimeException(e);
}
return buildTree(editor);
}
示例12: applyPathEdit
import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
private static void applyPathEdit(DirCache dirCache, PathEdit edit) {
final DirCacheEditor e = dirCache.editor();
e.add(edit);
e.finish();
}
示例13: delete
import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
@Override
public void delete() {
DirCacheEditor.DeletePath deletePath = new DirCacheEditor.DeletePath(
dirCacheEntry);
cacheTreeUpdate.registerPathEdit(deletePath);
}
示例14: insert
import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
public void insert(Account account) throws IOException {
File path = getPath();
if (path != null) {
try (Repository repo = new FileRepository(path);
ObjectInserter oi = repo.newObjectInserter()) {
PersonIdent ident =
new PersonIdent(
new GerritPersonIdentProvider(flags.cfg).get(), account.getRegisteredOn());
Config accountConfig = new Config();
AccountConfig.writeToConfig(account, accountConfig);
DirCache newTree = DirCache.newInCore();
DirCacheEditor editor = newTree.editor();
final ObjectId blobId =
oi.insert(Constants.OBJ_BLOB, accountConfig.toText().getBytes(UTF_8));
editor.add(
new PathEdit(AccountConfig.ACCOUNT_CONFIG) {
@Override
public void apply(DirCacheEntry ent) {
ent.setFileMode(FileMode.REGULAR_FILE);
ent.setObjectId(blobId);
}
});
editor.finish();
ObjectId treeId = newTree.writeTree(oi);
CommitBuilder cb = new CommitBuilder();
cb.setTreeId(treeId);
cb.setCommitter(ident);
cb.setAuthor(ident);
cb.setMessage("Create Account");
ObjectId id = oi.insert(cb);
oi.flush();
String refName = RefNames.refsUsers(account.getId());
RefUpdate ru = repo.updateRef(refName);
ru.setExpectedOldObjectId(ObjectId.zeroId());
ru.setNewObjectId(id);
ru.setRefLogIdent(ident);
ru.setRefLogMessage("Create Account", false);
Result result = ru.update();
if (result != Result.NEW) {
throw new IOException(
String.format("Failed to update ref %s: %s", refName, result.name()));
}
account.setMetaId(id.name());
}
}
}
示例15: getPathEdits
import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
@Override
public List<DirCacheEditor.PathEdit> getPathEdits(Repository repository, RevCommit baseCommit) {
DirCacheEditor.PathEdit changeContentEdit = new ChangeContent(filePath, newContent, repository);
return Collections.singletonList(changeContentEdit);
}