cdd63ba4a8f8

Add basic commenting.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sun, 04 Oct 2009 18:45:19 -0400
parents ac3c440a29a4
children 1596046f752c
branches/tags (none)
files review/api.py review/extension_ui.py review/messages.py

Changes

--- a/review/api.py	Sun Oct 04 18:33:20 2009 -0400
+++ b/review/api.py	Sun Oct 04 18:45:19 2009 -0400
@@ -104,7 +104,7 @@
         node = hex(self.target[rev].node())
         comment = ReviewComment(self.ui.username(), datetime.utcnow(), node,
             filename, lines, message)
-        comment.commit(self.repo)
+        comment.commit(self.ui, self.repo)
     
 
 
@@ -161,20 +161,21 @@
         return COMMENT_FILE_TEMPLATE % ( self.author, datetime,
             self.node, self.filename, lines, self.message )
     
-    def commit(self, repo):
+    def commit(self, ui, repo):
         '''Write and commit this comment to the given repo.'''
         
         path = os.path.join(repo.root, self.node, 'comments')
-        os.mkdir(path)
+        if not os.path.exists(path):
+            os.mkdir(path)
         
         data = self.render_data()
-        filename = sha1(data)
+        filename = sha1(data).hexdigest()
         commentpath = os.path.join(path, filename)
         
         with open(commentpath, 'w') as commentfile:
             commentfile.write(data)
         
-        cmdutil.commit(ui, self.repo, _commitfunc,
+        cmdutil.commit(ui, repo, _commitfunc,
             [commentpath],
             { 'message': 'Add a comment on changeset %s' % self.node,
               'addremove': True, })
--- a/review/extension_ui.py	Sun Oct 04 18:33:20 2009 -0400
+++ b/review/extension_ui.py	Sun Oct 04 18:45:19 2009 -0400
@@ -10,7 +10,7 @@
     if opts.pop('init'):
         ui.note(messages.INIT_START)
         try:
-            datastore = ReviewDatastore(ui, repo, lpath=opts.pop('local_path'),
+            ReviewDatastore(ui, repo, lpath=opts.pop('local_path'),
                 rpath=opts.pop('remote_path'), create=True)
             ui.status(messages.INIT_SUCCESS)
             return
@@ -20,7 +20,16 @@
             else:
                 raise util.Abort(messages.INIT_EXISTS_UNCOMMITTED)
             return
+    elif opts.pop('comment'):
+        rd = ReviewDatastore(ui, repo)
+        message = opts.pop('message')
         
+        if not message:
+            raise util.Abort(messages.COMMENT_REQUIRES_MESSAGE)
+        
+        rd.add_comment(message=message)
+        return
+    
     # No other options matched, so we're at the basic review command.
     rev = opts.pop('rev')
     rd = ReviewDatastore(ui, repo)
@@ -31,6 +40,8 @@
         ('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'),
+        ('c', 'comment', False, 'add a comment'),
+        ('m', 'message', '', 'use <text> as the comment or signoff message'),
         ('r', 'rev', '.', 'the revision to review'),
     ],
     'hg review')
--- a/review/messages.py	Sun Oct 04 18:33:20 2009 -0400
+++ b/review/messages.py	Sun Oct 04 18:45:19 2009 -0400
@@ -16,4 +16,8 @@
 INIT_EXISTS_UNCOMMITTED = '''\
 the review data has already been initialized, but is not recorded!
 run "hg commit .hgreview -m'initialize code review'" to record it permanently
+'''
+
+COMMENT_REQUIRES_MESSAGE = '''\
+a message must be provided to add a comment!
 '''
\ No newline at end of file