Java Code Examples for org.eclipse.jgit.dircache.DirCache#newInCore()

The following examples show how to use org.eclipse.jgit.dircache.DirCache#newInCore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResolveMerger.java    From onedev with MIT License 6 votes vote down vote up
/**
 * Constructor for ResolveMerger.
 *
 * @param local
 *            the {@link org.eclipse.jgit.lib.Repository}.
 * @param inCore
 *            a boolean.
 */
protected ResolveMerger(Repository local, boolean inCore) {
	super(local);
	Config config = local.getConfig();
	mergeAlgorithm = getMergeAlgorithm(config);
	inCoreLimit = getInCoreLimit(config);
	commitNames = defaultCommitNames();
	this.inCore = inCore;

	if (inCore) {
		implicitDirCache = false;
		dircache = DirCache.newInCore();
	} else {
		implicitDirCache = true;
		workingTreeOptions = local.getConfig().get(WorkingTreeOptions.KEY);
	}
}
 
Example 2
Source File: GfsDefaultCheckoutCacheTest.java    From ParallelGit with Apache License 2.0 6 votes vote down vote up
@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")));
}
 
Example 3
Source File: GfsDefaultCheckoutCacheTest.java    From ParallelGit with Apache License 2.0 6 votes vote down vote up
@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")));
}
 
Example 4
Source File: GfsDefaultCheckoutCacheTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@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")));
}
 
Example 5
Source File: GitRepository.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
private Map<String, Change<?>> blockingPreviewDiff(Revision baseRevision, Iterable<Change<?>> changes) {
    requireNonNull(baseRevision, "baseRevision");
    requireNonNull(changes, "changes");
    baseRevision = normalizeNow(baseRevision);

    readLock();
    try (ObjectReader reader = jGitRepository.newObjectReader();
         RevWalk revWalk = newRevWalk(reader);
         DiffFormatter diffFormatter = new DiffFormatter(null)) {

        final ObjectId baseTreeId = toTree(revWalk, baseRevision);
        final DirCache dirCache = DirCache.newInCore();
        final int numEdits = applyChanges(baseRevision, baseTreeId, dirCache, changes);
        if (numEdits == 0) {
            return Collections.emptyMap();
        }

        final CanonicalTreeParser p = new CanonicalTreeParser();
        p.reset(reader, baseTreeId);
        diffFormatter.setRepository(jGitRepository);
        final List<DiffEntry> result = diffFormatter.scan(p, new DirCacheIterator(dirCache));
        return toChangeMap(result);
    } catch (IOException e) {
        throw new StorageException("failed to perform a dry-run diff", e);
    } finally {
        readUnlock();
    }
}
 
Example 6
Source File: GfsDefaultCheckoutCacheTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 7
Source File: GfsDefaultCheckoutCacheTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@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")));
}
 
Example 8
Source File: GfsDefaultCheckoutCacheTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 9
Source File: CacheUtilsEditTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 10
Source File: CacheUtilsEditTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 11
Source File: CacheUtilsEditTest.java    From ParallelGit with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 12
Source File: AbstractParallelGitTest.java    From ParallelGit with Apache License 2.0 4 votes vote down vote up
@Before
public void setUpCache() {
  cache = DirCache.newInCore();
}
 
Example 13
Source File: GfsDefaultCheckoutCacheTest.java    From ParallelGit with Apache License 2.0 4 votes vote down vote up
@Nonnull
private DirCache createCacheWithFile(String path) throws IOException {
  DirCache cache = DirCache.newInCore();
  CacheUtils.addFile(path, REGULAR_FILE, someObjectId(), cache);
  return cache;
}
 
Example 14
Source File: AbstractParallelGitTest.java    From ParallelGit with Apache License 2.0 4 votes vote down vote up
protected void clearCache() {
  cache = DirCache.newInCore();
}
 
Example 15
Source File: AbstractParallelGitTest.java    From ParallelGit with Apache License 2.0 4 votes vote down vote up
protected void clearCache() {
  cache = DirCache.newInCore();
}
 
Example 16
Source File: GfsDefaultCheckoutCacheTest.java    From ParallelGit with Apache License 2.0 4 votes vote down vote up
@Nonnull
private DirCache createCacheWithFile(String path) throws IOException {
  DirCache cache = DirCache.newInCore();
  CacheUtils.addFile(path, REGULAR_FILE, someObjectId(), cache);
  return cache;
}
 
Example 17
Source File: GfsDefaultCheckoutTreeTest.java    From ParallelGit with Apache License 2.0 4 votes vote down vote up
@Nonnull
private ObjectId createTreeWithFile(String path, byte[] bytes) throws IOException {
  DirCache cache = DirCache.newInCore();
  CacheUtils.addFile(path, REGULAR_FILE, BlobUtils.insertBlob(bytes, repo), cache);
  return CacheUtils.writeTree(cache, repo);
}
 
Example 18
Source File: StrategySimpleTwoWayInCore.java    From onedev with MIT License 4 votes vote down vote up
InCoreMerger(ObjectInserter inserter) {
	super(inserter);
	tw = new NameConflictTreeWalk(null, reader);
	cache = DirCache.newInCore();
}
 
Example 19
Source File: StrategySimpleTwoWayInCore.java    From onedev with MIT License 4 votes vote down vote up
InCoreMerger(Repository local) {
	super(local);
	tw = new NameConflictTreeWalk(local, reader);
	cache = DirCache.newInCore();
}
 
Example 20
Source File: ResolveMerger.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Constructor for ResolveMerger.
 *
 * @param inserter
 *            an {@link org.eclipse.jgit.lib.ObjectInserter} object.
 * @param config
 *            the repository configuration
 * @since 4.8
 */
protected ResolveMerger(ObjectInserter inserter, Config config) {
	super(inserter);
	mergeAlgorithm = getMergeAlgorithm(config);
	commitNames = defaultCommitNames();
	inCore = true;
	implicitDirCache = false;
	dircache = DirCache.newInCore();
}