List of usage examples for org.eclipse.jgit.lib FileMode MISSING
FileMode MISSING
To view the source code for org.eclipse.jgit.lib FileMode MISSING.
Click Source Link
From source file:MyDiffFormatter.java
License:Eclipse Distribution License
private byte[] open(DiffEntry.Side side, DiffEntry entry) throws IOException { if (entry.getMode(side) == FileMode.MISSING) return EMPTY; if (entry.getMode(side).getObjectType() != Constants.OBJ_BLOB) return EMPTY; AbbreviatedObjectId id = entry.getId(side); if (!id.isComplete()) { Collection<ObjectId> ids = reader.resolve(id); if (ids.size() == 1) { throw new IllegalStateException(); // id = AbbreviatedObjectId.fromObjectId(ids.iterator().next()); // switch (side) { // case OLD: // entry.oldId = id; // break; // case NEW: // entry.newId = id; // break; // } } else if (ids.size() == 0) throw new MissingObjectException(id, Constants.OBJ_BLOB); else//from w w w . ja va2 s. c o m throw new AmbiguousObjectException(id, ids); } try { ObjectLoader ldr = source.open(side, entry); int binaryFileThreshold = DEFAULT_BINARY_FILE_THRESHOLD; return ldr.getBytes(binaryFileThreshold); } catch (LargeObjectException.ExceedsLimit overLimit) { return BINARY; } catch (LargeObjectException.ExceedsByteArrayLimit overLimit) { return BINARY; } catch (LargeObjectException.OutOfMemory tooBig) { return BINARY; } catch (LargeObjectException tooBig) { tooBig.setObjectId(id.toObjectId()); throw tooBig; } }
From source file:com.gitblit.models.PathModel.java
License:Apache License
public boolean isFile() { return FileMode.REGULAR_FILE.equals(mode) || FileMode.EXECUTABLE_FILE.equals(mode) || (FileMode.MISSING.equals(mode) && !isSymlink() && !isSubmodule() && !isTree()); }
From source file:com.gitblit.tests.JGitUtilsTest.java
License:Apache License
@Test public void testFileModes() throws Exception { assertEquals("drwxr-xr-x", JGitUtils.getPermissionsFromMode(FileMode.TREE.getBits())); assertEquals("-rw-r--r--", JGitUtils.getPermissionsFromMode(FileMode.REGULAR_FILE.getBits())); assertEquals("-rwxr-xr-x", JGitUtils.getPermissionsFromMode(FileMode.EXECUTABLE_FILE.getBits())); assertEquals("symlink", JGitUtils.getPermissionsFromMode(FileMode.SYMLINK.getBits())); assertEquals("submodule", JGitUtils.getPermissionsFromMode(FileMode.GITLINK.getBits())); assertEquals("missing", JGitUtils.getPermissionsFromMode(FileMode.MISSING.getBits())); }
From source file:com.googlesource.gerrit.plugins.uploadvalidator.DuplicatePathnameValidator.java
License:Apache License
private static boolean isDeleted(TreeWalk tw) { return FileMode.MISSING.equals(tw.getRawMode(0)); }
From source file:com.itemis.maven.plugins.unleash.scm.providers.merge.UnleashGitMerger.java
License:Eclipse Distribution License
/** * Processes one path and tries to merge. This method will do all do all * trivial (not content) merges and will also detect if a merge will fail. * The merge will fail when one of the following is true * <ul>/*from w w w . ja va2 s .c om*/ * <li>the index entry does not match the entry in ours. When merging one * branch into the current HEAD, ours will point to HEAD and theirs will * point to the other branch. It is assumed that the index matches the HEAD * because it will only not match HEAD if it was populated before the merge * operation. But the merge commit should not accidentally contain * modifications done before the merge. Check the <a href= * "http://www.kernel.org/pub/software/scm/git/docs/git-read-tree.html#_3_way_merge" * >git read-tree</a> documentation for further explanations.</li> * <li>A conflict was detected and the working-tree file is dirty. When a * conflict is detected the content-merge algorithm will try to write a * merged version into the working-tree. If the file is dirty we would * override unsaved data.</li> * </ul> * * @param base * the common base for ours and theirs * @param ours * the ours side of the merge. When merging a branch into the * HEAD ours will point to HEAD * @param theirs * the theirs side of the merge. When merging a branch into the * current HEAD theirs will point to the branch which is merged * into HEAD. * @param index * the index entry * @param work * the file in the working tree * @param ignoreConflicts * see * {@link UnleashGitMerger#mergeTrees(AbstractTreeIterator, RevTree, RevTree, boolean)} * @return <code>false</code> if the merge will fail because the index entry * didn't match ours or the working-dir file was dirty and a * conflict occurred * @throws MissingObjectException * @throws IncorrectObjectTypeException * @throws CorruptObjectException * @throws IOException * @since 3.5 */ @Override protected boolean processEntry(CanonicalTreeParser base, CanonicalTreeParser ours, CanonicalTreeParser theirs, DirCacheBuildIterator index, WorkingTreeIterator work, boolean ignoreConflicts) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { this.enterSubtree = true; final int modeO = this.tw.getRawMode(T_OURS); final int modeT = this.tw.getRawMode(T_THEIRS); final int modeB = this.tw.getRawMode(T_BASE); if (modeO == 0 && modeT == 0 && modeB == 0) { // File is either untracked or new, staged but uncommitted return true; } if (isIndexDirty()) { return false; } DirCacheEntry ourDce = null; if (index == null || index.getDirCacheEntry() == null) { // create a fake DCE, but only if ours is valid. ours is kept only // in case it is valid, so a null ourDce is ok in all other cases. if (nonTree(modeO)) { ourDce = new DirCacheEntry(this.tw.getRawPath()); ourDce.setObjectId(this.tw.getObjectId(T_OURS)); ourDce.setFileMode(this.tw.getFileMode(T_OURS)); } } else { ourDce = index.getDirCacheEntry(); } if (nonTree(modeO) && nonTree(modeT) && this.tw.idEqual(T_OURS, T_THEIRS)) { // OURS and THEIRS have equal content. Check the file mode if (modeO == modeT) { // content and mode of OURS and THEIRS are equal: it doesn't // matter which one we choose. OURS is chosen. Since the index // is clean (the index matches already OURS) we can keep the existing one keep(ourDce); // no checkout needed! return true; } else { // same content but different mode on OURS and THEIRS. // Try to merge the mode and report an error if this is // not possible. int newMode = mergeFileModes(modeB, modeO, modeT); if (newMode != FileMode.MISSING.getBits()) { if (newMode == modeO) { // ours version is preferred keep(ourDce); } else { // the preferred version THEIRS has a different mode // than ours. Check it out! if (isWorktreeDirty(work, ourDce)) { return false; } // we know about length and lastMod only after we have written the new content. // This will happen later. Set these values to 0 for know. DirCacheEntry e = add(this.tw.getRawPath(), theirs, DirCacheEntry.STAGE_0, 0, 0); this.toBeCheckedOut.put(this.tw.getPathString(), e); } return true; } else { // FileModes are not mergeable. We found a conflict on modes. // For conflicting entries we don't know lastModified and length. add(this.tw.getRawPath(), base, DirCacheEntry.STAGE_1, 0, 0); add(this.tw.getRawPath(), ours, DirCacheEntry.STAGE_2, 0, 0); add(this.tw.getRawPath(), theirs, DirCacheEntry.STAGE_3, 0, 0); this.unmergedPaths.add(this.tw.getPathString()); this.mergeResults.put(this.tw.getPathString(), new MergeResult<RawText>(Collections.<RawText>emptyList())); } return true; } } if (modeB == modeT && this.tw.idEqual(T_BASE, T_THEIRS)) { // THEIRS was not changed compared to BASE. All changes must be in // OURS. OURS is chosen. We can keep the existing entry. if (ourDce != null) { keep(ourDce); } // no checkout needed! return true; } if (modeB == modeO && this.tw.idEqual(T_BASE, T_OURS)) { // OURS was not changed compared to BASE. All changes must be in // THEIRS. THEIRS is chosen. // Check worktree before checking out THEIRS if (isWorktreeDirty(work, ourDce)) { return false; } if (nonTree(modeT)) { // we know about length and lastMod only after we have written // the new content. // This will happen later. Set these values to 0 for know. DirCacheEntry e = add(this.tw.getRawPath(), theirs, DirCacheEntry.STAGE_0, 0, 0); if (e != null) { this.toBeCheckedOut.put(this.tw.getPathString(), e); } return true; } else { // we want THEIRS ... but THEIRS contains a folder or the // deletion of the path. Delete what's in the workingtree (the // workingtree is clean) but do not complain if the file is // already deleted locally. This complements the test in // isWorktreeDirty() for the same case. if (this.tw.getTreeCount() > T_FILE && this.tw.getRawMode(T_FILE) == 0) { return true; } this.toBeDeleted.add(this.tw.getPathString()); return true; } } if (this.tw.isSubtree()) { // file/folder conflicts: here I want to detect only file/folder // conflict between ours and theirs. file/folder conflicts between // base/index/workingTree and something else are not relevant or // detected later if (nonTree(modeO) && !nonTree(modeT)) { if (nonTree(modeB)) { add(this.tw.getRawPath(), base, DirCacheEntry.STAGE_1, 0, 0); } add(this.tw.getRawPath(), ours, DirCacheEntry.STAGE_2, 0, 0); this.unmergedPaths.add(this.tw.getPathString()); this.enterSubtree = false; return true; } if (nonTree(modeT) && !nonTree(modeO)) { if (nonTree(modeB)) { add(this.tw.getRawPath(), base, DirCacheEntry.STAGE_1, 0, 0); } add(this.tw.getRawPath(), theirs, DirCacheEntry.STAGE_3, 0, 0); this.unmergedPaths.add(this.tw.getPathString()); this.enterSubtree = false; return true; } // ours and theirs are both folders or both files (and treewalk // tells us we are in a subtree because of index or working-dir). // If they are both folders no content-merge is required - we can // return here. if (!nonTree(modeO)) { return true; } // ours and theirs are both files, just fall out of the if block // and do the content merge } if (nonTree(modeO) && nonTree(modeT)) { // Check worktree before modifying files if (isWorktreeDirty(work, ourDce)) { return false; } // Don't attempt to resolve submodule link conflicts if (isGitLink(modeO) || isGitLink(modeT)) { add(this.tw.getRawPath(), base, DirCacheEntry.STAGE_1, 0, 0); add(this.tw.getRawPath(), ours, DirCacheEntry.STAGE_2, 0, 0); add(this.tw.getRawPath(), theirs, DirCacheEntry.STAGE_3, 0, 0); this.unmergedPaths.add(this.tw.getPathString()); return true; } MergeResult<RawText> result = contentMerge(base, ours, theirs); // if (ignoreConflicts) { // result.setContainsConflicts(false); // } updateIndex(base, ours, theirs, result); if (result.containsConflicts() && !ignoreConflicts) { this.unmergedPaths.add(this.tw.getPathString()); } this.modifiedFiles.add(this.tw.getPathString()); } else if (modeO != modeT) { // OURS or THEIRS has been deleted if (modeO != 0 && !this.tw.idEqual(T_BASE, T_OURS) || modeT != 0 && !this.tw.idEqual(T_BASE, T_THEIRS)) { add(this.tw.getRawPath(), base, DirCacheEntry.STAGE_1, 0, 0); add(this.tw.getRawPath(), ours, DirCacheEntry.STAGE_2, 0, 0); DirCacheEntry e = add(this.tw.getRawPath(), theirs, DirCacheEntry.STAGE_3, 0, 0); // OURS was deleted checkout THEIRS if (modeO == 0) { // Check worktree before checking out THEIRS if (isWorktreeDirty(work, ourDce)) { return false; } if (nonTree(modeT)) { if (e != null) { this.toBeCheckedOut.put(this.tw.getPathString(), e); } } } this.unmergedPaths.add(this.tw.getPathString()); // generate a MergeResult for the deleted file this.mergeResults.put(this.tw.getPathString(), contentMerge(base, ours, theirs)); } } return true; }
From source file:com.itemis.maven.plugins.unleash.scm.providers.merge.UnleashGitMerger.java
License:Eclipse Distribution License
/** * Updates the index after a content merge has happened. If no conflict has * occurred this includes persisting the merged content to the object * database. In case of conflicts this method takes care to write the * correct stages to the index.//from w w w. j av a2 s.com * * @param base * @param ours * @param theirs * @param result * @throws FileNotFoundException * @throws IOException */ private void updateIndex(CanonicalTreeParser base, CanonicalTreeParser ours, CanonicalTreeParser theirs, MergeResult<RawText> result) throws FileNotFoundException, IOException { File mergedFile = !this.inCore ? writeMergedFile(result) : null; if (result.containsConflicts()) { // A conflict occurred, the file will contain conflict markers // the index will be populated with the three stages and the // workdir (if used) contains the halfway merged content. add(this.tw.getRawPath(), base, DirCacheEntry.STAGE_1, 0, 0); add(this.tw.getRawPath(), ours, DirCacheEntry.STAGE_2, 0, 0); add(this.tw.getRawPath(), theirs, DirCacheEntry.STAGE_3, 0, 0); this.mergeResults.put(this.tw.getPathString(), result); return; } // No conflict occurred, the file will contain fully merged content. // The index will be populated with the new merged version. DirCacheEntry dce = new DirCacheEntry(this.tw.getPathString()); // Set the mode for the new content. Fall back to REGULAR_FILE if // we can't merge modes of OURS and THEIRS. int newMode = mergeFileModes(this.tw.getRawMode(0), this.tw.getRawMode(1), this.tw.getRawMode(2)); dce.setFileMode(newMode == FileMode.MISSING.getBits() ? FileMode.REGULAR_FILE : FileMode.fromBits(newMode)); if (mergedFile != null) { long len = mergedFile.length(); dce.setLastModified(mergedFile.lastModified()); dce.setLength((int) len); InputStream is = new FileInputStream(mergedFile); try { dce.setObjectId(getObjectInserter().insert(OBJ_BLOB, len, is)); } finally { is.close(); } } else { dce.setObjectId(insertMergeResult(result)); } this.builder.add(dce); }
From source file:com.itemis.maven.plugins.unleash.scm.providers.merge.UnleashGitMerger.java
License:Eclipse Distribution License
/** * Try to merge filemodes. If only ours or theirs have changed the mode * (compared to base) we choose that one. If ours and theirs have equal * modes return that one. If also that is not the case the modes are not * mergeable. Return {@link FileMode#MISSING} int that case. * * @param modeB//from w w w .java 2 s .com * filemode found in BASE * @param modeO * filemode found in OURS * @param modeT * filemode found in THEIRS * * @return the merged filemode or {@link FileMode#MISSING} in case of a * conflict */ private int mergeFileModes(int modeB, int modeO, int modeT) { if (modeO == modeT) { return modeO; } if (modeB == modeO) { // Base equal to Ours -> chooses Theirs if that is not missing return modeT == FileMode.MISSING.getBits() ? modeO : modeT; } if (modeB == modeT) { // Base equal to Theirs -> chooses Ours if that is not missing return modeO == FileMode.MISSING.getBits() ? modeT : modeO; } return FileMode.MISSING.getBits(); }
From source file:com.madgag.agit.diff.LineContextDiffer.java
License:Open Source License
private byte[] open(ObjectReader reader, FileMode mode, AbbreviatedObjectId id) throws IOException { if (mode == FileMode.MISSING) return new byte[] {}; if (mode.getObjectType() != Constants.OBJ_BLOB) return new byte[] {}; if (!id.isComplete()) { Collection<ObjectId> ids = reader.resolve(id); if (ids.size() == 1) id = AbbreviatedObjectId.fromObjectId(ids.iterator().next()); else if (ids.size() == 0) throw new MissingObjectException(id, Constants.OBJ_BLOB); else//from w w w. j a v a 2 s. com throw new AmbiguousObjectException(id, ids); } ObjectLoader ldr = reader.open(id.toObjectId()); return ldr.getCachedBytes(bigFileThreshold); }
From source file:com.microsoft.gittf.core.tasks.CreateCommitForPendingSetsTask.java
License:Open Source License
private void createBlob(final ObjectInserter repositoryInserter, final Map<CommitTreePath, Map<CommitTreePath, CommitTreeEntry>> treeHierarchy, final PendingChange pendingChange, final boolean addBaseContent, final TaskProgressMonitor progressMonitor) throws Exception { if (pendingChange.getItemType() == ItemType.FOLDER) { return;/*from w w w . j a v a 2 s . c o m*/ } File tempFile = null; InputStream tempInputStream = null; ObjectId blobID = null; try { tempFile = File.createTempFile(GitTFConstants.GIT_TF_NAME, null, tempDir); if (addBaseContent) { versionControlService.downloadBaseFile(pendingChange, tempFile.getAbsolutePath()); } else { versionControlService.downloadShelvedFile(pendingChange, tempFile.getAbsolutePath()); } if (tempFile.exists()) { tempInputStream = new FileInputStream(tempFile); blobID = repositoryInserter.insert(OBJ_BLOB, tempFile.length(), tempInputStream); } else { blobID = ObjectId.zeroId(); } FileMode fileMode; /* handle executable files */ if (pendingChange.getPropertyValues() != null) { if (PropertyConstants.EXECUTABLE_ENABLED_VALUE.equals(PropertyUtils .selectMatching(pendingChange.getPropertyValues(), PropertyConstants.EXECUTABLE_KEY))) { fileMode = addBaseContent ? FileMode.REGULAR_FILE : FileMode.EXECUTABLE_FILE; } else { fileMode = addBaseContent ? FileMode.EXECUTABLE_FILE : FileMode.REGULAR_FILE; } } else { fileMode = FileMode.MISSING; } String serverItem = pendingChange.getSourceServerItem() != null && addBaseContent ? pendingChange.getSourceServerItem() : pendingChange.getServerItem(); createBlob(repositoryInserter, treeHierarchy, serverItem, blobID, fileMode, progressMonitor); } finally { if (tempInputStream != null) { tempInputStream.close(); } if (tempFile != null) { tempFile.delete(); } } }
From source file:com.microsoft.gittf.core.tasks.pendDiff.PropertyChange.java
License:Open Source License
/** * Constructor//from ww w.j a v a 2 s .c o m * * @param path * the item path in the git repository * @param objectID * the object id of the item * @param mode * the file mode of the item */ public PropertyChange(final String path, final ObjectId objectID, final FileMode mode) { this(path, objectID, FileMode.MISSING, mode); }