--- a/review/api.py Sun Oct 04 16:25:22 2009 -0400
+++ b/review/api.py Sun Oct 04 17:33:58 2009 -0400
@@ -4,7 +4,8 @@
'''
import os
-from mercurial import hg
+from mercurial import cmdutil, hg
+from mercurial.node import hex
class PreexistingDatastore(Exception):
@@ -19,7 +20,8 @@
"""Parse the .hgreview file and return the data inside."""
data = {}
- lines = [line for line in repo['tip']['.hgreview'] if line.strip()]
+ hgrd = repo['tip']['.hgreview'].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('=')]
if label == 'local':
@@ -29,11 +31,15 @@
return data
+def _commitfunc(ui, repo, message, match, opts):
+ return repo.commit(message, opts.get('user'), opts.get('date'), match)
-class ReviewDatastore(dict):
+class ReviewDatastore(object):
'''The data store for all the reviews so far.'''
def __init__(self, ui, repo, lpath=None, rpath=None, create=False):
+ self.ui = ui
+
if not create:
data = _parse_hgrf(repo)
self.lpath = data['lpath']
@@ -56,6 +62,44 @@
hgrf.write('local = %s\n' % self.lpath)
hgrf.write('remote = %s\n' % self.rpath)
repo.add(['.hgreview'])
-
+
+ def __getitem__(self, rev):
+ '''Return a ReviewChangeset for the given revision.'''
+ node = hex(self.target[rev].node())
+ return ReviewChangeset(self.ui, self.repo, node)
+
+ def add_signoff(self, rev):
+ '''Add (and commit) a signoff for the given revision.'''
+ pass
+
+ def add_comment(self, rev, message):
+ '''Add (and commit) a comment for the given revision.'''
+ pass
+
+class ReviewChangeset(object):
+ '''The review data about one changeset in the target repository.'''
+
+ def __init__(self, ui, repo, node):
+ self.repo = repo
+ self.ui = ui
+ self.node = node
+
+ if '%s/.exists' % node in self.repo['tip']:
+ pass
+ else:
+ self.comments = []
+ self.signoffs = []
+
+ path = os.path.join(self.repo.root, node)
+ os.mkdir(path)
+ with open(os.path.join(path, '.exists'), 'w') as e:
+ pass
+
+ cmdutil.commit(ui, self.repo, _commitfunc,
+ [os.path.join(path, '.exists')],
+ { 'message': 'Initialize review data for changeset %s' % self.node,
+ 'addremove': True, })
+
+
--- a/review/extension_ui.py Sun Oct 04 16:25:22 2009 -0400
+++ b/review/extension_ui.py Sun Oct 04 17:33:58 2009 -0400
@@ -19,14 +19,19 @@
ui.note(messages.INIT_EXISTS_COMMITTED)
else:
raise util.Abort(messages.INIT_EXISTS_UNCOMMITTED)
+ return
-
+ # No other options matched, so we're at the basic review command.
+ rev = opts.pop('rev')
+ rd = ReviewDatastore(ui, repo)
+ rc = rd[rev]
cmdtable = {
'review': (review, [
('i', 'init', False, 'start code reviewing this repository'),
('', 'local-path', '', 'the local path to the code review data'),
('', 'remote-path', '', 'the remote path to code review data'),
+ ('r', 'rev', '.', 'the revision to review'),
],
'hg review')
}
\ No newline at end of file