Commits

Steve Losh committed 48541d2 Merge

Merged in benallard/hg-review (pull request #1)

Comments (0)

Files changed (2)

 
         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.
             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)
 
         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)
         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)
             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():
     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)),