Java Code Examples for org.eclipse.jgit.dircache.DirCacheEntry#setFileMode()
The following examples show how to use
org.eclipse.jgit.dircache.DirCacheEntry#setFileMode() .
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: SubtreeMerger.java From git-merge-repos with Apache License 2.0 | 6 votes |
private DirCache createTreeDirCache(Map<SubtreeConfig, RevCommit> parentCommits, String commitMessage) throws IOException { try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.setRecursive(true); addTrees(parentCommits, treeWalk); DirCacheBuilder builder = DirCache.newInCore().builder(); while (treeWalk.next()) { AbstractTreeIterator iterator = getSingleTreeIterator(treeWalk, commitMessage); if (iterator == null) { throw new IllegalStateException( "Tree walker did not return a single tree (should not happen): " + treeWalk.getPathString()); } byte[] path = Arrays.copyOf(iterator.getEntryPathBuffer(), iterator.getEntryPathLength()); DirCacheEntry entry = new DirCacheEntry(path); entry.setFileMode(iterator.getEntryFileMode()); entry.setObjectId(iterator.getEntryObjectId()); builder.add(entry); } builder.finish(); return builder.getDirCache(); } }
Example 2
Source File: ResolveMerger.java From onedev with MIT License | 5 votes |
/** * adds a new path with the specified stage to the index builder * * @param path * @param p * @param stage * @param lastMod * @param len * @return the entry which was added to the index */ private DirCacheEntry add(byte[] path, CanonicalTreeParser p, int stage, Instant lastMod, long len) { if (p != null && !p.getEntryFileMode().equals(FileMode.TREE)) { DirCacheEntry e = new DirCacheEntry(path, stage); e.setFileMode(p.getEntryFileMode()); e.setObjectId(p.getEntryObjectId()); e.setLastModified(lastMod); e.setLength(len); builder.add(e); return e; } return null; }
Example 3
Source File: ResolveMerger.java From onedev with MIT License | 5 votes |
/** * adds a entry to the index builder which is a copy of the specified * DirCacheEntry * * @param e * the entry which should be copied * * @return the entry which was added to the index */ private DirCacheEntry keep(DirCacheEntry e) { DirCacheEntry newEntry = new DirCacheEntry(e.getRawPath(), e.getStage()); newEntry.setFileMode(e.getFileMode()); newEntry.setObjectId(e.getObjectId()); newEntry.setLastModified(e.getLastModifiedInstant()); newEntry.setLength(e.getLength()); builder.add(newEntry); return newEntry; }
Example 4
Source File: ResetTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testResetConflict () throws Exception { File file = new File(workDir, "file"); write(file, "init"); File[] files = new File[] { file }; add(files); commit(files); DirCache index = repository.lockDirCache(); DirCacheBuilder builder = index.builder(); DirCacheEntry e = index.getEntry(file.getName()); DirCacheEntry e1 = new DirCacheEntry(file.getName(), 1); e1.setCreationTime(e.getCreationTime()); e1.setFileMode(e.getFileMode()); e1.setLastModified(e.getLastModified()); e1.setLength(e.getLength()); e1.setObjectId(e.getObjectId()); builder.add(e1); builder.finish(); builder.commit(); GitClient client = getClient(workDir); Map<File, GitStatus> status = client.getStatus(files, NULL_PROGRESS_MONITOR); assertTrue(status.get(file).isConflict()); assertEquals(GitConflictDescriptor.Type.BOTH_DELETED, status.get(file).getConflictDescriptor().getType()); client.reset(files, "HEAD", true, NULL_PROGRESS_MONITOR); status = client.getStatus(files, NULL_PROGRESS_MONITOR); assertFalse(status.get(file).isConflict()); }
Example 5
Source File: GitRepository.java From centraldogma with Apache License 2.0 | 5 votes |
@Override public void apply(DirCacheEntry ent) { try { ent.setObjectId(inserter.insert(Constants.OBJ_BLOB, text.getBytes(UTF_8))); ent.setFileMode(FileMode.REGULAR_FILE); } catch (IOException e) { throw new StorageException("failed to create a new text blob", e); } }
Example 6
Source File: GitRepository.java From centraldogma with Apache License 2.0 | 5 votes |
@Override public void apply(DirCacheEntry ent) { try { ent.setObjectId(inserter.insert(Constants.OBJ_BLOB, Jackson.writeValueAsBytes(jsonNode))); ent.setFileMode(FileMode.REGULAR_FILE); } catch (IOException e) { throw new StorageException("failed to create a new JSON blob", e); } }
Example 7
Source File: GfsDefaultCheckoutCacheTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Nonnull private DirCacheEntry someEntry(String path, int stage) { DirCacheEntry ret = new DirCacheEntry(normalizeNodePath(path), stage); ret.setFileMode(REGULAR_FILE); ret.setObjectId(someObjectId()); return ret; }
Example 8
Source File: CacheEntryUpdate.java From ParallelGit with Apache License 2.0 | 5 votes |
@Override public void apply(DirCacheEntry ent) { if(newBlob != null) ent.setObjectId(newBlob); if(newFileMode != null) ent.setFileMode(newFileMode); }
Example 9
Source File: GfsDefaultCheckoutCacheTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Nonnull private DirCacheEntry someEntry(String path, int stage) { DirCacheEntry ret = new DirCacheEntry(normalizeNodePath(path), stage); ret.setFileMode(REGULAR_FILE); ret.setObjectId(someObjectId()); return ret; }
Example 10
Source File: CacheEntryUpdate.java From ParallelGit with Apache License 2.0 | 5 votes |
@Override public void apply(DirCacheEntry ent) { if(newBlob != null) ent.setObjectId(newBlob); if(newFileMode != null) ent.setFileMode(newFileMode); }
Example 11
Source File: ResolveMerger.java From onedev with MIT License | 4 votes |
/** * 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. * * @param base * @param ours * @param theirs * @param result * @param attributes * @throws FileNotFoundException * @throws IOException */ private void updateIndex(CanonicalTreeParser base, CanonicalTreeParser ours, CanonicalTreeParser theirs, MergeResult<RawText> result, Attributes attributes) throws FileNotFoundException, IOException { TemporaryBuffer rawMerged = null; try { rawMerged = doMerge(result); File mergedFile = inCore ? null : writeMergedFile(rawMerged, attributes); 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(tw.getRawPath(), base, DirCacheEntry.STAGE_1, EPOCH, 0); add(tw.getRawPath(), ours, DirCacheEntry.STAGE_2, EPOCH, 0); add(tw.getRawPath(), theirs, DirCacheEntry.STAGE_3, EPOCH, 0); mergeResults.put(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(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(tw.getRawMode(0), tw.getRawMode(1), tw.getRawMode(2)); dce.setFileMode(newMode == FileMode.MISSING.getBits() ? FileMode.REGULAR_FILE : FileMode.fromBits(newMode)); if (mergedFile != null) { dce.setLastModified( nonNullRepo().getFS().lastModifiedInstant(mergedFile)); dce.setLength((int) mergedFile.length()); } dce.setObjectId(insertMergeResult(rawMerged, attributes)); builder.add(dce); } finally { if (rawMerged != null) { rawMerged.destroy(); } } }
Example 12
Source File: GitRepository.java From centraldogma with Apache License 2.0 | 4 votes |
@Override public void apply(DirCacheEntry ent) { ent.setFileMode(oldEntry.getFileMode()); ent.setObjectId(oldEntry.getObjectId()); }