当前位置: 首页>>代码示例>>Java>>正文


Java DirCacheEditor类代码示例

本文整理汇总了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;
}
 
开发者ID:link-intersystems,项目名称:GitDirStat,代码行数:31,代码来源:CacheTreeUpdate.java

示例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"));
}
 
开发者ID:beijunyi,项目名称:ParallelGit,代码行数:22,代码来源:CacheUtilsEditTest.java

示例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"));
}
 
开发者ID:beijunyi,项目名称:ParallelGit,代码行数:19,代码来源:CacheUtilsEditTest.java

示例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);
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:RenameFileModification.java

示例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();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:VersionedMetaData.java

示例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);
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:27,代码来源:CreateMoveCommitTree.java

示例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);
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:21,代码来源:CreateRevertCommitTree.java

示例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;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:8,代码来源:TreeCreator.java

示例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);
    }
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:8,代码来源:BaseCreateCommitTree.java

示例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);
        }
    });
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:13,代码来源:BaseCreateCommitTree.java

示例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);
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:30,代码来源:CreateCopyCommitTree.java

示例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();
}
 
开发者ID:line,项目名称:centraldogma,代码行数:6,代码来源:GitRepository.java

示例13: delete

import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
@Override
public void delete() {
	DirCacheEditor.DeletePath deletePath = new DirCacheEditor.DeletePath(
			dirCacheEntry);
	cacheTreeUpdate.registerPathEdit(deletePath);
}
 
开发者ID:link-intersystems,项目名称:GitDirStat,代码行数:7,代码来源:CacheTreeFileUpdate.java

示例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());
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:52,代码来源:AccountsOnInit.java

示例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);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:6,代码来源:ChangeFileContentModification.java


注:本文中的org.eclipse.jgit.dircache.DirCacheEditor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。