api: factor out the hgrf logic into reusable functions
author |
Steve Losh <steve@stevelosh.com> |
date |
Tue, 20 Jul 2010 19:43:02 -0400 |
parents |
a0929b448985
|
children |
53aadb5be2b6
|
branches/tags |
(none) |
files |
review/api.py |
Changes
--- 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).