• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1const pinflight = require('promise-inflight')
2const spawn = require('./spawn.js')
3const LRU = require('lru-cache')
4
5const revsCache = new LRU({
6  max: 100,
7  ttl: 5 * 60 * 1000,
8})
9
10const linesToRevs = require('./lines-to-revs.js')
11
12module.exports = async (repo, opts = {}) => {
13  if (!opts.noGitRevCache) {
14    const cached = revsCache.get(repo)
15    if (cached) {
16      return cached
17    }
18  }
19
20  return pinflight(`ls-remote:${repo}`, () =>
21    spawn(['ls-remote', repo], opts)
22      .then(({ stdout }) => linesToRevs(stdout.trim().split('\n')))
23      .then(revs => {
24        revsCache.set(repo, revs)
25        return revs
26      })
27  )
28}
29