RefDirectory(final FileRepository db) { final FS fs = db.getFS(); parent = db; gitDir = db.getDirectory(); logWriter = new ReflogWriter(db); refsDir = fs.resolve(gitDir, R_REFS); packedRefsFile = fs.resolve(gitDir, PACKED_REFS); looseRefs.set(RefList.<LooseRef>emptyList()); packedRefs.set(PackedRefList.NO_PACKED_REFS); }
@SuppressWarnings("unchecked") public void drop(DropTargetDropEvent event) { try { if (event.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { Transferable tr = event.getTransferable(); int action = event.getDropAction(); event.acceptDrop(action); java.util.List<File> files = (java.util.List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor); for (File f : files) { JEXStatics.logManager.log("Copying file " + f, 1, this); String newDest = parent.folder.getPath() + File.separator + f.getName(); FileUtility.copy(f, new File(newDest)); } parent.rebuild(); event.dropComplete(true); JEXStatics.logManager.log("Drop completed...", 1, this); return; } event.rejectDrop(); } catch (Exception e) { e.printStackTrace(); event.rejectDrop(); } }
public void setFolderViewed(String folderViewed, String notesFile) { this.folderViewed = folderViewed; this.notesFile = notesFile; if (folderViewed == null || notesFile == null) { JLabel noLabel = new JLabel("No notes available at this level"); notespane.setLayout(new BoxLayout(notespane, BoxLayout.PAGE_AXIS)); notespane.removeAll(); notespane.add(Box.createVerticalGlue()); notespane.add(noLabel); notespane.add(Box.createVerticalGlue()); } else { File folder = new File(this.folderViewed); File notes = new File(this.notesFile); notesLabel.setText(notes.getAbsolutePath()); notespane.setLayout(new BorderLayout()); notespane.removeAll(); notespane.add(editor); if (notes.exists()) editor.open(notes); fileRepository.setFolder(folder); } notespane.invalidate(); notespane.validate(); this.repaint(); }
/** * Adds a set of refs to the set of packed-refs. Only non-symbolic refs are added. If a ref with * the given name already existed in packed-refs it is updated with the new value. Each loose ref * which was added to the packed-ref file is deleted. If a given ref can't be locked it will not * be added to the pack file. * * @param refs the refs to be added. Must be fully qualified. * @throws IOException */ public void pack(List<String> refs) throws IOException { if (refs.size() == 0) return; FS fs = parent.getFS(); // Lock the packed refs file and read the content LockFile lck = new LockFile(packedRefsFile); if (!lck.lock()) throw new IOException(MessageFormat.format(JGitText.get().cannotLock, packedRefsFile)); try { final PackedRefList packed = getPackedRefs(); RefList<Ref> cur = readPackedRefs(); // Iterate over all refs to be packed for (String refName : refs) { Ref ref = readRef(refName, cur); if (ref.isSymbolic()) continue; // can't pack symbolic refs // Add/Update it to packed-refs int idx = cur.find(refName); if (idx >= 0) cur = cur.set(idx, peeledPackedRef(ref)); else cur = cur.add(idx, peeledPackedRef(ref)); } // The new content for packed-refs is collected. Persist it. commitPackedRefs(lck, cur, packed); // Now delete the loose refs which are now packed for (String refName : refs) { // Lock the loose ref File refFile = fileFor(refName); if (!fs.exists(refFile)) continue; LockFile rLck = new LockFile(refFile); if (!rLck.lock()) continue; try { LooseRef currentLooseRef = scanRef(null, refName); if (currentLooseRef == null || currentLooseRef.isSymbolic()) continue; Ref packedRef = cur.get(refName); ObjectId clr_oid = currentLooseRef.getObjectId(); if (clr_oid != null && clr_oid.equals(packedRef.getObjectId())) { RefList<LooseRef> curLoose, newLoose; do { curLoose = looseRefs.get(); int idx = curLoose.find(refName); if (idx < 0) break; newLoose = curLoose.remove(idx); } while (!looseRefs.compareAndSet(curLoose, newLoose)); int levels = levelsIn(refName) - 2; delete(refFile, levels, rLck); } } finally { rLck.unlock(); } } // Don't fire refsChanged. The refs have not change, only their // storage. } finally { lck.unlock(); } }
/** If the parent should fire listeners, fires them. */ private void fireRefsChanged() { final int last = lastNotifiedModCnt.get(); final int curr = modCnt.get(); if (last != curr && lastNotifiedModCnt.compareAndSet(last, curr) && last != 0) parent.fireEvent(new RefsChangedEvent()); }
protected long lastModified(AnyObjectId objectId) throws IOException { return repo.getFS().lastModified(repo.getObjectDatabase().fileFor(objectId)); }
@Test public void shouldWriteTheRequestedFileToTheOutput() { given(fileRepository.loadFile(INPUT_FILENAME)).willReturn(inputFile); application.rot13(INPUT_FILENAME); verify(inputFile).writeTo(output); }