revs.js 521 B

12345678910111213141516171819202122
  1. const spawn = require('./spawn.js')
  2. const { LRUCache } = require('lru-cache')
  3. const linesToRevs = require('./lines-to-revs.js')
  4. const revsCache = new LRUCache({
  5. max: 100,
  6. ttl: 5 * 60 * 1000,
  7. })
  8. module.exports = async (repo, opts = {}) => {
  9. if (!opts.noGitRevCache) {
  10. const cached = revsCache.get(repo)
  11. if (cached) {
  12. return cached
  13. }
  14. }
  15. const { stdout } = await spawn(['ls-remote', repo], opts)
  16. const revs = linesToRevs(stdout.trim().split('\n'))
  17. revsCache.set(repo, revs)
  18. return revs
  19. }