9ee9ef21460c

ReviewChangeset loads precursors comments
[view raw] [browse files]
author Christophe de Vienne <cdevienne@gmail.com>
date Mon, 27 Oct 2014 22:40:30 +0100
parents 3c3734c184d9
children 0dc141617716
branches/tags (none)
files review/api.py

Changes

--- a/review/api.py	Mon Oct 27 22:38:16 2014 +0100
+++ b/review/api.py	Mon Oct 27 22:40:30 2014 +0100
@@ -9,6 +9,7 @@
 from mercurial.node import hex
 from mercurial import ui as _ui
 from mercurial import demandimport
+from mercurial import obsolete
 demandimport.ignore.append('json')
 
 try:
@@ -454,22 +455,31 @@
         self.target = target
         self.ui = ui
         self.node = node
-
-        if '%s/.exists' % self.node in self.repo['tip']:
-            _match = lambda p: lambda fn: fn.startswith(p)
+        self.allnodes = [
+            hex(n) for n in obsolete.allprecursors(
+                target.obsstore, (self.node.decode('hex'),))
+        ]
 
-            relevant = filter(_match(node), self.repo['tip'])
-            commentfns = filter(_match('%s/comments' % node), relevant)
-            signofffns = filter(_match('%s/signoffs' % node), relevant)
+        self.comments = []
+        self.signoffs = []
+
+        _match = lambda p: lambda fn: fn.startswith(p)
+
+        for node in self.allnodes:
+            if '%s/.exists' % node in self.repo['tip']:
 
-            self.comments = [self._load_comment_file(fn) for fn in commentfns]
-            self.comments.sort(key=operator.attrgetter('local_datetime'))
+                relevant = filter(_match(node), self.repo['tip'])
+                commentfns = filter(_match('%s/comments' % node), relevant)
+                signofffns = filter(_match('%s/signoffs' % node), relevant)
 
-            self.signoffs = [self._load_signoff_file(fn) for fn in signofffns]
-            self.signoffs.sort(key=operator.attrgetter('local_datetime'))
-        else:
-            self.comments = []
-            self.signoffs = []
+                self.comments.extend(
+                    [self._load_comment_file(fn) for fn in commentfns])
+
+                self.signoffs.extend(
+                    [self._load_signoff_file(fn) for fn in signofffns])
+
+        self.comments.sort(key=operator.attrgetter('local_datetime'))
+        self.signoffs.sort(key=operator.attrgetter('local_datetime'))
 
     def signoffs_for_user(self, username):
         return filter(lambda s: s.author == username, self.signoffs)
@@ -492,8 +502,7 @@
         if existing:
             raise SignoffExists
 
-        if not (self.comments or self.signoffs):
-            self._create_exists_entry()
+        self._create_exists_entry()
 
         signoff = ReviewSignoff(fromlocal(self.ui.username()), util.makedate(),
                                 self.node, opinion, message, style)
@@ -518,8 +527,7 @@
         if filename and not ufilename:
             ufilename = fromlocal(filename)
 
-        if not (self.comments or self.signoffs):
-            self._create_exists_entry()
+        self._create_exists_entry()
 
         comment = ReviewComment(fromlocal(self.ui.username()), util.makedate(),
             self.node, ufilename, filename, map(int, lines), message, style)