/** Helper for {@link #get(File, Repository)}. */ private History getHistory(File file, Repository repository, boolean withFiles) throws HistoryException, SQLException { final String filePath = getSourceRootRelativePath(file); final String reposPath = toUnixPath(repository.getDirectoryName()); final ArrayList<HistoryEntry> entries = new ArrayList<HistoryEntry>(); final ConnectionResource conn = connectionManager.getConnectionResource(); try { final PreparedStatement ps; if (file.isDirectory()) { // Fetch history for all files under this directory. ps = conn.getStatement(GET_DIR_HISTORY); ps.setString(2, filePath); } else { // Fetch history for a single file only. ps = conn.getStatement(GET_FILE_HISTORY); ps.setString(2, getParentPath(filePath)); ps.setString(3, getBaseName(filePath)); } ps.setString(1, reposPath); final PreparedStatement filePS = withFiles ? conn.getStatement(GET_CS_FILES) : null; try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { // Get the information about a changeset String revision = rs.getString(1); String author = rs.getString(2); Timestamp time = rs.getTimestamp(3); String message = rs.getString(4); HistoryEntry entry = new HistoryEntry(revision, time, author, null, message, true); entries.add(entry); // Fill the list of files touched by the changeset, if // requested. if (withFiles) { int changeset = rs.getInt(5); filePS.setInt(1, changeset); try (ResultSet fileRS = filePS.executeQuery()) { while (fileRS.next()) { entry.addFile(fileRS.getString(1)); } } } } } } finally { connectionManager.releaseConnection(conn); } History history = new History(); history.setHistoryEntries(entries); RuntimeEnvironment env = RuntimeEnvironment.getInstance(); if (env.isTagsEnabled() && repository.hasFileBasedTags()) { repository.assignTagsInHistory(history); } return history; }