return ret;
}
+ private static boolean isHead(Ref ref) {
+ return ref.getName().startsWith(Constants.R_HEADS);
+ }
+
+ private static boolean isTag(Ref ref) {
+ return ref.getName().startsWith(Constants.R_TAGS);
+ }
+
+ /**
+ * Deletes orphans
+ * <p>
+ * A file is considered an orphan if it is either a "bitmap" or an index
+ * file, and its corresponding pack file is missing in the list.
+ * </p>
+ */
+ private void deleteOrphans() {
+ Path packDir = Paths.get(repo.getObjectsDirectory().getAbsolutePath(),
+ "pack"); //$NON-NLS-1$
+ List<String> fileNames = null;
+ try (Stream<Path> files = Files.list(packDir)) {
+ fileNames = files.map(path -> path.getFileName().toString())
+ .filter(name -> {
+ return (name.endsWith(PACK_EXT)
+ || name.endsWith(BITMAP_EXT)
+ || name.endsWith(INDEX_EXT));
+ }).sorted(Collections.reverseOrder())
+ .collect(Collectors.toList());
+ } catch (IOException e1) {
+ // ignore
+ }
+ if (fileNames == null) {
+ return;
+ }
+
+ String base = null;
+ for (String n : fileNames) {
+ if (n.endsWith(PACK_EXT)) {
+ base = n.substring(0, n.lastIndexOf('.'));
+ } else {
+ if (base == null || !n.startsWith(base)) {
+ try {
+ Files.delete(new File(packDir.toFile(), n).toPath());
+ } catch (IOException e) {
+ LOG.error(e.getMessage(), e);
+ }
+ }
+ }
+ }
+ }
+
/**
* @param ref
* the ref which log should be inspected