org.eclipse.jgit.dircache.DirCacheBuildIterator Java Examples
The following examples show how to use
org.eclipse.jgit.dircache.DirCacheBuildIterator.
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 |
/** * Process the given TreeWalk's entries. * * @param treeWalk * The walk to iterate over. * @param ignoreConflicts * see * {@link org.eclipse.jgit.merge.ResolveMerger#mergeTrees(AbstractTreeIterator, RevTree, RevTree, boolean)} * @return Whether the trees merged cleanly. * @throws java.io.IOException * @since 3.5 */ protected boolean mergeTreeWalk(TreeWalk treeWalk, boolean ignoreConflicts) throws IOException { boolean hasWorkingTreeIterator = tw.getTreeCount() > T_FILE; boolean hasAttributeNodeProvider = treeWalk .getAttributesNodeProvider() != null; while (treeWalk.next()) { if (!processEntry( treeWalk.getTree(T_BASE, CanonicalTreeParser.class), treeWalk.getTree(T_OURS, CanonicalTreeParser.class), treeWalk.getTree(T_THEIRS, CanonicalTreeParser.class), treeWalk.getTree(T_INDEX, DirCacheBuildIterator.class), hasWorkingTreeIterator ? treeWalk.getTree(T_FILE, WorkingTreeIterator.class) : null, ignoreConflicts, hasAttributeNodeProvider ? treeWalk.getAttributes() : NO_ATTRIBUTES)) { cleanUp(); return false; } if (treeWalk.isSubtree() && enterSubtree) treeWalk.enterSubtree(); } return true; }
Example #2
Source File: CherryPickCommand.java From netbeans with Apache License 2.0 | 5 votes |
@Override public ThreeWayMerger newMerger (Repository db, boolean inCore) { return new RecursiveMerger(db, inCore) { protected boolean mergeTreeWalk (TreeWalk treeWalk, boolean ignoreConflicts) throws IOException { boolean ok = true; boolean hasWorkingTreeIterator = tw.getTreeCount() > T_FILE; boolean hasAttributeNodeProvider = treeWalk.getAttributesNodeProvider() != null; while (treeWalk.next()) { if (!processEntry( treeWalk.getTree(T_BASE, CanonicalTreeParser.class), treeWalk.getTree(T_OURS, CanonicalTreeParser.class), treeWalk.getTree(T_THEIRS, CanonicalTreeParser.class), treeWalk.getTree(T_INDEX, DirCacheBuildIterator.class), hasWorkingTreeIterator ? treeWalk.getTree(T_FILE, WorkingTreeIterator.class) : null, ignoreConflicts, hasAttributeNodeProvider ? treeWalk.getAttributes() : NO_ATTRIBUTES )) { ok = false; } if (treeWalk.isSubtree() && enterSubtree) { treeWalk.enterSubtree(); } } if (!ok) { cleanUp(); } return ok; } }; }
Example #3
Source File: CheckoutRevisionCommand.java From netbeans with Apache License 2.0 | 5 votes |
private void mergeConflicts (List<String> conflicts, DirCache cache) throws GitException { DirCacheBuilder builder = cache.builder(); DirCacheBuildIterator dci = new DirCacheBuildIterator(builder); ObjectDatabase od = null; DiffAlgorithm.SupportedAlgorithm diffAlg = getRepository().getConfig().getEnum( ConfigConstants.CONFIG_DIFF_SECTION, null, ConfigConstants.CONFIG_KEY_ALGORITHM, DiffAlgorithm.SupportedAlgorithm.HISTOGRAM); MergeAlgorithm merger = new MergeAlgorithm(DiffAlgorithm.getAlgorithm(diffAlg)); try (TreeWalk walk = new TreeWalk(getRepository());) { od = getRepository().getObjectDatabase(); walk.addTree(dci); walk.setFilter(PathFilterGroup.create(Utils.getPathFilters(conflicts))); String lastPath = null; DirCacheEntry[] entries = new DirCacheEntry[3]; walk.setRecursive(true); while (walk.next()) { DirCacheEntry e = walk.getTree(0, DirCacheIterator.class).getDirCacheEntry(); String path = e.getPathString(); if (lastPath != null && !lastPath.equals(path)) { resolveEntries(merger, lastPath, entries, od, builder); } if (e.getStage() == 0) { DirCacheIterator c = walk.getTree(0, DirCacheIterator.class); builder.add(c.getDirCacheEntry()); } else { entries[e.getStage() - 1] = e; lastPath = path; } } resolveEntries(merger, lastPath, entries, od, builder); builder.commit(); } catch (IOException ex) { throw new GitException(ex); } finally { if (od != null) { od.close(); } } }
Example #4
Source File: ResolveMerger.java From onedev with MIT License | 4 votes |
/** * The resolve conflict way of three way merging * * @param baseTree * a {@link org.eclipse.jgit.treewalk.AbstractTreeIterator} * object. * @param headTree * a {@link org.eclipse.jgit.revwalk.RevTree} object. * @param mergeTree * a {@link org.eclipse.jgit.revwalk.RevTree} object. * @param ignoreConflicts * Controls what to do in case a content-merge is done and a * conflict is detected. The default setting for this should be * <code>false</code>. In this case the working tree file is * filled with new content (containing conflict markers) and the * index is filled with multiple stages containing BASE, OURS and * THEIRS content. Having such non-0 stages is the sign to git * tools that there are still conflicts for that path. * <p> * If <code>true</code> is specified the behavior is different. * In case a conflict is detected the working tree file is again * filled with new content (containing conflict markers). But * also stage 0 of the index is filled with that content. No * other stages are filled. Means: there is no conflict on that * path but the new content (including conflict markers) is * stored as successful merge result. This is needed in the * context of {@link org.eclipse.jgit.merge.RecursiveMerger} * where when determining merge bases we don't want to deal with * content-merge conflicts. * @return whether the trees merged cleanly * @throws java.io.IOException * @since 3.5 */ protected boolean mergeTrees(AbstractTreeIterator baseTree, RevTree headTree, RevTree mergeTree, boolean ignoreConflicts) throws IOException { builder = dircache.builder(); DirCacheBuildIterator buildIt = new DirCacheBuildIterator(builder); tw = new NameConflictTreeWalk(db, reader); tw.addTree(baseTree); tw.addTree(headTree); tw.addTree(mergeTree); int dciPos = tw.addTree(buildIt); if (workingTreeIterator != null) { tw.addTree(workingTreeIterator); workingTreeIterator.setDirCacheIterator(tw, dciPos); } else { tw.setFilter(TreeFilter.ANY_DIFF); } if (!mergeTreeWalk(tw, ignoreConflicts)) { return false; } if (!inCore) { // No problem found. The only thing left to be done is to // checkout all files from "theirs" which have been selected to // go into the new index. checkout(); // All content-merges are successfully done. If we can now write the // new index we are on quite safe ground. Even if the checkout of // files coming from "theirs" fails the user can work around such // failures by checking out the index again. if (!builder.commit()) { cleanUp(); throw new IndexWriteException(); } builder = null; } else { builder.finish(); builder = null; } if (getUnmergedPaths().isEmpty() && !failed()) { resultTree = dircache.writeTree(getObjectInserter()); return true; } resultTree = null; return false; }