OverviewFilesCommitsIssuesDocsReleasesPeers

pear-git / lib / backends / direct-git.js

98 lines · javascript ref:
import { RepositoryBackend } from './base.js'

/**
 * Direct Git Backend
 *
 * Reads directly from bare git repositories on disk.
 * Zero storage duplication, but requires seeder to be online.
 * Good for HTTP web UI and local access.
 */
export class DirectGitBackend extends RepositoryBackend {
  constructor(gitBrowser) {
    super()
    this.gitBrowser = gitBrowser
  }

  getStrategy() {
    return 'direct-git'
  }

  getDescription() {
    return 'Direct access to bare git repositories (zero duplication)'
  }

  // Delegate all methods to GitBrowser

  async getRepoInfo(repoName) {
    // GitBrowser doesn't have this method, return basic info
    const stats = await this.getStats(repoName)
    return {
      name: repoName,
      ...stats
    }
  }

  async listFiles(repoName, ref, path) {
    return this.gitBrowser.listFiles(repoName, ref, path)
  }

  async getCommits(repoName, ref, limit) {
    return this.gitBrowser.getCommits(repoName, ref, limit)
  }

  async readFile(repoName, filePath, ref) {
    return this.gitBrowser.readFile(repoName, filePath, ref)
  }

  async getBranches(repoName) {
    return this.gitBrowser.getBranches(repoName)
  }

  async getTags(repoName) {
    return this.gitBrowser.getTags(repoName)
  }

  async getStats(repoName) {
    return this.gitBrowser.getStats(repoName)
  }

  async getReadme(repoName, ref) {
    return this.gitBrowser.getReadme(repoName, ref)
  }

  async getSubmodules(repoName, ref) {
    return this.gitBrowser.getSubmodules(repoName, ref)
  }

  async getSubmoduleInfo(repoName, submodulePath, ref) {
    return this.gitBrowser.getSubmoduleInfo(repoName, submodulePath, ref)
  }

  async getCommitDiff(repoName, commitHash) {
    return this.gitBrowser.getCommitDiff(repoName, commitHash)
  }

  async getFileAtCommit(repoName, filePath, commitHash) {
    return this.gitBrowser.getFileAtCommit(repoName, filePath, commitHash)
  }

  parseRepoNameFromURL(url) {
    return this.gitBrowser.parseRepoNameFromURL(url)
  }

  // P2P Support - Direct Git doesn't support P2P

  canReplicate() {
    return false
  }

  async getReplicationKey(repoName) {
    return null
  }

  async getStorageSize(repoName) {
    // No duplication - storage is in the original git repo
    return 0
  }
}