org.eclipse.jgit.diff.DiffAlgorithm Java Examples
The following examples show how to use
org.eclipse.jgit.diff.DiffAlgorithm.
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: 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 #2
Source File: JgitUtils.java From contribution with GNU Lesser General Public License v2.1 | 5 votes |
/** * Generates the differences between the contents of the 2 files. * * @param baseFile * The base file to examine. * @param patchFile * The patch file to examine. * @return The iterator containing the differences. * @throws IOException * if Exceptions occur while reading the file. */ public static Iterator<JgitDifference> getDifferences(File baseFile, File patchFile) throws IOException { if (diffAlgorithm == null) { diffAlgorithm = DiffAlgorithm.getAlgorithm(SupportedAlgorithm.HISTOGRAM); } final RawText baseFileRaw = new RawText(baseFile); final RawText patchFileRaw = new RawText(patchFile); return new JgitDifferenceIterator(diffAlgorithm.diff(RawTextComparator.DEFAULT, baseFileRaw, patchFileRaw), baseFileRaw, patchFileRaw); }
Example #3
Source File: ResolveMerger.java From onedev with MIT License | 4 votes |
private static MergeAlgorithm getMergeAlgorithm(Config config) { SupportedAlgorithm diffAlg = config.getEnum( CONFIG_DIFF_SECTION, null, CONFIG_KEY_ALGORITHM, HISTOGRAM); return new MergeAlgorithm(DiffAlgorithm.getAlgorithm(diffAlg)); }
Example #4
Source File: MergeAlgorithm.java From onedev with MIT License | 2 votes |
/** * Creates a new MergeAlgorithm * * @param diff * the diff algorithm used by this merge */ public MergeAlgorithm(DiffAlgorithm diff) { this.diffAlg = diff; }