/** * @param max max number of entries to read * @return all reflog entries in reverse order * @throws IOException */ public List<ReflogEntry> getReverseEntries(int max) throws IOException { final byte[] log; try { log = IO.readFully(logName); } catch (FileNotFoundException e) { return Collections.emptyList(); } int rs = RawParseUtils.prevLF(log, log.length); List<ReflogEntry> ret = new ArrayList<ReflogEntry>(); while (rs >= 0 && max-- > 0) { rs = RawParseUtils.prevLF(log, rs); ReflogEntry entry = new ReflogEntry(log, rs < 0 ? 0 : rs + 2); ret.add(entry); } return ret; }
/** * Get specific entry in the reflog relative to the last entry which is considered entry zero. * * @param number * @return reflog entry or null if not found * @throws IOException */ public ReflogEntry getReverseEntry(int number) throws IOException { if (number < 0) throw new IllegalArgumentException(); final byte[] log; try { log = IO.readFully(logName); } catch (FileNotFoundException e) { return null; } int rs = RawParseUtils.prevLF(log, log.length); int current = 0; while (rs >= 0) { rs = RawParseUtils.prevLF(log, rs); if (number == current) return new ReflogEntry(log, rs < 0 ? 0 : rs + 2); current++; } return null; }