mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 17:27:53 +03:00
005a9ace91
Summary: Add an option to list remote and scratch bookmarks by pattern. Only very simple pattern is allowed: either the literal string or a prefix (like 'scratch/stash/*'). It was made intentionally to make sure that pattern requests are fast in mysql. Mysql tests will be added to the integration tests Test Plan: Run `test-infinitepush-*` Reviewers: mitrandir, andrasbelo, durham Reviewed By: durham Subscribers: mjpieters, #sourcecontrol Differential Revision: https://phabricator.intern.facebook.com/D4074409 Tasks: 12479677 Signature: t1:4074409:1477500968:e91cd2505d61a2f1db30c7f00cdcfc949e433507
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
import os
|
|
|
|
from indexapi import (
|
|
indexapi,
|
|
)
|
|
|
|
from mercurial import util
|
|
|
|
class fileindexapi(indexapi):
|
|
def __init__(self, repo):
|
|
super(fileindexapi, self).__init__()
|
|
self._repo = repo
|
|
root = repo.ui.config('infinitepush', 'indexpath')
|
|
if not root:
|
|
root = os.path.join('scratchbranches', 'index')
|
|
|
|
self._nodemap = os.path.join(root, 'nodemap')
|
|
self._bookmarkmap = os.path.join(root, 'bookmarkmap')
|
|
|
|
def addbundle(self, bundleid, nodes):
|
|
for node in nodes:
|
|
nodepath = os.path.join(self._nodemap, node)
|
|
self._write(nodepath, bundleid)
|
|
|
|
def addbookmark(self, bookmark, node):
|
|
bookmarkpath = os.path.join(self._bookmarkmap, bookmark)
|
|
self._write(bookmarkpath, node)
|
|
|
|
def addbookmarkandbundle(self, bundleid, nodes, bookmark, bookmarknode):
|
|
self.addbookmark(bookmark, bookmarknode)
|
|
self.addbundle(bundleid, nodes)
|
|
|
|
def getbundle(self, node):
|
|
nodepath = os.path.join(self._nodemap, node)
|
|
return self._read(nodepath)
|
|
|
|
def getnode(self, bookmark):
|
|
bookmarkpath = os.path.join(self._bookmarkmap, bookmark)
|
|
return self._read(bookmarkpath)
|
|
|
|
def getbookmarks(self, query):
|
|
result = {}
|
|
if query.endswith('*'):
|
|
query = 're:^' + query[:-1] + '.*'
|
|
kind, pat, matcher = util.stringmatcher(query)
|
|
prefixlen = len(self._bookmarkmap) + 1
|
|
for dirpath, _, books in self._repo.vfs.walk(self._bookmarkmap):
|
|
for book in books:
|
|
bookmark = os.path.join(dirpath, book)[prefixlen:]
|
|
if not matcher(bookmark):
|
|
continue
|
|
result[bookmark] = self._read(os.path.join(dirpath, book))
|
|
return result
|
|
|
|
def _write(self, path, value):
|
|
vfs = self._repo.vfs
|
|
dirname = vfs.dirname(path)
|
|
if not vfs.exists(dirname):
|
|
vfs.makedirs(dirname)
|
|
|
|
vfs.write(path, value)
|
|
|
|
def _read(self, path):
|
|
vfs = self._repo.vfs
|
|
if not vfs.exists(path):
|
|
return None
|
|
return vfs.read(path)
|