48541d29e527

Merged in benallard/hg-review (pull request #1)
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 29 Jun 2011 19:47:16 -0400
parents e62677ebd73d (current diff) 971a3a6e1df9 (diff)
children fa1f7726b08b
branches/tags (none)
files review/web.py

Changes

--- a/review/api.py	Sat Jan 29 19:00:39 2011 -0500
+++ b/review/api.py	Wed Jun 29 19:47:16 2011 -0400
@@ -423,6 +423,16 @@
 
         return ReviewSignoff(**data)
 
+    def _create_exists_entry(self):
+        path = os.path.join(self.repo.root, self.node)
+        os.mkdir(path)
+        with open(os.path.join(path, '.exists'), 'w') as e:
+            pass
+
+        cmdutil.commit(self.ui, self.repo, _commitfunc,
+            [os.path.join(path, '.exists')],
+            { 'message': 'Initialize review data for changeset %s' % self.node,
+              'addremove': True, })
 
     def __init__(self, ui, repo, target, node):
         """Initialize a ReviewChangeset.
@@ -455,16 +465,6 @@
             self.comments = []
             self.signoffs = []
 
-            path = os.path.join(self.repo.root, self.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, })
-
     def signoffs_for_user(self, username):
         return filter(lambda s: s.author == username, self.signoffs)
 
@@ -486,6 +486,9 @@
         if existing:
             raise SignoffExists
 
+        if not (self.comments or self.signoffs):
+            self._create_exists_entry()
+
         signoff = ReviewSignoff(fromlocal(self.ui.username()), util.makedate(),
                                 self.node, opinion, message, style)
         signoff._commit(self.ui, self.repo)
@@ -509,6 +512,9 @@
         if filename and not ufilename:
             ufilename = fromlocal(filename)
 
+        if not (self.comments or self.signoffs):
+            self._create_exists_entry()
+
         comment = ReviewComment(fromlocal(self.ui.username()), util.makedate(),
             self.node, ufilename, filename, map(int, lines), message, style)
         comment._commit(self.ui, self.repo)
@@ -615,7 +621,7 @@
             for n, line in enumerate(d):
                 start = n - context if n > context else 0
                 end = n + context + 1
-                if any(filter(lambda l: l[0] in '+-', d[start:end])):
+                if any(filter(lambda l: l and l[0] in '+-', d[start:end])):
                     yield (n, line)
 
         for filename, content in ds.iteritems():
--- a/review/web.py	Sat Jan 29 19:00:39 2011 -0500
+++ b/review/web.py	Wed Jun 29 19:47:16 2011 -0400
@@ -48,7 +48,10 @@
     return 'http://www.gravatar.com/avatar/%s?s=%d' % (md5(email(cset.user())).hexdigest(), size)
 
 def _line_type(line):
-    return 'rem' if line[0] == '-' else 'add' if line[0] == '+' else 'con'
+    try:
+        return {'+': 'add', '-':'rem'}[line[0]]
+    except (IndexError, KeyError):
+        return 'con'
 
 def _categorize_signoffs(signoffs):
     return { 'yes': len(filter(lambda s: s.opinion == 'yes', signoffs)),