• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DirCacheEditor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.jgit.dircache.DirCacheEditor的典型用法代码示例。如果您正苦于以下问题:Java DirCacheEditor类的具体用法?Java DirCacheEditor怎么用?Java DirCacheEditor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DirCacheEditor类属于org.eclipse.jgit.dircache包,在下文中一共展示了DirCacheEditor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: getPathEdits

import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
@Override
public List<DirCacheEditor.PathEdit> getPathEdits(Repository repository, RevCommit baseCommit) {
  DirCacheEditor.DeletePath deletePathEdit = new DirCacheEditor.DeletePath(filePath);
  return Collections.singletonList(deletePathEdit);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:6,代码来源:DeleteFileModification.java


示例17: createNewTree

import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
private DirCache createNewTree(Repository repository) throws IOException {
  DirCache newTree = readBaseTree(repository);
  List<DirCacheEditor.PathEdit> pathEdits = getPathEdits(repository);
  applyPathEdits(newTree, pathEdits);
  return newTree;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:7,代码来源:TreeCreator.java


示例18: applyPathEdits

import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
private static void applyPathEdits(DirCache tree, List<DirCacheEditor.PathEdit> pathEdits) {
  DirCacheEditor dirCacheEditor = tree.editor();
  pathEdits.forEach(dirCacheEditor::add);
  dirCacheEditor.finish();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:6,代码来源:TreeCreator.java


示例19: composeGitlinksCommit

import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
/** Create a separate gitlink commit */
public CodeReviewCommit composeGitlinksCommit(Branch.NameKey subscriber)
    throws IOException, SubmoduleException {
  OpenRepo or;
  try {
    or = orm.getRepo(subscriber.getParentKey());
  } catch (NoSuchProjectException | IOException e) {
    throw new SubmoduleException("Cannot access superproject", e);
  }

  CodeReviewCommit currentCommit;
  if (branchTips.containsKey(subscriber)) {
    currentCommit = branchTips.get(subscriber);
  } else {
    Ref r = or.repo.exactRef(subscriber.get());
    if (r == null) {
      throw new SubmoduleException(
          "The branch was probably deleted from the subscriber repository");
    }
    currentCommit = or.rw.parseCommit(r.getObjectId());
    addBranchTip(subscriber, currentCommit);
  }

  StringBuilder msgbuf = new StringBuilder("");
  PersonIdent author = null;
  DirCache dc = readTree(or.rw, currentCommit);
  DirCacheEditor ed = dc.editor();
  for (SubmoduleSubscription s : targets.get(subscriber)) {
    RevCommit newCommit = updateSubmodule(dc, ed, msgbuf, s);
    if (newCommit != null) {
      if (author == null) {
        author = newCommit.getAuthorIdent();
      } else if (!author.equals(newCommit.getAuthorIdent())) {
        author = myIdent;
      }
    }
  }
  ed.finish();
  ObjectId newTreeId = dc.writeTree(or.ins);

  // Gitlinks are already in the branch, return null
  if (newTreeId.equals(currentCommit.getTree())) {
    return null;
  }
  CommitBuilder commit = new CommitBuilder();
  commit.setTreeId(newTreeId);
  commit.setParentId(currentCommit);
  StringBuilder commitMsg = new StringBuilder("Update git submodules\n\n");
  if (verboseSuperProject != VerboseSuperprojectUpdate.FALSE) {
    commitMsg.append(msgbuf);
  }
  commit.setMessage(commitMsg.toString());
  commit.setAuthor(author);
  commit.setCommitter(myIdent);
  ObjectId id = or.ins.insert(commit);
  return or.rw.parseCommit(id);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:58,代码来源:SubmoduleOp.java


示例20: updateSubmodule

import org.eclipse.jgit.dircache.DirCacheEditor; //导入依赖的package包/类
private RevCommit updateSubmodule(
    DirCache dc, DirCacheEditor ed, StringBuilder msgbuf, SubmoduleSubscription s)
    throws SubmoduleException, IOException {
  OpenRepo subOr;
  try {
    subOr = orm.getRepo(s.getSubmodule().getParentKey());
  } catch (NoSuchProjectException | IOException e) {
    throw new SubmoduleException("Cannot access submodule", e);
  }

  DirCacheEntry dce = dc.getEntry(s.getPath());
  RevCommit oldCommit = null;
  if (dce != null) {
    if (!dce.getFileMode().equals(FileMode.GITLINK)) {
      String errMsg =
          "Requested to update gitlink "
              + s.getPath()
              + " in "
              + s.getSubmodule().getParentKey().get()
              + " but entry "
              + "doesn't have gitlink file mode.";
      throw new SubmoduleException(errMsg);
    }
    oldCommit = subOr.rw.parseCommit(dce.getObjectId());
  }

  final CodeReviewCommit newCommit;
  if (branchTips.containsKey(s.getSubmodule())) {
    newCommit = branchTips.get(s.getSubmodule());
  } else {
    Ref ref = subOr.repo.getRefDatabase().exactRef(s.getSubmodule().get());
    if (ref == null) {
      ed.add(new DeletePath(s.getPath()));
      return null;
    }
    newCommit = subOr.rw.parseCommit(ref.getObjectId());
    addBranchTip(s.getSubmodule(), newCommit);
  }

  if (Objects.equals(newCommit, oldCommit)) {
    // gitlink have already been updated for this submodule
    return null;
  }
  ed.add(
      new PathEdit(s.getPath()) {
        @Override
        public void apply(DirCacheEntry ent) {
          ent.setFileMode(FileMode.GITLINK);
          ent.setObjectId(newCommit.getId());
        }
      });

  if (verboseSuperProject != VerboseSuperprojectUpdate.FALSE) {
    createSubmoduleCommitMsg(msgbuf, s, subOr, newCommit, oldCommit);
  }
  subOr.rw.parseBody(newCommit);
  return newCommit;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:59,代码来源:SubmoduleOp.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Vector类代码示例发布时间:2022-05-22
下一篇:
Java CommonTermsQuery类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap