本文整理汇总了Java中org.eclipse.jgit.dircache.DirCache.unlock方法的典型用法代码示例。如果您正苦于以下问题:Java DirCache.unlock方法的具体用法?Java DirCache.unlock怎么用?Java DirCache.unlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.dircache.DirCache
的用法示例。
在下文中一共展示了DirCache.unlock方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testJGitCheckout
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的package包/类
public void testJGitCheckout () throws Exception {
File file1 = new File(workDir, "file1");
write(file1, "blablablabla");
Git git = new Git(repository);
org.eclipse.jgit.api.AddCommand cmd = git.add();
cmd.addFilepattern("file1");
cmd.call();
org.eclipse.jgit.api.CommitCommand commitCmd = git.commit();
commitCmd.setAuthor("author", "[email protected]");
commitCmd.setMessage("commit message");
commitCmd.call();
String commitId = git.log().call().iterator().next().getId().getName();
DirCache cache = repository.lockDirCache();
try {
DirCacheCheckout checkout = new DirCacheCheckout(repository, null, cache, new RevWalk(repository).parseCommit(repository.resolve(commitId)).getTree());
checkout.checkout();
} finally {
cache.unlock();
}
}
示例3: checkJGitFix
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的package包/类
private void checkJGitFix (String branch, File file) throws Exception {
ObjectId headTree = null;
try {
headTree = Utils.findCommit(repository, Constants.HEAD).getTree();
} catch (GitException.MissingObjectException ex) { }
DirCache cache = repository.lockDirCache();
RevCommit commit;
commit = Utils.findCommit(repository, branch);
DirCacheCheckout dco = new DirCacheCheckout(repository, headTree, cache, commit.getTree());
dco.setFailOnConflict(false);
dco.checkout();
if (file.exists()) {
// and do not forget to remove WA in checkout command when JGit is fixed.
fail("Hey, JGit is fixed, why don't you fix me as well?");
}
cache.unlock();
}
示例4: assertDirCacheEntryModified
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的package包/类
private void assertDirCacheEntryModified (Collection<File> files) throws IOException {
DirCache cache = repository.lockDirCache();
for (File f : files) {
String relativePath = Utils.getRelativePath(workDir, f);
DirCacheEntry e = cache.getEntry(relativePath);
assertNotNull(e);
assertEquals(relativePath, e.getPathString());
InputStream in = new FileInputStream(f);
try {
assertNotSame(e.getObjectId(), repository.newObjectInserter().idFor(Constants.OBJ_BLOB, f.length(), in));
} finally {
in.close();
}
}
cache.unlock();
}
示例5: assertDirCacheEntry
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的package包/类
protected static void assertDirCacheEntry (Repository repository, File workDir, Collection<File> files) throws IOException {
DirCache cache = repository.lockDirCache();
for (File f : files) {
String relativePath = Utils.getRelativePath(workDir, f);
DirCacheEntry e = cache.getEntry(relativePath);
assertNotNull(e);
assertEquals(relativePath, e.getPathString());
if (f.lastModified() != e.getLastModified()) {
assertEquals((f.lastModified() / 1000) * 1000, (e.getLastModified() / 1000) * 1000);
}
try (InputStream in = new FileInputStream(f)) {
assertEquals(e.getObjectId(), repository.newObjectInserter().idFor(Constants.OBJ_BLOB, f.length(), in));
}
if (e.getLength() == 0 && f.length() != 0) {
assertTrue(e.isSmudged());
} else {
assertEquals(f.length(), e.getLength());
}
}
cache.unlock();
}
示例6: assertNullDirCacheEntry
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的package包/类
private void assertNullDirCacheEntry (Collection<File> files) throws Exception {
DirCache cache = repository.lockDirCache();
for (File f : files) {
DirCacheEntry e = cache.getEntry(Utils.getRelativePath(workDir, f));
assertNull(e);
}
cache.unlock();
}
示例7: assertDirCacheSize
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的package包/类
private void assertDirCacheSize (int expectedSize) throws IOException {
DirCache cache = repository.lockDirCache();
try {
assertEquals(expectedSize, cache.getEntryCount());
} finally {
cache.unlock();
}
}
示例8: indexToWorkingTree
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的package包/类
/**
* Show changes between index and working tree.
*
* @param formatter diff formatter
* @return list of diff entries
* @throws IOException if any i/o errors occurs
*/
private List<DiffEntry> indexToWorkingTree(DiffFormatter formatter) throws IOException {
DirCache dirCache = null;
ObjectReader reader = repository.newObjectReader();
List<DiffEntry> diff;
try {
dirCache = repository.lockDirCache();
DirCacheIterator iterA = new DirCacheIterator(dirCache);
FileTreeIterator iterB = new FileTreeIterator(repository);
// Seems bug in DiffFormatter when work with working. Disable detect
// renames by formatter and do it later.
formatter.setDetectRenames(false);
diff = formatter.scan(iterA, iterB);
if (!params.isNoRenames()) {
// Detect renames.
RenameDetector renameDetector = createRenameDetector();
ContentSource.Pair sourcePairReader =
new ContentSource.Pair(ContentSource.create(reader), ContentSource.create(iterB));
renameDetector.addAll(diff);
diff = renameDetector.compute(sourcePairReader, NullProgressMonitor.INSTANCE);
}
} finally {
reader.close();
if (dirCache != null) {
dirCache.unlock();
}
}
return diff;
}
示例9: commitToIndex
import org.eclipse.jgit.dircache.DirCache; //导入方法依赖的package包/类
/**
* Show changes between specified revision and index. If <code>commitId == null</code> then view
* changes between HEAD and index.
*
* @param commitId id of commit, pass <code>null</code> is the same as pass HEAD
* @param formatter diff formatter
* @return list of diff entries
* @throws IOException if any i/o errors occurs
*/
private List<DiffEntry> commitToIndex(String commitId, DiffFormatter formatter)
throws IOException {
if (commitId == null) {
commitId = Constants.HEAD;
}
ObjectId commitA = repository.resolve(commitId);
if (commitA == null) {
throw new IllegalArgumentException("Invalid commit id " + commitId);
}
RevTree treeA;
try (RevWalk revWalkA = new RevWalk(repository)) {
treeA = revWalkA.parseTree(commitA);
}
DirCache dirCache = null;
List<DiffEntry> diff;
try (ObjectReader reader = repository.newObjectReader()) {
dirCache = repository.lockDirCache();
CanonicalTreeParser iterA = new CanonicalTreeParser();
iterA.reset(reader, treeA);
DirCacheIterator iterB = new DirCacheIterator(dirCache);
if (!params.isNoRenames()) {
// Use embedded RenameDetector it works well with index and
// revision history.
formatter.setDetectRenames(true);
int renameLimit = params.getRenameLimit();
if (renameLimit > 0) {
formatter.getRenameDetector().setRenameLimit(renameLimit);
}
}
diff = formatter.scan(iterA, iterB);
} finally {
if (dirCache != null) {
dirCache.unlock();
}
}
return diff;
}