# HG changeset patch # User Steve Losh # Date 1279669382 14400 # Node ID 9cd3f1057ae106eb1ca68c3769a4c32a345a1e20 # Parent a0929b448985ea6ae407dcffe19ffdcb0c5995d5 api: factor out the hgrf logic into reusable functions diff -r a0929b448985 -r 9cd3f1057ae1 review/api.py --- a/review/api.py Tue Jul 20 19:11:50 2010 -0400 +++ b/review/api.py Tue Jul 20 19:43:02 2010 -0400 @@ -200,6 +200,32 @@ return '/'.join(_split_path_dammit(p)) +def _get_hgrf(repo): + """Return the .hgreview file for the given repo.""" + for head in (repo[h] for h in repo.heads()): + if '.hgreview' in head: + return head['.hgreview'] + return None + +def review_initialized(repo): + """Return whether the review data has been initialized by *someone*.""" + return True if _get_hgrf(repo) else False + +def local_datastore_exists(repo): + """Return whether a local review repo exists for this repo.""" + hgrf = _get_hgrf(repo) + hgrd = _parse_hgrf(hgrf) if hgrf else None + + if not hgrd: + return False + + try: + hg.repository(_ui.ui(), os.path.join(repo.root, DEFAULT_DATASTORE_DIRNAME)) + return True + except error.RepoError: + return False + + class ReviewDatastore(object): """The code review data for a particular repository.""" def __init__(self, ui, repo, lpath=None, rpath=None, create=False, @@ -228,11 +254,8 @@ self.target = repo self.lpath = lpath or os.path.join(self.target.root, DEFAULT_DATASTORE_DIRNAME) - hgrd = None - for head in (repo[h] for h in repo.heads()): - if '.hgreview' in head: - hgrd = _parse_hgrf(head['.hgreview']) - break + hgrf = _get_hgrf(repo) + hgrd = _parse_hgrf(hgrf) if hgrf else None if not create: if not hgrd: @@ -688,8 +711,8 @@ return self.target[self.node].files() def unicode_files(self): - """Returns a tuple of files in the revision for this ReviewChangeset. - + """Return a tuple of files in the revision for this ReviewChangeset. + Each element is a pair of strings, the first is a unicode string of the filename, the second is a bytestring of the filename (which Mercurial will want).