List of usage examples for org.eclipse.jgit.treewalk TreeWalk isRecursive
public boolean isRecursive()
From source file:org.eclipse.egit.core.synchronize.ThreeWayDiffEntry.java
License:Open Source License
/** * Converts the TreeWalk into TreeWayDiffEntry headers. * * @param walk// w ww. j av a 2s . c o m * the TreeWalk to walk through. Must have exactly three trees in * this order: local, base and remote and can't be recursive. * @return headers describing the changed file. * @throws IOException * the repository cannot be accessed. * @throws IllegalArgumentException * when {@code walk} doen't have exactly three trees, or when * {@code walk} is recursive */ public static List<ThreeWayDiffEntry> scan(TreeWalk walk) throws IOException { if (walk.getTreeCount() != 3 && walk.getTreeCount() != 4) throw new IllegalArgumentException("TreeWalk need to have three or four trees"); //$NON-NLS-1$ if (walk.isRecursive()) throw new IllegalArgumentException("TreeWalk shouldn't be recursive."); //$NON-NLS-1$ List<ThreeWayDiffEntry> r = new ArrayList<ThreeWayDiffEntry>(); MutableObjectId idBuf = new MutableObjectId(); while (walk.next()) { ThreeWayDiffEntry e = new ThreeWayDiffEntry(); walk.getObjectId(idBuf, 0); e.localId = AbbreviatedObjectId.fromObjectId(idBuf); walk.getObjectId(idBuf, 1); e.baseId = AbbreviatedObjectId.fromObjectId(idBuf); walk.getObjectId(idBuf, 2); e.remoteId = AbbreviatedObjectId.fromObjectId(idBuf); boolean localSameAsBase = e.localId.equals(e.baseId); if (!A_ZERO.equals(e.localId) && localSameAsBase && e.baseId.equals(e.remoteId)) continue; e.path = walk.getPathString(); boolean localIsMissing = walk.getFileMode(0) == FileMode.MISSING; boolean baseIsMissing = walk.getFileMode(1) == FileMode.MISSING; boolean remoteIsMissing = walk.getFileMode(2) == FileMode.MISSING; if (localIsMissing || baseIsMissing || remoteIsMissing) { if (!localIsMissing && baseIsMissing && remoteIsMissing) { e.direction = Direction.OUTGOING; e.changeType = ChangeType.ADD; } else if (localIsMissing && baseIsMissing && !remoteIsMissing) { e.direction = Direction.INCOMING; e.changeType = ChangeType.ADD; } else if (!localIsMissing && !baseIsMissing && remoteIsMissing) { e.direction = Direction.INCOMING; e.changeType = ChangeType.DELETE; } else if (localIsMissing && !baseIsMissing && !remoteIsMissing) { e.direction = Direction.OUTGOING; e.changeType = ChangeType.DELETE; } else { e.direction = Direction.CONFLICTING; e.changeType = ChangeType.MODIFY; } } else { if (localSameAsBase && !e.localId.equals(e.remoteId)) e.direction = Direction.INCOMING; else if (e.remoteId.equals(e.baseId) && !e.remoteId.equals(e.localId)) e.direction = Direction.OUTGOING; else e.direction = Direction.CONFLICTING; e.changeType = ChangeType.MODIFY; } r.add(e); if (walk.isSubtree()) { e.isTree = true; walk.enterSubtree(); } } return r; }