# HG changeset patch # User Steve Losh # Date 1276555982 14400 # Node ID 1a2f5b8da6efe9b6c20b349691c0397cc7100fd7 # Parent 3ad9a898bc0d5d35d96afb2d6759d4efe6b5d9d2 api: look in all heads for the .hgreview file diff -r 3ad9a898bc0d -r 1a2f5b8da6ef review/api.py --- a/review/api.py Sun Jun 13 16:58:40 2010 -0400 +++ b/review/api.py Mon Jun 14 18:53:02 2010 -0400 @@ -101,7 +101,7 @@ return filter(None, list(_spd(p)))[::-1] -def _parse_hgrf(repo): +def _parse_hgrf(hgrf): """Parse the .hgreview file and return the data inside. The .hgreview file will be pulled from the tip revision of the given @@ -109,7 +109,7 @@ """ data = {} - hgrd = repo['tip']['.hgreview'].data().split('\n') + hgrd = hgrf.data().split('\n') lines = [line for line in hgrd if line.strip()] for line in lines: label, _, path = [i.strip() for i in line.partition('=')] @@ -188,7 +188,9 @@ review_data = ReviewDatastore(ui, repo) - To set up a repository to support code review: + To set up a repository to support code review (which will either create + a new repo if this has not been done by someone, or clone down the data + repo if it has): review_data = ReviewDatastore(ui, repo, create=True) @@ -201,24 +203,28 @@ """ self.ui = ui self.target = repo - self.lpath = lpath or os.path.join( - self.target.root, DEFAULT_DATASTORE_DIRNAME - ) + 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 if not create: - if not '.hgreview' in repo['tip']: + if not hgrd: raise UninitializedDatastore(False) - data = _parse_hgrf(repo) - self.rpath = data['rpath'] + self.rpath = hgrd['rpath'] try: self.repo = hg.repository(_ui.ui(), self.lpath) except error.RepoError: raise UninitializedDatastore(True) - elif '.hgreview' in repo['tip']: - data = _parse_hgrf(self.target) - self.rpath = data['rpath'] + return + + if hgrd: + self.rpath = hgrd['rpath'] if self.rpath.startswith('.'): raise RelativeRemotePath @@ -241,8 +247,8 @@ with open(os.path.join(self.target.root, '.hgreview'), 'w') as hgrf: hgrf.write('remote = %s\n' % self.rpath) + self.target.add(['.hgreview']) - self.repo = hg.repository(ui, self.lpath, create) def __getitem__(self, rev):